yml2proc
changeset 25 cb4a7f8b230d
parent 23 f2e8837da4e9
equal deleted inserted replaced
24:1cb8f7566a07 25:cb4a7f8b230d
    16 except:
    16 except:
    17     sys.stderr.write("This program needs lxml, see http://codespeak.net/lxml/\n")
    17     sys.stderr.write("This program needs lxml, see http://codespeak.net/lxml/\n")
    18     sys.exit(1)
    18     sys.exit(1)
    19 
    19 
    20 from yml2 import ymlCStyle, comment, oldSyntax
    20 from yml2 import ymlCStyle, comment, oldSyntax
    21 from pyPEG import parse, u
    21 from pyPEG import parse
    22 import backend
    22 import backend
    23 
    23 
    24 def printInfo(option, opt_str, value, parser):
    24 def printInfo(option, opt_str, value, parser):
    25     sys.stdout.write(__doc__)
    25     sys.stdout.write(__doc__)
    26     sys.exit(0)
    26     sys.exit(0)
    31     if isinstance(msg, BaseException):
    31     if isinstance(msg, BaseException):
    32         try:
    32         try:
    33             msg = str(msg) + "\n"
    33             msg = str(msg) + "\n"
    34         except:
    34         except:
    35             msg = u(msg) + u"\n"
    35             msg = u(msg) + u"\n"
    36     if type(msg) is unicode:
    36     if type(msg) is str:
    37         msg = codecs.encode(msg, sys.stderr.encoding)
    37         msg = codecs.encode(msg, sys.stderr.encoding)
    38     sys.stderr.write(msg)
    38     sys.stderr.write(msg)
    39 
    39 
    40 optParser = OptionParser()
    40 optParser = OptionParser()
    41 optParser.add_option("-C", "--old-syntax", action="store_true", dest="old_syntax",
    41 optParser.add_option("-C", "--old-syntax", action="store_true", dest="old_syntax",
   180         transform = etree.XSLT(xsltree)
   180         transform = etree.XSLT(xsltree)
   181         
   181         
   182         if options.params:
   182         if options.params:
   183             params = eval(options.params)
   183             params = eval(options.params)
   184             for key, value in params.iteritems():
   184             for key, value in params.iteritems():
   185                 if type(value) != unicode:
   185                 if type(value) != str:
   186                     params[key] = u(value)
   186                     params[key] = u(value)
   187         if options.stringparams:
   187         if options.stringparams:
   188             for key, value in eval(options.stringparams).iteritems():
   188             for key, value in eval(options.stringparams).iteritems():
   189                 params[key] = u"'" + u(value) + u"'"
   189                 params[key] = u"'" + u(value) + u"'"
   190 
   190 
   201         rtext = unicodedata.normalize(options.normalization, rtext)
   201         rtext = unicodedata.normalize(options.normalization, rtext)
   202 
   202 
   203     if options.pretty:
   203     if options.pretty:
   204         plaintext = etree.tostring(etree.fromstring(rtext), pretty_print=True, xml_declaration=True, encoding=options.encoding)
   204         plaintext = etree.tostring(etree.fromstring(rtext), pretty_print=True, xml_declaration=True, encoding=options.encoding)
   205     else:
   205     else:
   206         if isinstance(rtext, unicode):
   206         if isinstance(rtext, str):
   207             plaintext = codecs.encode(rtext, options.encoding)
   207             plaintext = codecs.encode(rtext, options.encoding)
   208         else:
   208         else:
   209             plaintext = str(rtext)
   209             plaintext = str(rtext)
   210 
   210 
   211     try:
   211     try: