From e17058953c320682d462ca2b35b30cc247613e21 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 4 Jun 2010 05:36:59 +0800 Subject: [PATCH] Add preliminary functions and variables for hex encoding patch Kangaderoo has a patch which potentially fixes storage and display issues for users who do not have their database text storage as utf8. Functions and variables added to Charset to disect the patch --- pyfpdb/Charset.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pyfpdb/Charset.py b/pyfpdb/Charset.py index 9c49f505..055ca714 100644 --- a/pyfpdb/Charset.py +++ b/pyfpdb/Charset.py @@ -26,7 +26,9 @@ import Configuration encoder_to_utf = codecs.lookup('utf-8') encoder_to_sys = codecs.lookup(Configuration.LOCALE_ENCODING) +coder_hex = codecs.lookup('hex_codec') +hex_coding = False #FIXME: Should only be on if db is not UTF8 - test in Database.py? # I'm saving a few cycles with this one not_needed1, not_needed2, not_needed3 = False, False, False if Configuration.LOCALE_ENCODING == 'UTF8': @@ -75,3 +77,19 @@ def to_gui(s): except UnicodeEncodeError: sys.stderr.write('Could not encode: "%s"\n' % s) raise + +def to_hex(s): + try: + out = coder_hex.encode(s)[0] + return out + except UnicodeDecodeError: + sys.stderr.write('Could not convert: "%s"\n' % s) + return s + +def from_hex(s): + try: + out = coder_hex.decode(s)[0] + return out + except UnicodeDecodeError: + sys.stderr.write('Could not convert: "%s"\n' % s) + return s