Back to index

moin  1.9.0~rc2
Public Member Functions
test_unicode.TestParserOutput Class Reference

List of all members.

Public Member Functions

def test_ParserOutput

Detailed Description

Parser has to generate unicode output. 

Definition at line 20 of file test_unicode.py.


Member Function Documentation

This method aims generally at MoinMoin.parser.text_xslt -
    this parser should encode Unicode input to UTF8 as late as possible.

Definition at line 22 of file test_unicode.py.

00022 
00023     def test_ParserOutput(self):
00024         """ This method aims generally at MoinMoin.parser.text_xslt -
00025             this parser should encode Unicode input to UTF8 as late as possible.
00026         """
00027         request = self.request
00028         assert not request.cfg.allow_xslt, u'allow_xslt should be disabled'
00029         errmsg = []
00030 
00031         # Some examples to verify with additional stuff
00032         parser_raw_input = {
00033             u'text_html': u'<html><body><h1>%s</h1></body></html>',
00034             u'text_irssi': u"[12:01] <RaphaelBosek> %s",
00035             u'text_moin_wiki': u'||<#fefefe> %s ||',
00036             u'text_python': u'if True: print "%s"',
00037             u'text_xslt': u'<?xml version="1.0" encoding="ISO-8859-1"?><!-- %s -->',
00038         }
00039 
00040         # Blacklist for parsers that don't work - this list should be empty !
00041         parser_blacklist = []
00042 
00043         # Create a page if it doesn't exist already.
00044         if not u'page' in request.formatter.__dict__ or not request.formatter.page:
00045             request.formatter.page = Page(request, u'test_parser_unicode_page')
00046             # this temporarily fixes an error with page-names, should be fixed at a central place some time
00047             request.page = Page(request, u'test_parser_unicode_page')
00048 
00049         # Check all parsers for UNICODE output.
00050         for parsername in MoinMoin.parser.modules:
00051             if parsername in parser_blacklist:
00052                 continue
00053 
00054             module = __import__(u'MoinMoin.parser', globals(), {}, [parsername])
00055             parsermodule = getattr(module, parsername)
00056             if u'Parser' in parsermodule.__dict__:
00057                 # Get the parser_input or use a simple fallback if the parser is not found in parser_raw_input
00058                 i = parser_raw_input.get(parsername, u'%s') % u'\xC3\x84\xC3\x96\xC3\x9C\xC3\xE2\x82\xAC\x27'
00059                 p = parsermodule.Parser(i, request)
00060 
00061                 # This is the actual request that would produce an exception, which would usually look like the following:
00062                 # >  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
00063                 # usually occurring in python/lib/StringIO.py:270
00064                 r = request.redirectedOutput(p.format, request.formatter)
00065 
00066                 # This assertion will only be triggered, if the parser does not write unicode at all
00067                 assert isinstance(r, unicode), u'MoinMoin.parser.%s does not write UNICODE data but %s' % (parsername, type(r), )

Here is the call graph for this function:


The documentation for this class was generated from the following file: