File indexing completed on 2024-04-28 15:53:57

0001 class RegexObject():
0002     """
0003    The :class:`RegexObject` class supports the following methods and attributes:
0004         """
0005 
0006     def search(self, string, pos, endpos):
0007         """
0008 
0009         Scan through *string* looking for a location where this regular expression
0010         produces a match, and return a corresponding :class:`MatchObject` instance.
0011         Return ``None`` if no position in the string matches the pattern; note that this
0012         is different from finding a zero-length match at some point in the string.
0013 
0014         The optional second parameter *pos* gives an index in the string where the
0015         search is to start; it defaults to ``0``.  This is not completely equivalent to
0016         slicing the string; the ``'^'`` pattern character matches at the real beginning
0017         of the string and at positions just after a newline, but not necessarily at the
0018         index where the search is to start.
0019 
0020         The optional parameter *endpos* limits how far the string will be searched; it
0021         will be as if the string is *endpos* characters long, so only the characters
0022         from *pos* to ``endpos - 1`` will be searched for a match.  If *endpos* is less
0023         than *pos*, no match will be found, otherwise, if *rx* is a compiled regular
0024         expression object, ``rx.search(self, string, 0, 50)`` is equivalent to
0025         ``rx.search(self, string[:50], 0)``.
0026 
0027         >>> pattern = re.compile(self, "d")
0028         >>> pattern.search(self, "dog")     # Match at index 0
0029         <_sre.SRE_Match object at ...>
0030         >>> pattern.search(self, "dog", 1)  # No match; search doesn't include the "d"
0031 
0032 
0033     """
0034         return MatchObject()
0035     def match(self, string, pos, endpos):
0036         """
0037 
0038         If zero or more characters at the *beginning* of *string* match this regular
0039         expression, return a corresponding :class:`MatchObject` instance.  Return
0040         ``None`` if the string does not match the pattern; note that this is different
0041         from a zero-length match.
0042 
0043         The optional *pos* and *endpos* parameters have the same meaning as for the
0044         :meth:`~search` method.
0045 
0046         >>> pattern = re.compile(self, "o")
0047         >>> pattern.match(self, "dog")      # No match as "o" is not at the start of "dog".
0048         >>> pattern.match(self, "dog", 1)   # Match as "o" is the 2nd character of "dog".
0049         <_sre.SRE_Match object at ...>
0050 
0051         If you want to locate a match anywhere in *string*, use
0052         :meth:`~search` instead (self, see also :ref:`search-vs-match`).
0053 
0054 
0055     """
0056         return MatchObject()
0057     def split(self, string, maxsplit=0):
0058         """
0059 
0060         Identical to the :func:`split` function, using the compiled pattern.
0061 
0062 
0063     """
0064         return [str()]
0065     def findall(self, string, pos, endpos):
0066         """
0067 
0068         Similar to the :func:`findall` function, using the compiled pattern, but
0069         also accepts optional *pos* and *endpos* parameters that limit the search
0070         region like for :meth:`match`.
0071 
0072 
0073     """
0074         return [str()]
0075     def finditer(self, string, pos, endpos):
0076         """
0077 
0078         Similar to the :func:`finditer` function, using the compiled pattern, but
0079         also accepts optional *pos* and *endpos* parameters that limit the search
0080         region like for :meth:`match`.
0081 
0082 
0083     """
0084         return [str()]
0085     def sub(self, repl, string, count=0):
0086         """
0087 
0088         Identical to the :func:`sub` function, using the compiled pattern.
0089 
0090 
0091     """
0092         return str()
0093     def subn(self, repl, string, count=0):
0094         """
0095 
0096         Identical to the :func:`subn` function, using the compiled pattern."""
0097         return str()
0098 
0099     flags = str()
0100     groups = int()
0101     groupindex = {"None": int()}
0102     pattern = SRE_Pattern()
0103 
0104 class MatchObject:
0105     """
0106    Match objects always have a boolean value of ``True``.
0107    Since :meth:`~regex.match` and :meth:`~regex.search` return ``None``
0108    when there is no match, you can test whether there was a match with a simple
0109    ``if`` statement::
0110 
0111       match = re.search(self, pattern, string)
0112       if match:
0113           process(self, match)
0114    """
0115     def expand(self, template):
0116         """
0117 
0118         Return the string obtained by doing backslash substitution on the template
0119         string *template*, as done by the :meth:`~sub` method.  Escapes
0120         such as ``\n`` are converted to the appropriate characters, and numeric
0121         backreferences (self, ``\1``, ``\2``) and named backreferences (self, ``\g<1>``,
0122         ``\g<name>``) are replaced by the contents of the corresponding group.
0123 
0124 
0125         """
0126         return str()
0127     def group(self, group1, *args):
0128         """
0129 
0130         Returns one or more subgroups of the match.  If there is a single argument, the
0131         result is a single string; if there are multiple arguments, the result is a
0132         tuple with one item per argument. Without arguments, *group1* defaults to zero
0133         (self, the whole match is returned). If a *groupN* argument is zero, the corresponding
0134         return value is the entire matching string; if it is in the inclusive range
0135         [1..99], it is the string matching the corresponding parenthesized group.  If a
0136         group number is negative or larger than the number of groups defined in the
0137         pattern, an :exc:`IndexError` exception is raised. If a group is contained in a
0138         part of the pattern that did not match, the corresponding result is ``None``.
0139         If a group is contained in a part of the pattern that matched multiple times,
0140         the last match is returned.
0141 
0142             >>> m = re.match(self, r"(self, \w+) (self, \w+)", "Isaac Newton, physicist")
0143             >>> m.group(self, 0)       # The entire match
0144             'Isaac Newton'
0145             >>> m.group(self, 1)       # The first parenthesized subgroup.
0146             'Isaac'
0147             >>> m.group(self, 2)       # The second parenthesized subgroup.
0148             'Newton'
0149             >>> m.group(self, 1, 2)    # Multiple arguments give us a tuple.
0150             (self, 'Isaac', 'Newton')
0151 
0152         If the regular expression uses the ``(self, ?P<name>...)`` syntax, the *groupN*
0153         arguments may also be strings identifying groups by their group name.  If a
0154         string argument is not used as a group name in the pattern, an :exc:`IndexError`
0155         exception is raised.
0156 
0157         A moderately complicated example:
0158 
0159             >>> m = re.match(self, r"(self, ?P<first_name>\w+) (self, ?P<last_name>\w+)", "Malcolm Reynolds")
0160             >>> m.group(self, 'first_name')
0161             'Malcolm'
0162             >>> m.group(self, 'last_name')
0163             'Reynolds'
0164 
0165         Named groups can also be referred to by their index:
0166 
0167             >>> m.group(self, 1)
0168             'Malcolm'
0169             >>> m.group(self, 2)
0170             'Reynolds'
0171 
0172         If a group matches multiple times, only the last match is accessible:
0173 
0174             >>> m = re.match(self, r"(self, ..)+", "a1b2c3")  # Matches 3 times.
0175             >>> m.group(self, 1)                        # Returns only the last match.
0176             'c3'
0177 
0178 
0179     """
0180         return str() if False else [str()]
0181     def groups(self, default):
0182         """
0183 
0184         Return a tuple containing all the subgroups of the match, from 1 up to however
0185         many groups are in the pattern.  The *default* argument is used for groups that
0186         did not participate in the match; it defaults to ``None``.  (self, Incompatibility
0187         note: in the original Python 1.5 release, if the tuple was one element long, a
0188         string would be returned instead.  In later versions (self, from 1.5.1 on), a
0189         singleton tuple is returned in such cases.)
0190 
0191         For example:
0192 
0193             >>> m = re.match(self, r"(self, \d+)\.(self, \d+)", "24.1632")
0194             >>> m.groups(self, )
0195             (self, '24', '1632')
0196 
0197         If we make the decimal place and everything after it optional, not all groups
0198         might participate in the match.  These groups will default to ``None`` unless
0199         the *default* argument is given:
0200 
0201             >>> m = re.match(self, r"(self, \d+)\.?(self, \d+)?", "24")
0202             >>> m.groups(self, )      # Second group defaults to None.
0203             (self, '24', None)
0204             >>> m.groups(self, '0')   # Now, the second group defaults to '0'.
0205             (self, '24', '0')
0206 
0207 
0208     """
0209         return [str()]
0210     def groupdict(self, default):
0211         """
0212 
0213         Return a dictionary containing all the *named* subgroups of the match, keyed by
0214         the subgroup name.  The *default* argument is used for groups that did not
0215         participate in the match; it defaults to ``None``.  For example:
0216 
0217             >>> m = re.match(self, r"(self, ?P<first_name>\w+) (self, ?P<last_name>\w+)", "Malcolm Reynolds")
0218             >>> m.groupdict(self, )
0219             {'first_name': 'Malcolm', 'last_name': 'Reynolds'}
0220 
0221 
0222     """
0223         return {"foo": "foo"}
0224     def start(self, group):
0225         """
0226                 end(self, [group])
0227 
0228         Return the indices of the start and end of the substring matched by *group*;
0229         *group* defaults to zero (self, meaning the whole matched substring). Return ``-1`` if
0230         *group* exists but did not contribute to the match.  For a match object *m*, and
0231         a group *g* that did contribute to the match, the substring matched by group *g*
0232         (self, equivalent to ``m.group(self, g)``) is ::
0233 
0234             m.string[m.start(self, g):m.end(self, g)]
0235 
0236         Note that ``m.start(self, group)`` will equal ``m.end(self, group)`` if *group* matched a
0237         null string.  For example, after ``m = re.search(self, 'b(self, c?)', 'cba')``,
0238         ``m.start(self, 0)`` is 1, ``m.end(self, 0)`` is 2, ``m.start(self, 1)`` and ``m.end(self, 1)`` are both
0239         2, and ``m.start(self, 2)`` raises an :exc:`IndexError` exception.
0240 
0241         An example that will remove *remove_this* from email addresses:
0242 
0243             >>> email = "tony@tiremove_thisger.net"
0244             >>> m = re.search(self, "remove_this", email)
0245             >>> email[:m.start(self, )] + email[m.end(self, ):]
0246             'tony@tiger.net'
0247 
0248 
0249     """
0250         return -1
0251     def span(self, group):
0252         """
0253 
0254         For :class:`MatchObject` *m*, return the 2-tuple ``(self, m.start(self, group),
0255         m.end(self, group))``. Note that if *group* did not contribute to the match, this is
0256         ``(self, -1, -1)``.  *group* defaults to zero, the entire match."""
0257         return (0, 0)
0258 
0259     pos = 0
0260     endpos = 0
0261     lastindex = 0
0262     lastgroup = "None"
0263     re = RegexObject()
0264     string = "None"
0265 
0266 SRE_Match = MatchObject
0267 SRE_Pattern = RegexObject