def locale_cookie_headers(locale_code): '''Returns HTTP headers setting the cookie that stores the Pyramid locale. ''' # native_str() calls below are because waitress expects # bytes in Python 2 and unicode in Python 3. return [(native_str('Set-Cookie'), native_str('_LOCALE_={0}; expires=' 'Fri, 31-Dec-9999 23:00:00 GMT; Path=/'.format(locale_code)))]
def locale_cookie_headers(locale_code): '''Returns HTTP headers setting the cookie that stores the Pyramid locale. ''' # native_str() calls below are because waitress expects # bytes in Python 2 and unicode in Python 3. return [(native_str('Set-Cookie'), native_str( '_LOCALE_={0}; expires=' 'Fri, 31-Dec-9999 23:00:00 GMT; Path=/'.format(locale_code)))]
def parse(self): """Parse an XML/HTML document to its DOM representation.""" self._parser = parser = sax.make_parser() parser.setFeature(sax.handler.feature_external_pes, False) parser.setFeature(sax.handler.feature_external_ges, False) parser.setFeature(sax.handler.feature_namespaces, False) parser.setProperty(sax.handler.property_lexical_handler, self) parser.setContentHandler(self) source = sax.xmlreader.InputSource() # Sweet XMLReader.parse() documentation says: # "As a limitation, the current implementation only accepts byte # streams; processing of character streams is for further study." # So if source is unicode, we pre-encode it: # TODO Is this dance really necessary? Can't I just call a function? byts = self._source.encode('utf-8') source.setEncoding(native_str('utf-8')) source.setByteStream(BytesIO(byts)) source.setSystemId(self._filename) try: parser.parse(source) except SAXParseException as e: exc = XMLTemplateParseError(e.getMessage(), self._source, self._filename, e.getLineNumber(), e.getColumnNumber()) exc.__cause__ = None raise exc self._doc._source = self._source return self._doc
def parse(self): self._parser = parser = sax.make_parser() parser.setFeature(sax.handler.feature_external_pes, False) parser.setFeature(sax.handler.feature_external_ges, False) parser.setFeature(sax.handler.feature_namespaces, False) parser.setProperty(sax.handler.property_lexical_handler, self) parser.setContentHandler(self) source = sax.xmlreader.InputSource() # Sweet XMLReader.parse() documentation says: # "As a limitation, the current implementation only accepts byte # streams; processing of character streams is for further study." # So if source is unicode, we pre-encode it: # TODO Is this dance really necessary? Can't I just call a function? byts = self._source.encode('utf-8') source.setEncoding(native_str('utf-8')) source.setByteStream(BytesIO(byts)) source.setSystemId(self._filename) parser.parse(source) return self._doc
def generator(territories): if top_entry: yield (native_str(''), _("- Choose -")) # TODO translate somehow for tup in territories: if len(tup[0]) == 2: # Keep only countries yield tup
def generator(territories): if top_entry: yield (native_str(""), _("- Choose -")) # TODO translate somehow for tup in territories: if len(tup[0]) == 2: # Keep only countries yield tup