예제 #1
0
파일: php.py 프로젝트: Jenyay/outwiker
 def analyse_text(text):
     if shebang_matches(text, r'php'):
         return True
     rv = 0.0
     if re.search(r'<\?(?!xml)', text):
         rv += 0.3
     return rv
예제 #2
0
파일: php.py 프로젝트: trasparente/pygments
 def analyse_text(text):
     if shebang_matches(text, r'php'):
         return True
     rv = 0.0
     if re.search(r'<\?(?!xml)', text):
         rv += 0.3
     return rv
예제 #3
0
    def analyse_text(text):
        def strip_pod(lines):
            in_pod = False
            stripped_lines = []

            for line in lines:
                if re.match(r'^=(?:end|cut)', line):
                    in_pod = False
                elif re.match(r'^=\w+', line):
                    in_pod = True
                elif not in_pod:
                    stripped_lines.append(line)

            return stripped_lines

        # XXX handle block comments
        lines = text.splitlines()
        lines = strip_pod(lines)
        text = '\n'.join(lines)

        if shebang_matches(text, r'perl6|rakudo|niecza|pugs'):
            return True

        saw_perl_decl = False
        rating = False

        # check for my/our/has declarations
        if re.search(
                r"(?:my|our|has)\s+(?:" + Perl6Lexer.PERL6_IDENTIFIER_RANGE +
                r"+\s+)?[$@%&(]", text):
            rating = 0.8
            saw_perl_decl = True

        for line in lines:
            line = re.sub('#.*', '', line)
            if re.match(r'^\s*$', line):
                continue

            # match v6; use v6; use v6.0; use v6.0.0;
            if re.match(r'^\s*(?:use\s+)?v6(?:\.\d(?:\.\d)?)?;', line):
                return True
            # match class, module, role, enum, grammar declarations
            class_decl = re.match(
                r'^\s*(?:(?P<scope>my|our)\s+)?(?:module|class|role|enum|grammar)',
                line)
            if class_decl:
                if saw_perl_decl or class_decl.group('scope') is not None:
                    return True
                rating = 0.05
                continue
            break

        if ':=' in text:
            # Same logic as above for PerlLexer
            rating /= 2

        return rating
예제 #4
0
    def test_shebang_matches(self):
        self.assertTrue(util.shebang_matches("#!/usr/bin/env python", r"python(2\.\d)?"))
        self.assertTrue(util.shebang_matches("#!/usr/bin/python2.4", r"python(2\.\d)?"))
        self.assertTrue(util.shebang_matches("#!/usr/bin/startsomethingwith python", r"python(2\.\d)?"))
        self.assertTrue(util.shebang_matches("#!C:\\Python2.4\\Python.exe", r"python(2\.\d)?"))

        self.assertFalse(util.shebang_matches("#!/usr/bin/python-ruby", r"python(2\.\d)?"))
        self.assertFalse(util.shebang_matches("#!/usr/bin/python/ruby", r"python(2\.\d)?"))
        self.assertFalse(util.shebang_matches("#!", r"python"))
def test_shebang_matches():
    assert util.shebang_matches('#!/usr/bin/env python\n', r'python(2\.\d)?')
    assert util.shebang_matches('#!/usr/bin/python2.4', r'python(2\.\d)?')
    assert util.shebang_matches('#!/usr/bin/startsomethingwith python',
                                r'python(2\.\d)?')
    assert util.shebang_matches('#!C:\\Python2.4\\Python.exe', r'python(2\.\d)?')

    assert not util.shebang_matches('#!/usr/bin/python-ruby', r'python(2\.\d)?')
    assert not util.shebang_matches('#!/usr/bin/python/ruby', r'python(2\.\d)?')
    assert not util.shebang_matches('#!', r'python')
예제 #6
0
    def test_shebang_matches(self):
        self.assert_(util.shebang_matches('#!/usr/bin/env python', r'python(2\.\d)?'))
        self.assert_(util.shebang_matches('#!/usr/bin/python2.4', r'python(2\.\d)?'))
        self.assert_(util.shebang_matches('#!/usr/bin/startsomethingwith python',
                                          r'python(2\.\d)?'))
        self.assert_(util.shebang_matches('#!C:\\Python2.4\\Python.exe',
                                          r'python(2\.\d)?'))

        self.failIf(util.shebang_matches('#!/usr/bin/python-ruby', r'python(2\.\d)?'))
        self.failIf(util.shebang_matches('#!/usr/bin/python/ruby', r'python(2\.\d)?'))
        self.failIf(util.shebang_matches('#!', r'python'))
예제 #7
0
파일: perl.py 프로젝트: axil/blog
    def analyse_text(text):
        def strip_pod(lines):
            in_pod = False
            stripped_lines = []

            for line in lines:
                if re.match(r'^=(?:end|cut)', line):
                    in_pod = False
                elif re.match(r'^=\w+', line):
                    in_pod = True
                elif not in_pod:
                    stripped_lines.append(line)

            return stripped_lines

        # XXX handle block comments
        lines = text.splitlines()
        lines = strip_pod(lines)
        text = '\n'.join(lines)

        if shebang_matches(text, r'perl6|rakudo|niecza|pugs'):
            return True

        saw_perl_decl = False
        rating = False

        # check for my/our/has declarations
        if re.search("(?:my|our|has)\s+(?:" + Perl6Lexer.PERL6_IDENTIFIER_RANGE +
                     "+\s+)?[$@%&(]", text):
            rating = 0.8
            saw_perl_decl = True

        for line in lines:
            line = re.sub('#.*', '', line)
            if re.match('^\s*$', line):
                continue

            # match v6; use v6; use v6.0; use v6.0.0;
            if re.match('^\s*(?:use\s+)?v6(?:\.\d(?:\.\d)?)?;', line):
                return True
            # match class, module, role, enum, grammar declarations
            class_decl = re.match('^\s*(?:(?P<scope>my|our)\s+)?(?:module|class|role|enum|grammar)', line)
            if class_decl:
                if saw_perl_decl or class_decl.group('scope') is not None:
                    return True
                rating = 0.05
                continue
            break

        return rating
예제 #8
0
    def test_shebang_matches(self):
        self.assertTrue(util.shebang_matches('#!/usr/bin/env python', r'python(2\.\d)?'))
        self.assertTrue(util.shebang_matches('#!/usr/bin/python2.4', r'python(2\.\d)?'))
        self.assertTrue(util.shebang_matches('#!/usr/bin/startsomethingwith python',
                                             r'python(2\.\d)?'))
        self.assertTrue(util.shebang_matches('#!C:\\Python2.4\\Python.exe',
                                             r'python(2\.\d)?'))

        self.assertFalse(util.shebang_matches('#!/usr/bin/python-ruby',
                                              r'python(2\.\d)?'))
        self.assertFalse(util.shebang_matches('#!/usr/bin/python/ruby',
                                              r'python(2\.\d)?'))
        self.assertFalse(util.shebang_matches('#!', r'python'))
예제 #9
0
    def analyse_text(text):
        if shebang_matches(text, r'perl'):
            return True

        result = 0

        if re.search(r'(?:my|our)\s+[$@%(]', text):
            result += 0.9

        if ':=' in text:
            # := is not valid Perl, but it appears in unicon, so we should
            # become less confident if we think we found Perl with :=
            result /= 2

        return result
예제 #10
0
 def analyse_text(text):
     return shebang_matches(text, r'ruby(1\.\d)?')
예제 #11
0
파일: julia.py 프로젝트: th0/test2
 def analyse_text(text):
     return shebang_matches(text, r'julia')
예제 #12
0
 def analyse_text(text):
     return shebang_matches(text, r'ruby(1\.\d)?')
예제 #13
0
파일: shell.py 프로젝트: bkerler/PythonQt
 def analyse_text(text):
     if shebang_matches(text, r'(ba|z|)sh'):
         return 1
     if text.startswith('$ '):
         return 0.2
예제 #14
0
 def analyse_text(text):
     return shebang_matches(text, r'pythonw?(3(\.\d)?)?')
예제 #15
0
 def analyse_text(text):
     return shebang_matches(text, shebang_regex)
예제 #16
0
 def analyse_text(text):
     if shebang_matches(text, r'execlineb'):
         return 1
예제 #17
0
 def analyse_text(text):
     return shebang_matches(text, r"(tcl)")
예제 #18
0
 def analyse_text(text):
     return shebang_matches(text, r'requs')
예제 #19
0
 def analyse_text(text):
     if shebang_matches(text, r"(ba|z|)sh"):
         return 1
     if text.startswith("$ "):
         return 0.2
예제 #20
0
파일: converter.py 프로젝트: BoPeng/SOS
 def analyse_text(text):
     return (shebang_matches(text, r'sos-runner') or \
         '#fileformat=SOS' in text[:1000])
예제 #21
0
파일: agile.py 프로젝트: achernet/wxPython
 def analyse_text(text):
     return shebang_matches(text, r'perl(\d\.\d\.\d)?')
예제 #22
0
 def analyse_text(text):
     return shebang_matches(text, shebang_regex)
예제 #23
0
 def analyse_text(text):
     return shebang_matches(text, r'(ba|z|)sh')
예제 #24
0
 def analyse_text(text):
     if shebang_matches(text, r'(ba|z|)sh'):
         return 1
     if text.startswith('$ '):
         return 0.2
예제 #25
0
 def analyse_text(text):
     return shebang_matches(text, r'(ba|z|)sh')
예제 #26
0
 def analyse_text(text):
     return shebang_matches(text, r'pythonw?(2\.\d)?')
예제 #27
0
파일: converter.py 프로젝트: pgcudahy/sos
 def analyse_text(self, text):
     return shebang_matches(
         text, r"sos-runner") or "#fileformat=SOS" in text[:1000]
예제 #28
0
 def analyse_text(text):
     return (shebang_matches(text, r'pythonw?(3(\.\d)?)?') or
             'import ' in text[:1000]) \
         and ('import numpy' in text or 'from numpy import' in text)
예제 #29
0
 def analyse_text(text):
     return shebang_matches(text, r'perl(\d\.\d\.\d)?')
예제 #30
0
 def analyse_text(text):
     return shebang_matches(text, r'pythonw?2(\.\d)?') or \
         'import ' in text[:1000]
예제 #31
0
파일: python.py 프로젝트: bkerler/PythonQt
 def analyse_text(text):
     return shebang_matches(text, r'pythonw?(2(\.\d)?)?') or \
         'import ' in text[:1000]
예제 #32
0
 def analyse_text(text):
     return (shebang_matches(text, r'sos-runner') or \
         '#fileformat=SOS' in text[:1000])
예제 #33
0
파일: python.py 프로젝트: bkerler/PythonQt
 def analyse_text(text):
     return (shebang_matches(text, r'pythonw?(2(\.\d)?)?') or
             'import ' in text[:1000]) \
         and ('import numpy' in text or 'from numpy import' in text)
예제 #34
0
 def analyse_text(text):
     return shebang_matches(text, r'(tcl)')
예제 #35
0
 def analyse_text(text):
     return shebang_matches(text, r'requs')
예제 #36
0
파일: perl.py 프로젝트: axil/blog
 def analyse_text(text):
     if shebang_matches(text, r'perl'):
         return True
     if re.search('(?:my|our)\s+[$@%(]', text):
         return 0.9
예제 #37
0
 def analyse_text(text):
     return shebang_matches(text, r'seq')
예제 #38
0
파일: perl.py 프로젝트: siva600/flask_app
 def analyse_text(text):
     if shebang_matches(text, r'perl'):
         return True
     if re.search('(?:my|our)\s+[$@%(]', text):
         return 0.9
예제 #39
0
파일: pygments.py 프로젝트: EuPaulo/pytuga
 def analyse_text(text):  # @NoSelf
     return shebang_matches(text, r'pythonw?3(\.\d)?')