Python re.Match() Examples

The following are code examples for showing how to use re.Match(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: zenchmarks   Author: squeaky-pl   File: basic.py    (license) View Source Project 6 votes vote down vote up
def _processLength(self, lengthMatch):
        """
        Processes the length definition of a netstring.

        Extracts and stores in C{self._expectedPayloadSize} the number
        representing the netstring size.  Removes the prefix
        representing the length specification from
        C{self._remainingData}.

        @raise NetstringParseError: if the received netstring does not
            start with a number or the number is bigger than
            C{self.MAX_LENGTH}.
        @param lengthMatch: A regular expression match object matching
            a netstring length specification
        @type lengthMatch: C{re.Match}
        """
        endOfNumber = lengthMatch.end(1)
        startOfData = lengthMatch.end(2)
        lengthString = self._remainingData[:endOfNumber]
        # Expect payload plus trailing comma:
        self._expectedPayloadSize = self._extractLength(lengthString) + 1
        self._remainingData = self._remainingData[startOfData:] 
Example 2
Project: xphyle   Author: jdidion   File: paths.py    (license) View Source Project 6 votes vote down vote up
def _match_to_dict(
            self, match: Match, errors: bool = True) -> Dict[str, Any]:
        """Convert a regular expression Match to a dict of (name, value) for
        all PathVars.
        
        Args:
            match: A :class:`re.Match`.
            errors: If True, raise an exception for validation failure,
                otherwise return None.
        
        Returns:
            A (name, value) dict.
        
        Raises:
            ValueError if any values fail validation.
        """
        return match_to_dict(match, self.path_vars, errors) 
Example 3
Project: xphyle   Author: jdidion   File: paths.py    (license) View Source Project 6 votes vote down vote up
def find(
            self, root: PathLike = None,
            recursive: bool = False) -> Sequence[PathInst]:
        """Find all paths in `root` matching this spec.
        
        Args:
            root: Directory in which to begin the search.
            recursive: Whether to search recursively.
        
        Returns:
            A sequence of PathInst.
        """
        if root is None:
            root = self.default_search_root()
        find_results = find(
            root, self.pattern, path_types=[self.path_type],
            recursive=recursive, return_matches=True)
        matches = dict(
            (path, self._match_to_dict(match, errors=False))
            for path, match in cast(
                Sequence[Tuple[str, Match[str]]], find_results))
        return [
            path_inst(path, match)
            for path, match in matches.items()
            if match is not None] 
Example 4
Project: kinect-2-libras   Author: inessadl   File: cookielib.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 5
Project: hostapd-mana   Author: adde88   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 6
Project: Intranet-Penetration   Author: yuxiaokui   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 7
Project: MKFQ   Author: maojingios   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 8
Project: hakkuframework   Author: 4shadoww   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 9
Project: zippy   Author: securesystemslab   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 10
Project: qiskit-sdk-py   Author: QISKit   File: visualization.py    (license) View Source Project 5 votes vote down vote up
def _truncate_float(matchobj, format_str='0.2g'):
    """Truncate long floats

    Args:
        matchobj (re.Match object): contains original float
        format_str (str): format specifier
    Returns:
        returns truncated float
    """
    if matchobj.group(0):
        return format(float(matchobj.group(0)), format_str) 
Example 11
Project: oil   Author: oilshell   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 12
Project: python2-tracer   Author: extremecoders-re   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 13
Project: packaging   Author: blockstack   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 14
Project: sslstrip-hsts-openwrt   Author: adde88   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 15
Project: islam-buddy   Author: hamir   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 16
Project: pelisalacarta-ce   Author: pelisalacarta-ce   File: _headersutil.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 17
Project: FightstickDisplay   Author: calexil   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 18
Project: plugin.video.streamondemand-pureita   Author: orione7   File: _headersutil.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 19
Project: xxNet   Author: drzorm   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 20
Project: cryptogram   Author: xinmingzhang   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 21
Project: Repobot   Author: Desgard   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 22
Project: pefile.pypy   Author: cloudtracer   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 23
Project: ouroboros   Author: pybee   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 24
Project: ndk-python   Author: gittor   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 25
Project: empyrion-python-api   Author: huhlig   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 26
Project: kodi-tk_del   Author: hubsif   File: _headersutil.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 27
Project: UMOG   Author: hsab   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 28
Project: mechanize   Author: python-mechanize   File: _headersutil.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start] + match.string[end:] 
Example 29
Project: pmatic   Author: LarsMichelsen   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 30
Project: blackmamba   Author: zrzka   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 31
Project: kbe_server   Author: xiaohaoppy   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 32
Project: beepboop   Author: nicolehe   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 33
Project: deb-python-eventlet   Author: openstack   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 34
Project: Docker-XX-Net   Author: kuanghy   File: cookielib.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 35
Project: addon   Author: alfa-addon   File: _headersutil.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 36
Project: xphyle   Author: jdidion   File: paths.py    (license) View Source Project 5 votes vote down vote up
def match_to_dict(
        match: Match, path_vars: Dict[str, PathVar],
        errors: bool = True) -> Dict[str, Any]:
    """Convert a regular expression Match to a dict of (name, value) for
    all PathVars.
    
    Args:
        match: A re.Match.
        path_vars: A dict of PathVars.
        errors: If True, raise an exception on validation error, otherwise
            return None.
    
    Returns:
        A (name, value) dict.
    
    Raises:
        ValueError if any values fail validation.
    """
    match_groups = match.groupdict()
    try:
        return dict(
            (name, var(match_groups.get(name, None)))
            for name, var in path_vars.items())
    except ValueError:
        if errors:
            raise
        else:
            return None

# pylint: disable=no-member 
Example 37
Project: xphyle   Author: jdidion   File: paths.py    (license) View Source Project 5 votes vote down vote up
def find(
            self, root: PathLike = None, 
            path_types: Sequence[PathTypeArg] = 'f',
            recursive: bool = False) -> Sequence[PathInst]:
        """Find all paths matching this PathSpec. The search starts in 'root'
        if it is not None, otherwise it starts in the deepest fixed directory
        of this PathSpec's DirSpec.
        
        Args:
            root: Directory in which to begin the search.
            path_types: Types to return -- files ('f'), directories ('d') or
                both ('fd').
            recursive: Whether to search recursively.
        
        Returns:
            A sequence of PathInst.
        """
        if root is None:
            if self.fixed_dir:
                root = str(self.dir_spec)
            else:
                root = self.dir_spec.default_search_root()
        
        files = find(
            root, self.pattern, path_types=path_types, recursive=recursive,
            return_matches=True)
        
        return [
            path_inst(path, match_to_dict(match, self.path_vars))
            for path, match in cast(Sequence[Tuple[str, Match[str]]], files)] 
Example 38
Project: BruteXSS   Author: rajeshmajumdar   File: _headersutil.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 39
Project: hackathon   Author: vertica   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:] 
Example 40
Project: yatta_reader   Author: sound88   File: cookiejar.py    (license) View Source Project 5 votes vote down vote up
def unmatched(match):
    """Return unmatched part of re.Match object."""
    start, end = match.span(0)
    return match.string[:start]+match.string[end:]