本文整理汇总了Python中re.IGNORECASE属性的典型用法代码示例。如果您正苦于以下问题:Python re.IGNORECASE属性的具体用法?Python re.IGNORECASE怎么用?Python re.IGNORECASE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类re
的用法示例。
在下文中一共展示了re.IGNORECASE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_process
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def read_process(cmd, args=''):
fullcmd = '%s %s' % (cmd, args)
pipeout = popen(fullcmd)
try:
firstline = pipeout.readline()
cmd_not_found = re.search(
b'(not recognized|No such file|not found)',
firstline,
re.IGNORECASE
)
if cmd_not_found:
raise IOError('%s must be on your system path.' % cmd)
output = firstline + pipeout.read()
finally:
pipeout.close()
return output
示例2: check_paste
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def check_paste ( self, paste_id ):
paste_url = self.PASTEBIN_URL + paste_id
try:
paste_txt = PyQuery ( url = paste_url )('#paste_code').text()
for regex,file,directory in self.regexes:
if re.match ( regex, paste_txt, re.IGNORECASE ):
Logger ().log ( 'Found a matching paste: ' + paste_url + ' (' + file + ')', True, 'CYAN' )
self.save_result ( paste_url,paste_id,file,directory )
return True
Logger ().log ( 'Not matching paste: ' + paste_url )
except KeyboardInterrupt:
raise
except:
Logger ().log ( 'Error reading paste (probably a 404 or encoding issue).', True, 'YELLOW')
return False
示例3: ReqBuilder
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def ReqBuilder(self, target_BoxObject):
filename, extension = os.path.splitext(target_BoxObject.path)
extension = extension[1:] # removing the dot character before the extension
result = self.templateRequest.safe_substitute(ip=target_BoxObject.ip,
port=target_BoxObject.port,
path=target_BoxObject.path,
filename=filename,
extension=extension,
hostname=target_BoxObject.hostname,
description=target_BoxObject.description)
if self.autoContentLength:
bodylength = len(result) - re.search("(\r\n\r\n)|(\n\n)", result).end()
if re.search("content\\-length", result, re.IGNORECASE):
result = re.sub(r"(?i)content\-length:\s*\d+", "Content-Length: " + str(bodylength),
result, 1)
else:
result = re.sub(r"(\r\n\r\n)|(\n\n)", "\r\nContent-Length: " + str(bodylength) + "\r\n\r\n",
result, 1)
return result
示例4: test
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def test(self,user,password,token):
for line in self.regexs:
(ignore,regex) = line
regex = regex.replace('<user>',user)
results = None
if ignore == True:
results = re.search(regex,password,re.IGNORECASE)
else:
results = re.search(regex,password)
if results != None:
if self.debug:
print(" \- - A blacklisted term was found")
return (20,None)
if self.debug:
print(" \- * No blacklisted terms were found")
return (0,None)
示例5: set_memlimit
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def set_memlimit(limit):
global max_memuse
global real_max_memuse
sizes = {
'k': 1024,
'm': _1M,
'g': _1G,
't': 1024*_1G,
}
m = re.match(r'(\d+(\.\d+)?) (K|M|G|T)b?$', limit,
re.IGNORECASE | re.VERBOSE)
if m is None:
raise ValueError('Invalid memory limit %r' % (limit,))
memlimit = int(float(m.group(1)) * sizes[m.group(3).lower()])
real_max_memuse = memlimit
if memlimit > MAX_Py_ssize_t:
memlimit = MAX_Py_ssize_t
if memlimit < _2G - 1:
raise ValueError('Memory limit %r too low to be useful' % (limit,))
max_memuse = memlimit
示例6: regex
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def regex(self, response, port):
match = False
if re.search(b'<title>502 Bad Gateway', response):
return match
for pattern in SIGNS:
pattern = pattern.split(b'|')
if re.search(pattern[-1], response, re.IGNORECASE):
text = response.decode('utf-8', 'ignore')
match = True
proto = {"server": pattern[1].decode(), "port": port, "banner": text}
self.out.append(proto)
break
if not match:
proto = {"server": get_server(port), "port": port, "banner": response.decode('utf-8', 'ignore')}
self.out.append(proto)
示例7: __init__
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def __init__(self, pairs, reflections={}):
"""
Initialize the chatbot. Pairs is a list of patterns and responses. Each
pattern is a regular expression matching the user's statement or question,
e.g. r'I like (.*)'. For each such pattern a list of possible responses
is given, e.g. ['Why do you like %1', 'Did you ever dislike %1']. Material
which is matched by parenthesized sections of the patterns (e.g. .*) is mapped to
the numbered positions in the responses, e.g. %1.
@type pairs: C{list} of C{tuple}
@param pairs: The patterns and responses
@type reflections: C{dict}
@param reflections: A mapping between first and second person expressions
@rtype: C{None}
"""
self._pairs = [(re.compile(x, re.IGNORECASE),y) for (x,y) in pairs]
self._reflections = reflections
# bug: only permits single word expressions to be mapped
示例8: __init__
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def __init__(self, pairs, reflections={}):
"""
Initialize the chatbot. Pairs is a list of patterns and responses. Each
pattern is a regular expression matching the user's statement or question,
e.g. r'I like (.*)'. For each such pattern a list of possible responses
is given, e.g. ['Why do you like %1', 'Did you ever dislike %1']. Material
which is matched by parenthesized sections of the patterns (e.g. .*) is mapped to
the numbered positions in the responses, e.g. %1.
:type pairs: list of tuple
:param pairs: The patterns and responses
:type reflections: dict
:param reflections: A mapping between first and second person expressions
:rtype: None
"""
self._pairs = [(re.compile(x, re.IGNORECASE),y) for (x,y) in pairs]
self._reflections = reflections
self._regex = self._compile_reflections()
示例9: check_juniper_rift_in_path
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def check_juniper_rift_in_path():
if shutil.which("rift-environ") is None:
fatal_error("Cannot find Juniper RIFT (rift-environ) in PATH")
# run it and check version
output = subprocess.check_output(["rift-environ",
"--version"], universal_newlines=True)
# print (output)
regex = re.compile(r"^.hrift encoding schema: *(\d+)\.(\d+).*",
re.IGNORECASE | re.MULTILINE)
major = re.search(regex, output)
if not major or not major.group(1):
fatal_error("Cannot detect major version of Juniper RIFT")
minor = major.group(2)
major = major.group(1)
expected_minor = protocol_minor_version
expected_major = protocol_major_version
if int(major) != expected_major or int(minor) != expected_minor:
fatal_error("Wrong Major/Minor version of Juniper RIFT: (expected {}.{}, got {}.{})"
.format(expected_major, expected_minor, major, minor))
示例10: render_re
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def render_re(regex):
"""Renders a repr()-style value for a compiled regular expression."""
actual_flags = []
if regex.flags:
flags = [
(re.IGNORECASE, 'IGNORECASE'),
(re.LOCALE, 'LOCALE'),
(re.UNICODE, 'UNICODE'),
(re.MULTILINE, 'MULTILINE'),
(re.DOTALL, 'DOTALL'),
(re.VERBOSE, 'VERBOSE'),
]
for val, name in flags:
if regex.flags & val:
actual_flags.append(name)
if actual_flags:
return 're.compile(%r, %s)' % (regex.pattern, '|'.join(actual_flags))
else:
return 're.compile(%r)' % regex.pattern
示例11: normalize_release_tags
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def normalize_release_tags(name, real_title):
import re
import xbmc
def _normalize_name(val):
proper = re.sub(r"[\[\(\]\)]", "", val)
proper = re.sub(r"'", "", proper)
proper = re.sub(r"\W", " ", proper)
proper = re.sub(r"\s+", " ", proper)
return proper
name = _normalize_name(name)
real_title = _normalize_name(real_title)
release_tags = re.compile(real_title, re.IGNORECASE).sub("", name)
tags = map(re.escape, VIDEO_CODECS.keys() + AUDIO_CODECS.keys() + RESOLUTIONS.keys())
release_tags = re.compile("(%s)" % "|".join(tags), re.IGNORECASE).sub("", release_tags)
release_tags = re.sub(r"\s+", " ", release_tags)
return release_tags.strip()
示例12: expand_windows_drive
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def expand_windows_drive(path: str) -> str:
r"""Expand a drive-path like E: into E:\.
Does nothing for other paths.
Args:
path: The path to expand.
"""
# Usually, "E:" on Windows refers to the current working directory on drive
# E:\. The correct way to specifify drive E: is "E:\", but most users
# probably don't use the "multiple working directories" feature and expect
# "E:" and "E:\" to be equal.
if re.fullmatch(r'[A-Z]:', path, re.IGNORECASE):
return path + "\\"
else:
return path
示例13: transform_path
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def transform_path(path):
r"""Do platform-specific transformations, like changing E: to E:\.
Returns None if the path is invalid on the current platform.
"""
if not utils.is_windows:
return path
path = utils.expand_windows_drive(path)
# Drive dependent working directories are not supported, e.g.
# E:filename is invalid
if re.search(r'^[A-Z]:[^\\]', path, re.IGNORECASE):
return None
# Paths like COM1, ...
# See https://github.com/qutebrowser/qutebrowser/issues/82
if pathlib.Path(path).is_reserved():
return None
return path
示例14: query_state
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def query_state(self, query):
"""
Query the drone current state return a dictionary of every drone state
whose message name contains the query string
:return: dictionary of drone state
:param: query, the string to search for in the message received from the drone.
"""
result = OrderedDict()
for message in self.messages.values():
if re.search(query, message.fullName, re.IGNORECASE):
try:
result[message.fullName] = message.state()
except RuntimeError:
continue
for arg_name in message.args_name:
name = message.fullName + "." + arg_name
if re.search(query, name, re.IGNORECASE):
try:
result[message.fullName] = message.state()
except RuntimeError:
break
return result
示例15: __init__
# 需要导入模块: import re [as 别名]
# 或者: from re import IGNORECASE [as 别名]
def __init__(self, bot: Bot):
self.bot = bot
self.matches = [
(re.compile(i[0], re.IGNORECASE), i[1]) for i in self.match_strings
]