Did I find the right examples for you? yes no

All Samples(5)  |  Call(5)  |  Derive(0)  |  Import(0)

        def parse_page(inString, cursor=0, endMarker=None, file_path=None, name="[top level]"):
    pname = name
    # XXXX SOMEDAY REFACTOR THIS AND CLEAN IT UP.
    #p "parse_page", (cursor, inString[cursor:cursor+20])
    page_start = cursor
    thePage = page.Page(file_path)
    lenString = len(inString)
    if cursor>lenString:
        raise ValueError, "when parsing page [%s] content at start: cursor beyond string end "%pname+repr((cursor, lenString))
    # skip whitespace
    cursor = skipws(inString, cursor)
    # look for {{env .. /}} environment modifier
    test = True
    while test:
        test = matchAtCursor(inString, "{{env", cursor)
        if test and inString[test]=="-":
            test = False # may match get-env
        if test:
            cursor = test
            (success, result, nextcursor) = parse_json_descriptor(inString, cursor)
            if success:
                (test, message) = whiffenv.check_environment_message(result)
                if not test:
                    return (False, message, cursor)
                thePage.add_environment_dict(result)
                cursor = nextcursor
            else:
                return (False, result, nextcursor)
            test = matchAtCursor(inString, "/}}", cursor)
            if test:
                cursor = test
            else:
                #pr "json parse got", result
                return (False, "Parsing environment at page [%s] begin -- could not parse to end of '{{env' json specification: expect /}} or comma found:"%pname+repr(inString[cursor:cursor+4]), cursor)
    # look for {{require page formal parameters
    # OR cgi-default specifications 
    test = True    
    while test:
        scursor = skipws(inString, cursor)
        #p "looking for require at", repr(inString[scursor:scursor+20])
        test = matchAtCursor(inString, "{{require", scursor)
        if test:
            cursor = test
            test = nextMatchEnd(inString, "}}", cursor+1)
            has_default_value = False
            if not test:
                return (False, "'Parsing page [%s] formal parameters -- {{require' not terminated by '}}'"%pname, cursor)
            elif inString[test-3:test]!="/}}":
                # form is {{require name}} page {{/require}}
                has_default_value = True
                #test = nextMatchEnd(inString, "}}", cursor+1)
                nameEnd = test-2
            else:
                # form is {{require name/}}
                nameEnd = test-3
            namechunk = inString[cursor:nameEnd]
            #p "namechunk", namechunk
            sname = namechunk.split()
            if len(sname)!=1:
                return (False, "parsing page [%s] formal argument {{require -- expect argument name containing no whitespace"%pname+repr(sname), cursor)
            name = sname[0]
            name = dropQuotes(name)
            default_value = None
            cursor = test
            if has_default_value:
                # parse a page terminated by {{/require}}
                (test, result, endLocation) = parse_page(inString, cursor, "{{/require}}", file_path=file_path, name=name)
                if test:
                    default_value = page.DeferPageBindings(result)
                    cursor = endLocation
                    # Eat the end {{/require}}
                    test = matchAtCursor(inString, "{{/require}}", cursor, True)
                    if test:
                        cursor = test
                    else:
                        return (False, 'parsing page [%s] formal argument [%s] -- after default page did not find "{{/require}}"'%(pname, name), cursor)
                else:
                    return (test, 'parsing page [%s] formal argument %s -- '%(pname,name)+result, endLocation) # pass on the complaint from page_parse
            #pr "add page require default", default_value
            thePage.add_require(name, default_value)
        else:
            test = matchAtCursor(inString, "{{cgi-default", scursor)
            if test:
                cursor = test
                # parse format {{cgi-default NAME}}VALUE{{/cgi-default}}
                test = nextMatchEnd(inString, "}}", cursor+1)
                if not test:
                    return (False, "parsing page [%s] formal parameters -- '{{cgi-default' not terminated by '}}'"%pname, cursor)
                nameEnd = test-2
                namechunk = inString[cursor:nameEnd]
                if not namechunk:
                    return (False, "parsing page [%s] formal parameters -- '{{cgi-default' has no name field"%pname, cursor)
                if namechunk[-1]=="/":
                    return (False, "parsing page [%s] formal parameters -- '{{cgi-default...}}' must be terminated with {{/cgi-default}} not /}}"%pname, cursor)
                sname = namechunk.split()
                if len(sname)!=1:
                    return (False, "parsing page [%s] formal parameters -- cgi-default name must contain no whitespace"%pname, cursor)
                name = sname[0]
                name = dropQuotes(name)
                cursor = test
                (test, result, endLocation) = parse_page(inString, cursor, "{{/cgi-default}}", file_path=file_path, name=name)
                if test:
                    # eat the end marker
                    cursor = endLocation
                    test = matchAtCursor(inString, "{{/cgi-default}}", cursor, True)
                    if not test:
                        #pr (cursor, inString[:cursor], inString[cursor:])
                        return (False, "parsing page [%s] formal parameters -- after '{{cgi-default' %s did not find {{/cgi-default}}"%(pname,name), cursor)
                    cursor = test
                    #pr "add cgi-default page", result
                    thePage.add_cgi_default(name, result)
                else:
                    # pass on page parsing complaint
                    return (False, 'parsing page [%s] formal parameters cgi-default %s -- '%(pname, name)+result, endLocation)
        # return to top of require search loop
    # parse remainder as stream components
    while cursor
    


src/w/h/whiff-1.1/whiff/middleware/expandPostedTemplate.py   whiff(Download)
            print >> sys.stderr,"verbose: END OF TEMPLATE TEXT"
        # create the template
        (test, result, cursor) = parseTemplate.parse_page(templateText, file_path="[posted template: %s...]"% repr(templateText.strip()[:80]))
        if not test:
            c1 = templateText[ max(0, cursor-20): cursor ]

src/w/h/whiff-1.1/whiff/middleware/Eval.py   whiff(Download)
        page = self.param_value(self.page, env)
        #pr "evalling page of len", len(page)
        (test, result, cursor) = parseTemplate.parse_page(page, file_path="[Eval argument: %s...]" % repr(page.strip()[:80]))
        if not test:
            c1 = page[ max(0, cursor-20): cursor ]

src/w/h/whiff-1.1/whiff/middleware/callPageWithStrings.py   whiff(Download)
    pathr = []
    outer_args = {}
    (test, page, cursor) = parseTemplate.parse_page("page with ARG= [{{use ARG/}}]", file_path="(test)")
    if not test:
        c1 = templateText[ max(0, cursor-20): cursor ]

src/w/h/whiff-1.1/scripts/whiff_parse.py   whiff(Download)
def testparse(filepath):
    text = open(filepath).read()
    (test, result, cursor) = parseTemplate.parse_page(text, file_path=filepath)
    if not test:
        raise ValueError, "whiff template parse failed: "+repr((result, cursor))

src/w/h/whiff-1.1/whiff/middleware/getPage.py   whiff(Download)
            print "verbose: END OF TEMPLATE TEXT"
        # create the template
        (test, result, cursor) = parseTemplate.parse_page(templateText)
        if not test:
            c1 = templateText[ max(0, cursor-20): cursor ]