Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
D = regex.D
DEBUG = regex.DEBUG
A = regex.A
ASCII = regex.ASCII
B = regex.B
BESTMATCH = regex.BESTMATCH
E = regex.E
ENHANCEMATCH = regex.ENHANCEMATCH
F = regex.F
FULLCASE = regex.FULLCASE
I = regex.I
IGNORECASE = regex.IGNORECASE
L = regex.L
LOCALE = regex.LOCALE
M = regex.M
MULTILINE = regex.MULTILINE
R = regex.R
REVERSE = regex.REVERSE
S = regex.S
DOTALL = regex.DOTALL
U = regex.U
UNICODE = regex.UNICODE
X = regex.X
VERBOSE = regex.VERBOSE
V0 = regex.V0
VERSION0 = regex.VERSION0
V1 = regex.V1
VERSION1 = regex.VERSION1
W = regex.W
WORD = regex.WORD
DEFAULT_VERSION = regex.DEFAULT_VERSION
REGEX_TYPE = type(regex.compile('', 0))
__all__ = [ 'Source', 'SourceLocation' ]
from typing import *
import regex as re #type: ignore
import sys
re.DEFAULT_VERSION = re.VERSION1
_syntax_skip_space = re.compile( r'\s+' )
_syntax_skip_nonline_space = re.compile( r'[\s--[\r\n]]+' )
_syntax_peek_line = re.compile( r'(.*)$', re.MULTILINE )
_syntax_lead_space = re.compile( r'([\p{Space_Separator}\t]*)' )
_syntax_empty_line = re.compile( r'[\p{Space_Separator}\t]*$', re.MULTILINE )
_syntax_line_ends = re.compile( r'[\n\r]' )
class SourceLocation(NamedTuple):
source: 'Source'
offset: int
def translate(self, tab_size = 4) -> Tuple[Optional[str],int,int]:
return (
self.source._path,
self.line_at(),
self.col_at(tab_size)
)
D = _regex.D
DEBUG = _regex.DEBUG
A = _regex.A
ASCII = _regex.ASCII
B = _regex.B
BESTMATCH = _regex.BESTMATCH
E = _regex.E
ENHANCEMATCH = _regex.ENHANCEMATCH
F = _regex.F
FULLCASE = _regex.FULLCASE
I = _regex.I
IGNORECASE = _regex.IGNORECASE
L = _regex.L
LOCALE = _regex.LOCALE
M = _regex.M
MULTILINE = _regex.MULTILINE
R = _regex.R
REVERSE = _regex.REVERSE
S = _regex.S
DOTALL = _regex.DOTALL
U = _regex.U
UNICODE = _regex.UNICODE
X = _regex.X
VERBOSE = _regex.VERBOSE
V0 = _regex.V0
VERSION0 = _regex.VERSION0
V1 = _regex.V1
VERSION1 = _regex.VERSION1
W = _regex.W
WORD = _regex.WORD
P = _regex.P
POSIX = _regex.POSIX
# For later comparison with cover
matches = regex.findall(r"<title>(.*?)</title>", file_contents)
for match in matches:
titlepage_svg_title = match.replace("The titlepage for ", "")
if filename.endswith(".css"):
# Check CSS style
# First remove @supports selectors and normalize indentation within them
matches = regex.findall(r"^@supports\(.+?\){.+?}\s*}", file_contents, flags=regex.MULTILINE | regex.DOTALL)
for match in matches:
processed_match = regex.sub(r"^@supports\(.+?\){\s*(.+?)\s*}\s*}", "\\1", match.replace("\n\t", "\n") + "\n}", flags=regex.MULTILINE | regex.DOTALL)
file_contents = file_contents.replace(match, processed_match)
# Remove comments that are on their own line
file_contents = regex.sub(r"^/\*.+?\*/\n", "", file_contents, flags=regex.MULTILINE | regex.DOTALL)
# Check for unneeded white-space nowrap in abbr selectors
matches = regex.findall(r"abbr.+?{[^}]*?white-space:\s*nowrap;[^}]*?}", css)
if matches:
messages.append(LintMessage("abbr selector does not need white-space: nowrap; as it inherits it from core.css.", se.MESSAGE_TYPE_ERROR, filename))
for match in matches:
messages.append(LintMessage(match, se.MESSAGE_TYPE_ERROR, filename, True))
# Don't specify border color
matches = regex.findall(r"(?:border|color).+?(?:#[a-f0-9]{0,6}|black|white|red)", file_contents, flags=regex.IGNORECASE)
if matches:
messages.append(LintMessage("Don't specify border colors, so that reading systems can adjust for night mode.", se.MESSAGE_TYPE_WARNING, filename))
for match in matches:
messages.append(LintMessage(match, se.MESSAGE_TYPE_WARNING, filename, True))
# If we select on the xml namespace, make sure we define the namespace in the CSS, otherwise the selector won't work
def extract_ipv4(data):
#regexp = re.compile(r'\s?((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\s?', flags=re.MULTILINE)
regexp = re.compile(r'[\s():{}\[\]]{1}((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)[\s():{}\[\]]{1}', flags=re.MULTILINE)
regexp = re.compile(r'[^0-9]?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[^0-9]?', flags=re.MULTILINE)
match = regexp.finditer(data)
result = []
for m in match:
try:
ipaddress.ip_address(m.group(1))
result.append(m.group(1))
except ValueError:
continue
#ip = m.group(0).strip(' ():{}[]')
#ip = ip.strip()
#if ip:
# result.append(ip)
import regex
# noinspection PyProtectedMember
from regex import _regex_core
# =============================================================================
# Core regex functions
# =============================================================================
# - All will use VERBOSE mode for legibility. (No impact on speed: compiled.)
# - Don't forget to use raw strings for all regex definitions!
# - Beware comments inside regexes. The comment parser isn't quite as benign
# as you might think. Use very plain text only.
# - (?: XXX ) makes XXX into an unnamed group.
REGEX_COMPILE_FLAGS = (regex.IGNORECASE | regex.MULTILINE | regex.VERBOSE |
regex.UNICODE)
def at_wb_start_end(regex_str: str) -> str:
"""
Returns a version of the regex starting and ending with a word boundary.
Caution using this. Digits do not end a word, so "mm3" will not match if
your "mm" group ends in a word boundary.
"""
return f"\b(?: {regex_str} )\b"
def at_start_wb(regex_str: str) -> str:
"""
Returns a version of the regex starting with a word boundary.
# Tree parsing
from __future__ import annotations # type: ignore
import regex as re # type: ignore
from typing import *
from abc import abstractmethod
from enum import Enum, auto
from .source import Source, SourceLocation
from .parse_tree import *
_syntax_empty_line = re.compile( r'[\p{Space_Separator}\t]*$', re.MULTILINE )
_syntax_inline_header = re.compile( r'::' )
_syntax_inline_note = re.compile( r'\^([\p{L}\p{N}]*)' )
class BlockLevelBuilder:
def __init__(self, source : Source, parser : TreeParser, indent : str):
self._annotations : List[Annotation] = []
self._blocks : List[Node] = []
self.source = source
self._parser = parser
self._indent = indent
def append_annotation( self, anno : Annotation ) -> None:
self._annotations.append( anno )
def append_block( self, block ) -> None:
def regex_match_score(prediction, pattern):
"""Check if the prediction matches the given regular expression."""
try:
compiled = re.compile(
pattern,
flags=re.IGNORECASE + re.UNICODE + re.MULTILINE
)
except BaseException:
logger.warn('Regular expression failed to compile: %s' % pattern)
return False
return compiled.match(prediction) is not None
def regex_match(text, pattern):
"""Test if a regex pattern is contained within a text."""
try:
pattern = re.compile(
pattern,
flags=re.IGNORECASE + re.UNICODE + re.MULTILINE,
)
except BaseException:
return False
return pattern.search(text) is not None
def regex_match(text, pattern):
"""Test if a regex pattern is contained within a text."""
try:
pattern = re.compile(
pattern,
flags=re.IGNORECASE + re.UNICODE + re.MULTILINE,
)
except BaseException:
return False
return pattern.search(text) is not None