Show
Ignore:
Timestamp:
01/18/08 23:39:41 (16 years ago)
Author:
jerome
Message:

Added modules to store utility functions and application
intialization code, which has nothing to do in classes.
Modified tool.py accordingly (far from being finished)
Use these new modules where necessary.
Now converts all command line arguments to unicode before
beginning to work. Added a proper logging method for already
encoded query strings.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/tool.py

    r3288 r3294  
    2929import getopt 
    3030import smtplib 
    31 import gettext 
    3231import locale 
    3332import socket 
     
    109108        self.logger = logger.openLogger("stderr") 
    110109         
    111         # locale stuff 
    112         try : 
    113             locale.setlocale(locale.LC_ALL, (lang, charset)) 
    114         except (locale.Error, IOError) : 
    115             locale.setlocale(locale.LC_ALL, None) 
     110        # Saves a copy of the locale settings 
    116111        (self.language, self.charset) = locale.getlocale() 
    117         self.language = self.language or "C" 
    118         try : 
    119             self.charset = self.charset or locale.getpreferredencoding() 
    120         except locale.Error :     
    121             self.charset = sys.stdout.encoding or sys.getfilesystemencoding() 
    122          
    123         # Dirty hack : if the charset is ASCII, we can safely use UTF-8 instead 
    124         # This has the advantage of allowing transparent support for recent 
    125         # versions of CUPS which (en-)force charset to UTF-8 when printing. 
    126         # This should be needed only when printing, but is probably (?) safe 
    127         # to do when using interactive commands. 
    128         if self.charset.upper() in ('ASCII', 'ANSI_X3.4-1968') : 
    129             self.charset = "UTF-8" 
    130          
    131         # translation stuff 
    132         try : 
    133             try : 
    134                 trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)], codeset=self.charset) 
    135             except TypeError : # Python <2.4 
    136                 trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)]) 
    137             trans.install(unicode=True) 
    138         except : 
    139             gettext.NullTranslations().install(unicode=True) 
    140      
     112         
    141113        # pykota specific stuff 
    142114        self.documentation = doc 
     
    362334                    # and reset the list of arguments to the lines read from 
    363335                    # the file. 
    364                     argsfile = open(parsed["arguments"] or parsed["A"], "r") 
     336                    argsfile = open(parsed["arguments"] or parsed["A"], "r") # TODO : charset decoding 
    365337                    argv = [ l.strip() for l in argsfile.readlines() ] 
    366338                    argsfile.close()