Beispiel #1
0
def compile(pattern, flags=0):
    "Compile a regular expression pattern, returning a pattern object."

    if _jsre._is_valid(pattern):
       return _jsre.compile(pattern, flags)

    return _pyre().compile(pattern, flags)
Beispiel #2
0
def compile(pattern, flags=0):
    "Compile a regular expression pattern, returning a pattern object."

    if _jsre._is_valid(pattern):
        return _jsre.compile(pattern, flags)

    return _pyre().compile(pattern, flags)
Beispiel #3
0
 def __init__(self, expected, test_case, callable_obj=None,
              expected_regex=None):
     self.expected = expected
     self.test_case = test_case
     if callable_obj is not None:
         try:
             self.obj_name = callable_obj.__name__
         except AttributeError:
             self.obj_name = str(callable_obj)
     else:
         self.obj_name = None
     if isinstance(expected_regex, (bytes, str)):
         expected_regex = re.compile(expected_regex)
     self.expected_regex = expected_regex
     self.msg = None
Beispiel #4
0
# issue 873
str(globals())

# issue 883
for _ in range(2):
    for _ in range(2):
        pass

# issue 900
"".format(**globals())

# issue 901 : _jsre's SRE_Pattern lacking methods: .sub(), .subn(), .split(), and .fullmatch()
import _jsre as re

regex = re.compile('a|b')

# These methods work!
assert regex.match('ab') is not None
assert regex.search(' ab') is not None
assert regex.findall('ab') == ['a', 'b']


def switch(m):
    return 'a' if m.group(0) == 'b' else 'b'


# Missing: .sub()
assert regex.sub(switch, 'ba') == 'ab'

# Missing: .fullmatch()
Beispiel #5
0
    }

def _quote(str, LegalChars=_LegalChars):
    r"""Quote a string for use in a cookie header.

    If the string does not need to be double-quoted, then just return the
    string.  Otherwise, surround the string in doublequotes and quote
    (with a \) special characters.
    """
    if all(c in LegalChars for c in str):
        return str
    else:
        return '"' + _nulljoin(_Translator.get(s, s) for s in str) + '"'


_OctalPatt = re.compile(r"\\[0-3][0-7][0-7]")
_QuotePatt = re.compile(r"[\\].")

def _unquote(str):
    # If there aren't any doublequotes,
    # then there can't be any special characters.  See RFC 2109.
    if len(str) < 2:
        return str
    if str[0] != '"' or str[-1] != '"':
        return str

    # We have to assume that we must decode this string.
    # Down to work.

    # Remove the "s
    str = str[1:-1]

def _quote(str, LegalChars=_LegalChars):
    r"""Quote a string for use in a cookie header.

    If the string does not need to be double-quoted, then just return the
    string.  Otherwise, surround the string in doublequotes and quote
    (with a \) special characters.
    """
    if all(c in LegalChars for c in str):
        return str
    else:
        return '"' + _nulljoin(_Translator.get(s, s) for s in str) + '"'


_OctalPatt = re.compile(r"\\[0-3][0-7][0-7]")
_QuotePatt = re.compile(r"[\\].")


def _unquote(str):
    # If there aren't any doublequotes,
    # then there can't be any special characters.  See RFC 2109.
    if len(str) < 2:
        return str
    if str[0] != '"' or str[-1] != '"':
        return str

    # We have to assume that we must decode this string.
    # Down to work.

    # Remove the "s
Beispiel #7
0
# issue 873
str(globals())

# issue 883
for _ in range(2):
    for _ in range(2):
        pass

# issue 900
"".format(**globals())

# issue 901 : _jsre's SRE_Pattern lacking methods: .sub(), .subn(), .split(), and .fullmatch()
import _jsre as re

regex = re.compile('a|b')

# These methods work!
assert regex.match('ab') is not None
assert regex.search(' ab') is not None
assert regex.findall('ab') == ['a', 'b']

def switch(m):
    return 'a' if m.group(0) == 'b' else 'b'

# Missing: .sub()
assert regex.sub(switch, 'ba') == 'ab'

# Missing: .fullmatch()
# assert regex.fullmatch('b') is not None