Edgewall Software

Changeset 390 for trunk/genshi/input.py


Ignore:
Timestamp:
Oct 24, 2006, 5:52:57 PM (17 years ago)
Author:
cmlenz
Message:

Configurable encoding of template files, closing #65.

  • The XMLParser constructor now accepts an optional encoding parameter.
  • The MarkupTemplate and TextTemplate class also get an encoding parameter in their initializers.
  • A default_encoding can be specified when creating a TemplateLoader instance, but the encoding can also be specified explicitly when calling the load() method.
  • Encodings specified using an XML declaration in templates and XML files are now honored (as long as Expat supports them, that is, and it doesn't support many).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/genshi/input.py

    r386 r390  
    7676    _external_dtd = '\n'.join(_entitydefs)
    7777
    78     def __init__(self, source, filename=None):
     78    def __init__(self, source, filename=None, encoding=None):
    7979        """Initialize the parser for the given XML input.
    8080       
    8181        @param source: the XML text as a file-like object
    8282        @param filename: the name of the file, if appropriate
     83        @param encoding: the encoding of the file; if not specified, the
     84            encoding is assumed to be ASCII, UTF-8, or UTF-16, or whatever the
     85            encoding specified in the XML declaration (if any)
    8386        """
    8487        self.source = source
     
    8689
    8790        # Setup the Expat parser
    88         parser = expat.ParserCreate('utf-8', '}')
     91        parser = expat.ParserCreate(encoding, '}')
    8992        parser.buffer_text = True
    9093        parser.returns_unicode = True
Note: See TracChangeset for help on using the changeset viewer.