Exemple #1
0
    def _test_execute( self, type, testcontent, count, ref='', cfunc=None  ) :
        # Initialising the parser
        etparser = ETParser( lex_optimize=True, yacc_optimize=False )

        # The first character is forced to be a `A` to avoid having `@` as the
        # first character
        testcontent = 'A' + testcontent

        # Characterize the generated testcontent set the wikiproperties
        wikiprops   = {}
        testcontent = ( "@ %s " % wikiprops ) + '\n' + testcontent
        
        # Test by comparing the dumps
        try :
            tu      = etparser.parse( testcontent, debuglevel=0 )
            result  = tu.dump()[:-1]
        except :
            tu     = etparser.parse( testcontent, debuglevel=2 )
            result = tu.dump()[:-1]

        # The reference is computed if no compare function (cfunc) is passed.
        if cfunc :
            cfunc( ref, tu )
        else :
            ref        = ref or testcontent
            ref        = etparser._wiki_preprocess( ref )
            props, ref = wiki_properties( ref )
            if result != ref :
                print ''.join(diff.ndiff( result.splitlines(1), ref.splitlines(1) ))
            assert result == ref, type+'... testcount %s'%count
Exemple #2
0
    def _test_execute(self, type, testcontent, count, ref=''):
        # Initialising the parser
        etparser = ETParser(lex_optimize=True, yacc_optimize=False)
        # The first character is forced to be a `A` to avoid having `@` as the
        # first character
        testcontent = 'A' + testcontent
        # Prepare the reference.
        ref = ref or testcontent
        ref = etparser._wiki_preprocess(ref)
        props, ref = wiki_properties(ref)

        # Characterize the generated testcontent set the wikiproperties
        wikiprops = {}
        testcontent = ("@ %s " % wikiprops) + '\n' + testcontent

        # Test by comparing the dumps
        try:
            tu = etparser.parse(testcontent, debuglevel=0)
            result = tu.dump()[:-1]
        except:
            # open( 'testcontent', 'w' ).write( testcontent )
            tu = etparser.parse(testcontent, debuglevel=2)
            result = tu.dump()[:-1]
        if result != ref:
            # open( 'result', 'w' ).write( result )
            # open( 'ref', 'w' ).write( ref )
            print ''.join(diff.ndiff(result.splitlines(1), ref.splitlines(1)))
        assert result == ref, type + '... testcount %s' % count
Exemple #3
0
    def html( self, node, igen, *args, **kwargs ) :
        from   eazytext.parser import ETParser

        fn = lambda (k, v) : '%s : %s' % (k,v)

        boxstyle = '; '.join(map( fn, self.css.items() ))
        if self.style :
            boxstyle += '; %s ;' % self.style

        titlestyle = '; '.join(map( fn, self.title_css.items() ))
        if self.titlestyle  :
            titlestyle += '; %s ;' % self.titlestyle

        contstyle = '; '.join(map( fn, self.cont_css.items() ))
        if self.contentstyle :
            contstyle += '; %s ;' % self.contentstyle

        self.nowiki_h = ''
        if self.nowiki :
            etparser = ETParser(
                             skin=None,
                             nested=True,
                             lex_optimize=False,
                             yacc_optimize=False,
                       )
            tu = etparser.parse( self.nowiki, debuglevel=0 )
            self.nowiki_h = tu.tohtml()

        if self.title :
            html = tmpl % ( boxstyle, titlestyle, self.title, spantmpl,
                            contstyle, self.nowiki_h )
        else :
            html = tmpl % ( boxstyle, titlestyle, self.title, '',
                            contstyle, self.nowiki_h )
        return html
Exemple #4
0
    def _test_execute( self, type, testcontent, count, ref=''  ) :
        # Initialising the parser
        etparser     = ETParser( lex_optimize=True, yacc_optimize=False )
        # The first character is forced to be a `A` to avoid having `@` as the
        # first character
        testcontent = 'A' + testcontent
        # Prepare the reference.
        ref        = ref or testcontent
        ref        = etparser._wiki_preprocess( ref )
        props, ref = wiki_properties( ref )

        # Characterize the generated testcontent set the wikiproperties
        wikiprops   = {}
        testcontent = ( "@ %s " % wikiprops ) + '\n' + testcontent
        
        # Test by comparing the dumps
        try :
            tu      = etparser.parse( testcontent, debuglevel=0 )
            result  = tu.dump()[:-1]
        except :
            # open( 'testcontent', 'w' ).write( testcontent )
            tu     = etparser.parse( testcontent, debuglevel=2 )
            result = tu.dump()[:-1]
        if result != ref :
            # open( 'result', 'w' ).write( result )
            # open( 'ref', 'w' ).write( ref )
            print ''.join(diff.ndiff( result.splitlines(1), ref.splitlines(1) ))
        assert result == ref, type+'... testcount %s'%count
Exemple #5
0
    def _test_execute(self, type, testcontent, count, ref="", cfunc=None):
        # Initialising the parser
        etparser = ETParser(lex_optimize=True, yacc_optimize=False)

        # The first character is forced to be a `A` to avoid having `@` as the
        # first character
        testcontent = "A" + testcontent

        # Characterize the generated testcontent set the wikiproperties
        wikiprops = {}
        testcontent = ("@ %s " % wikiprops) + "\n" + testcontent

        # Test by comparing the dumps
        try:
            tu = etparser.parse(testcontent, debuglevel=0)
            result = tu.dump()[:-1]
        except:
            tu = etparser.parse(testcontent, debuglevel=2)
            result = tu.dump()[:-1]

        # The reference is computed if no compare function (cfunc) is passed.
        if cfunc:
            cfunc(ref, tu)
        else:
            ref = ref or testcontent
            ref = etparser._wiki_preprocess(ref)
            props, ref = wiki_properties(ref)
            if result != ref:
                print "".join(diff.ndiff(result.splitlines(1), ref.splitlines(1)))
            assert result == ref, type + "... testcount %s" % count
Exemple #6
0
    def test_2_parsermethods( self ) :
        """Testing methods provided by parsers"""
        log.info( "Testing methods provided by parsers" )

        # wiki_properties()
        refprop = { 'a': 1, 'b': 2 }
        etp = ETParser(lex_optimize=True, yacc_optimize=False, yacc_debug=False)
        prop, text = wiki_properties( wikiproptext1 )
        assert_equal( prop, {}, 'Mismatch in `prop` for `wikiproptext1`' )
        assert_equal( text, 'hello world\n',
                      'Mismatch in `text` for `wikiproptext1`' )

        prop, text = wiki_properties( wikiproptext2 )
        assert_equal( prop, refprop, 'Mismatch in `prop` for `wikiproptext2`' )
        assert_equal( text, '\nhello world\n', 
                      'Mismatch in `text` for `wikiproptext1`' )

        prop, text = wiki_properties( wikiproptext3 )
        assert_equal( prop, refprop, 'Mismatch in `prop` for `wikiproptext3`' )
        assert_equal( text, 'hello world\n', 
                      'Mismatch in `text` for `wikiproptext3`' )

        # Check style agreegation
        etp = ETParser( style={ 'border' : '1px solid gray',
                                'margin-top' : '10px',
                                'style' : { 'display' : 'block',
                                            'style' : 'margin-left : 10px' },
                              },
                        lex_optimize=True, yacc_optimize=False, yacc_debug=False )
        etp.parse( aggr_wikiprop )
        refstyle = 'border : 1px solid gray; display : block; ' + \
                   'margin-left : 10px; color : brown; font-style : italic; ' +\
                   'margin-top : 5px'
        assert_equal( sorted(etp.styleattr), sorted(refstyle),
                      'Mismatch in style aggregation' )
Exemple #7
0
    def html(self, node, igen, *args, **kwargs):
        from eazytext.parser import ETParser

        fn = lambda (k, v): '%s : %s' % (k, v)

        boxstyle = '; '.join(map(fn, self.css.items()))
        if self.style:
            boxstyle += '; %s ;' % self.style

        titlestyle = '; '.join(map(fn, self.title_css.items()))
        if self.titlestyle:
            titlestyle += '; %s ;' % self.titlestyle

        contstyle = '; '.join(map(fn, self.cont_css.items()))
        if self.contentstyle:
            contstyle += '; %s ;' % self.contentstyle

        self.nowiki_h = ''
        if self.nowiki:
            etparser = ETParser(
                skin=None,
                nested=True,
                lex_optimize=False,
                yacc_optimize=False,
            )
            tu = etparser.parse(self.nowiki, debuglevel=0)
            self.nowiki_h = tu.tohtml()

        if self.title:
            html = tmpl % (boxstyle, titlestyle, self.title, spantmpl,
                           contstyle, self.nowiki_h)
        else:
            html = tmpl % (boxstyle, titlestyle, self.title, '', contstyle,
                           self.nowiki_h)
        return html
Exemple #8
0
 def __init__(self, etxloc=None, etxtext=None, etxconfig={}):
     """`etxconfig` parameter will find its way into every object defined
     by wiki processor.
         TODO : somehow find a way to pass the arguments to `body` function
     """
     self.etxconfig = dict(defaultconfig.items())
     self.etxconfig.update(etxconfig)
     self.etxconfig.setdefault('devmod', DEVMOD)
     # Initialize plugins
     self.etxconfig = initplugins(self.etxconfig,
                                  force=self.etxconfig['devmod'])
     self.etxloc, self.etxtext = etxloc, etxtext
     self.etparser = ETParser(etxconfig=self.etxconfig)
Exemple #9
0
    def test_2_parsermethods(self):
        """Testing methods provided by parsers"""
        log.info("Testing methods provided by parsers")

        # wiki_properties()
        refprop = {'a': 1, 'b': 2}
        etp = ETParser(lex_optimize=True,
                       yacc_optimize=False,
                       yacc_debug=False)
        prop, text = wiki_properties(wikiproptext1)
        assert_equal(prop, {}, 'Mismatch in `prop` for `wikiproptext1`')
        assert_equal(text, 'hello world\n',
                     'Mismatch in `text` for `wikiproptext1`')

        prop, text = wiki_properties(wikiproptext2)
        assert_equal(prop, refprop, 'Mismatch in `prop` for `wikiproptext2`')
        assert_equal(text, '\nhello world\n',
                     'Mismatch in `text` for `wikiproptext1`')

        prop, text = wiki_properties(wikiproptext3)
        assert_equal(prop, refprop, 'Mismatch in `prop` for `wikiproptext3`')
        assert_equal(text, 'hello world\n',
                     'Mismatch in `text` for `wikiproptext3`')

        # Check style agreegation
        etp = ETParser(style={
            'border': '1px solid gray',
            'margin-top': '10px',
            'style': {
                'display': 'block',
                'style': 'margin-left : 10px'
            },
        },
                       lex_optimize=True,
                       yacc_optimize=False,
                       yacc_debug=False)
        etp.parse(aggr_wikiprop)
        refstyle = 'border : 1px solid gray; display : block; ' + \
                   'margin-left : 10px; color : brown; font-style : italic; ' +\
                   'margin-top : 5px'
        assert_equal(sorted(etp.styleattr), sorted(refstyle),
                     'Mismatch in style aggregation')
Exemple #10
0
def etx_cmdline(etxloc, **kwargs):
    from eazytext.compiler import Compiler

    htmlfile = kwargs.get('ofile', '')
    etxconfig = dict(defaultconfig.items())
    # directories, module_directory, devmod
    etxconfig.update(kwargs)
    etxconfig['module_directory'] = u'.'
    etxconfig['include_skin'] = True
    etxconfig['ashtml'] = True

    # Parse command line arguments and configuration
    context = eval(etxconfig.pop('context', '{}'))
    debuglevel = etxconfig.pop('debuglevel', 0)
    show = etxconfig.pop('show', False)
    dump = etxconfig.pop('dump', False)
    encoding = etxconfig['input_encoding']

    # Initialize plugins)
    etxconfig.setdefault('devmod', DEVMOD)
    etxconfig = initplugins(etxconfig, force=etxconfig['devmod'])

    # Setup parser
    etparser = ETParser(etxconfig=etxconfig, debug=debuglevel)
    compiler = Compiler(etxloc=etxloc, etxconfig=etxconfig, etparser=etparser)
    pyfile = compiler.etxfile + '.py'
    if not htmlfile:
        htmlfile = basename(compiler.etxfile).rsplit('.', 1)[0] + '.html'
        htmlfile = join(dirname(compiler.etxfile), htmlfile)

    if debuglevel:
        print "AST tree ..."
        tu = compiler.toast()
    elif show:
        print "AST tree ..."
        tu = compiler.toast()
        tu.show()
    elif dump:
        from eazytext.ast import Context
        tu = compiler.toast()
        rctext = tu.dump(Context())
        text = codecs.open(compiler.etxfile, encoding=encoding).read()
        if rctext[:-1] != text:
            print "Mismatch ..."
            sys.exit(1)
        else:
            print "Success ..."
    else:
        print "Generating py / html file ... "
        pytext = compiler.topy(etxhash=compiler.etxlookup.etxhash)
        # Intermediate file should always be encoded in 'utf-8'
        codecs.open(pyfile, mode='w', encoding=DEFAULT_ENCODING).write(pytext)

        t = Translate(etxloc=etxloc, etxconfig=etxconfig)
        html = t(context=deepcopy(context))
        codecs.open(htmlfile, mode='w', encoding=encoding).write(html)

        # This is for measuring performance
        st = dt.now()
        [
            Translate(etxloc=etxloc,
                      etxconfig=etxconfig)(context=deepcopy(context))
            for i in range(2)
        ]