当前位置: 首页>>代码示例>>Python>>正文


Python parser.Parser类代码示例

本文整理汇总了Python中slimit.parser.Parser的典型用法代码示例。如果您正苦于以下问题:Python Parser类的具体用法?Python Parser怎么用?Python Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: analyzeJSCodesFinerBlock

def analyzeJSCodesFinerBlock(script, display=False):
  try:
    t1 = time.time()
    parser = Parser()
    script = script.strip()
    if script.startswith('<!--') and script.endswith('-->'):
      script = script[4: -3]
    tree = parser.parse(script)
    visitor = MyVisitor( display)
    visitor.visit(tree, 0)
    if len(visitor.first_level_seq) != len(visitor.scripts):
      print >>sys.stderr, "error parsing script: scripts and seqs length inconsistent "+script[:100]
      return None, None
    t2 = time.time()
    total_time = t2 - t1
    total_len = float(len(script))
    try:
      portion = [len(x)/total_len for x in visitor.scripts]
      for i in range(len(portion)):
        t = total_time * portion[i]
        print "AST_TIME: %f %d" %(t, len(visitor.scripts[i]))    
    except:
      pass
    return visitor.first_level_seq, visitor.scripts
  except Exception as e:
    print >>sys.stderr, "error parsing script: "+str(e)+" || [START]"+script[:100]+"[END]"
    return None, None
开发者ID:ziy212,项目名称:HeadlessBrowser,代码行数:27,代码来源:script_analyzer.py

示例2: find_first_match

 def find_first_match(test_file_content, pos):
   test_file_content = TestMethodMatcher.UnitTest.insert_mark(test_file_content, pos)
   if not test_file_content:
     return None
   parser = Parser()
   tree = parser.parse(test_file_content)
   return TestMethodMatcher.UnitTest.get_test_name(tree)
开发者ID:emn178,项目名称:sublime-text-2-teaspoon,代码行数:7,代码来源:Teaspoon.py

示例3: extract_glow_lib

def extract_glow_lib():
    runjs = norm_path('untrusted/run.js')
    parser = JSParser()

    with open(runjs) as f:
        tree = parser.parse(f.read())

    for node in nodevisitor.visit(tree):
        if (isinstance(node, ast.Assign) and
            isinstance(node.left, ast.DotAccessor) and
            node.left.identifier.value == 'glowscript_libraries' and
            isinstance(node.right, ast.Object)):
                break
    else:
        print('Parsing {} failed'.format(runjs))
        exit(-1)

    return preproc_lib_path({
        prop.left.value:
            [
                eval(lib.value)
                for lib in prop.right.items
                if isinstance(lib, ast.String)
            ]
            for prop in node.right.properties
    })
开发者ID:BruceSherwood,项目名称:glowscript,代码行数:26,代码来源:build_cli.py

示例4: extract

    def extract(self, node):
        '''
        Given a BeautifulSoup representation of an HTML document,
        return a list of all code snippets in that document.
        '''

        node_code = None
        code_snippets = []

        # Attempt to parse content for a code node as JavaScript.
        # Mark the content as a code snippet if it is parsed successfully.
        # Skip nodes with nothing but whitespace content.
        if type(node) is Tag and node.name in self.TAGS:
            if node.text.strip() != '':
                try:
                    js_parser = JavaScriptParser()
                    js_parser.parse(node.text)
                except (SyntaxError, TypeError, AttributeError):
                    logger.debug("Code content could not be parsed as JavaScript.")
                else:
                    node_code = node.text
                    code_snippets.append(node_code)

        # If this node did not contain valid code, then visit all children
        # and check them for code.
        if node_code is None and hasattr(node, 'children'):
            for child_element in node.children:
                code_snippets.extend(self.extract(child_element))

        return code_snippets
开发者ID:andrewhead,项目名称:Package-Qualifiers,代码行数:30,代码来源:code.py

示例5: load_data

def load_data():
    # Read list names (toplists.js)
    f = open("./data/masterbugtable.js", "r")
    tmp = f.read()
    f.close()
    masterbugtable = json.loads(tmp[tmp.index("{") :])
    # find and process latest test data
    f = open("./data/testing/index.json", "r")
    tmp = f.read()
    f.close()
    test_file_index = json.loads(tmp)
    f = open("./data/testing/%s" % test_file_index[-1], "r")
    test_data = {}
    test_reader = csv.reader(f)
    for line in test_reader:
        test_data[str(line[0])] = {"bug": line[0], "test_date": line[1], "ua": line[2], "test_state": line[3]}
    f.close()
    f = open("./data/sitedata.js", "r")
    parser = Parser()
    tree = parser.parse(f.read())
    f.close()
    return {
        "masterbugtable": masterbugtable,
        "test_result_files": test_file_index,
        "test_results": test_data,
        "tests_parsed": tree,
    }
开发者ID:lonnen,项目名称:mobilewebcompat,代码行数:27,代码来源:siteinfo.py

示例6: minify

def minify(text, mangle=False, mangle_toplevel=False):
    parser = Parser()
    tree = parser.parse(text)
    if mangle:
        mangler.mangle(tree, toplevel=mangle_toplevel)
    minified = ECMAMinifier().visit(tree)
    return minified
开发者ID:BlueMoon3000,项目名称:election-2016,代码行数:7,代码来源:minifier.py

示例7: _parse_succeeds

 def _parse_succeeds(self, text):
     try:
         parser = JsParser()
         parser.parse(text)
     except (SyntaxError, TypeError):
         return False
     else:
         return True
开发者ID:andrewhead,项目名称:tutorons-server,代码行数:8,代码来源:extract.py

示例8: case

    def case(self, case):
        parser_a = Parser()
        result_a = parser_a.parse(case)

        parser_b = Parser()
        result_b = parser_b.parse(case)

        self.assertEqual(result_a, result_b)
开发者ID:lelit,项目名称:slimit,代码行数:8,代码来源:test_visitor.py

示例9: test_func

 def test_func(self):
     parser = Parser()
     tree = parser.parse(input)
     mangle(tree, toplevel=True)
     self.assertMultiLineEqual(
         textwrap.dedent(tree.to_ecma()).strip(),
         textwrap.dedent(expected).strip()
         )
开发者ID:BlueMoon3000,项目名称:election-2016,代码行数:8,代码来源:test_mangler.py

示例10: whileExtract

def whileExtract(s):
    '''Extracts all the while loops in the script. '''
    l = []
    parser = Parser()
    tree = parser.parse(s)
    for node in nodevisitor.visit(tree):
        if isinstance(node, ast.While):
            l+=[node.to_ecma()]
    return l
开发者ID:shidan1,项目名称:workshop,代码行数:9,代码来源:StringExtractor.py

示例11: _parse_redirect_to_security_challenge_script

def _parse_redirect_to_security_challenge_script(script: str) -> str:
    """ Parses the script which redirects us to security challenge page and gets that URL. """
    parser = Parser()
    tree = parser.parse(script)
    nodes = [node for node in nodevisitor.visit(tree) if isinstance(node, ast.Assign)]
    for node in nodevisitor.visit(tree):
        if isinstance(node, ast.Assign) and hasattr(node, 'left') and isinstance(node.left, ast.DotAccessor):
            children = node.left.children()
            if len(children) == 2 and children[0].value == 'window' and children[1].value == 'location':
                return node.right.value.strip('\'"')
开发者ID:dmwyatt,项目名称:makebank,代码行数:10,代码来源:login.py

示例12: test_bug_no_semicolon_at_the_end_of_block_plus_newline_at_eof

 def test_bug_no_semicolon_at_the_end_of_block_plus_newline_at_eof(self):
     # https://github.com/rspivak/slimit/issues/3
     text = textwrap.dedent("""
     function add(x, y) {
       return x + y;
     }
     """)
     parser = Parser()
     tree = parser.parse(text)
     self.assertTrue(bool(tree.children()))
开发者ID:EDITD,项目名称:slimit,代码行数:10,代码来源:test_parser.py

示例13: analyzeJSCodes

def analyzeJSCodes(script, display=False):
  try:
    parser = Parser()
    tree = parser.parse(script)
    visitor = MyVisitor( display)
    visitor.visit(tree, 0)
    #print "first_level_seq: %d" %len(visitor.first_level_seq)
    return visitor.node_order_list
  except Exception as e:
    print >>sys.stderr, "error parsing script: "+str(e)+" || "+script
    return None
开发者ID:ziy212,项目名称:HeadlessBrowser,代码行数:11,代码来源:script_analyzer.py

示例14: _test_function_expression

 def _test_function_expression(self):
     text = """
     if (true) {
       function() {
         foo;
         location = 'http://anywhere.com';
       }
     }
     """
     parser = Parser()
     parser.parse(text)
开发者ID:EDITD,项目名称:slimit,代码行数:11,代码来源:test_parser.py

示例15: rewriteJSCodes

def rewriteJSCodes(script, display=False):
  try:
    parser = Parser()
    tree = parser.parse(script)
    visitor = RewriteVisitor( display)
    visitor.visit(tree, 0)
    x = ECMAVisitor().visit(tree)
    print x
    #print tree.to_ecma()
    #print "first_level_seq: %d" %len(visitor.first_level_seq)
  except Exception as e:
    print >>sys.stderr, "error parsing script: "+str(e)+" || "+script
开发者ID:ziy212,项目名称:HeadlessBrowser,代码行数:12,代码来源:script_analyzer.py


注:本文中的slimit.parser.Parser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。