MCPcopy Create free account
hub / github.com/davidblewett/rure-python / __init__

Method __init__

rure/lib.py:52–91  ·  view source on GitHub ↗

Compiles a regular expression. Once compiled, it can be used repeatedly to search, split or replace text in a string. :param re: Bytestring expression to compile :param flags: Bitmask of flags :param kwargs: Config options to pass (size_limit, dfa_size_limit

(self, re, _pointer=None,
                 flags=DEFAULT_FLAGS, **options)

Source from the content-addressed store, hash-verified

50 """
51
52 def __init__(self, re, _pointer=None,
53 flags=DEFAULT_FLAGS, **options):
54 """ Compiles a regular expression. Once compiled, it can be used
55 repeatedly to search, split or replace text in a string.
56
57 :param re: Bytestring expression to compile
58 :param flags: Bitmask of flags
59 :param kwargs: Config options to pass (size_limit, dfa_size_limit)
60 """
61 if not isinstance(re, bytes):
62 raise TypeError("'rure.lib.Rure' must be instantiated with a "
63 "bytestring as first argument.")
64
65 self._err = _native.ffi.gc(_native.lib.rure_error_new(), _native.lib.rure_error_free)
66 self._opts = _native.ffi.gc(_native.lib.rure_options_new(), _native.lib.rure_options_free)
67
68 self.options = options
69 if 'size_limit' in options:
70 _native.lib.rure_options_size_limit(self._opts, options['size_limit'])
71 if 'dfa_size_limit' in options:
72 _native.lib.rure_options_dfa_size_limit(self._opts,
73 options['dfa_size_limit'])
74
75 if _pointer is None:
76 s = checked_call(
77 _native.lib.rure_compile,
78 self._err,
79 re,
80 len(re),
81 flags,
82 self._opts
83 )
84 else:
85 s = _pointer
86 self._ptr = _native.ffi.gc(s, _native.lib.rure_free)
87 self.capture_cls = namedtuple(
88 'Captures',
89 [i.decode('utf8') if i else u'' for i in self.capture_names()],
90 rename=True
91 )
92
93 @accepts_bytes
94 def capture_name_index(self, name):

Callers

nothing calls this directly

Calls 2

capture_namesMethod · 0.95
checked_callFunction · 0.85

Tested by

no test coverage detected