本文整理匯總了Python中re.I屬性的典型用法代碼示例。如果您正苦於以下問題:Python re.I屬性的具體用法?Python re.I怎麽用?Python re.I使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類re
的用法示例。
在下文中一共展示了re.I屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: matchHeader
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def matchHeader(self, headermatch, attack=False):
if attack:
r = self.attackres
else: r = rq
if r is None:
return
header, match = headermatch
headerval = r.headers.get(header)
if headerval:
# set-cookie can have multiple headers, python gives it to us
# concatinated with a comma
if header == 'Set-Cookie':
headervals = headerval.split(', ')
else:
headervals = [headerval]
for headerval in headervals:
if re.search(match, headerval, re.I):
return True
return False
示例2: tweak
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def tweak(self, content):
tweaked = self.legacy_tweak(content)
if tweaked:
return tweaked
apply_persistence_to_all_lines = \
0 < self.setup_params.persistence_size and \
not self.config_is_persistence_aware(content)
matching_re = r'^(\s*(%s)\s*)(.*)$' % self.BOOT_PARAMS_STARTER
kernel_parameter_line_pattern = re.compile(
matching_re,
flags = re.I | re.MULTILINE)
out = self.tweak_first_match(
content,
kernel_parameter_line_pattern,
apply_persistence_to_all_lines,
self.param_operations(),
self.param_operations_for_persistence())
return self.post_process(out)
示例3: tweak_bootfile_path
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def tweak_bootfile_path(img_file_spec, isolinux_dir):
"""
Function to find image files to boot and return them concatinated
with a space. Return the spec untouched if no locations are found.
:param kernel_file_spec: Image path specification lead by kernel/linux keyword within isolinux supported .cfg files.
:param isolinux_dir: Path to isolinux directory of an ISO
:return: Converted file paths joined by a space. If no files can be located, img_file_spec is returned unmodified.
"""
kernel_line = ''
raw_paths = img_file_spec.split(',')
converted_paths = [locate_kernel_file(p, isolinux_dir) for p in raw_paths]
if raw_paths != converted_paths: # Tweaked the paths successfully?
return ' '.join(converted_paths)
if 'z,' in img_file_spec:
# Fallback to legacy code.
# "... I found this only in dban"
iso_dir = iso.isolinux_bin_dir(config.image_path)
replacement = ' /multibootusb/' + iso.iso_basename(config.image_path) \
+ '/' \
+ iso_dir.replace('\\', '/') + '/'
return img_file_spec.replace('z,', replacement)
# Give up and return the original with replaced delimeters.
return ' '.join(img_file_spec.split(','))
示例4: compact_names
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def compact_names(self):
global variables
# build regular expression that can later tell which names to preserve (these should not undergo compaction)
preserve_pattern = re.compile(r'[$%@!?~]?(' + '|'.join(self.variable_names_to_preserve) + ')$', re.I)
for v in variables:
if self.variable_names_to_preserve and preserve_pattern.match(v):
#self.original2short[v] = v
#self.short2original[v] = v
continue
elif v not in self.original2short and v not in ksp_builtins.variables:
self.original2short[v] = '%s%s' % (v[0], compress_variable_name(v))
if self.original2short[v] in ksp_builtins.variables:
raise Exception('This is your unlucky day. Even though the chance is only 3.2%%%% the variable %s was mapped to the same hash as that of a builtin KSP variable.' % (v))
if self.original2short[v] in self.short2original:
raise Exception('This is your unlucky day. Even though the chance is only 3.2%%%% two variable names were compacted to the same short name: %s and %s' % (v, self.short2original[self.original2short[v]]))
self.short2original[self.original2short[v]] = v
ASTModifierIDSubstituter(self.original2short, force_lower_case=True).modify(self.module)
示例5: remove_html_tags
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def remove_html_tags(htmlstr):
#先過濾CDATA
re_cdata = re.compile('//<!\[CDATA\[[^>]*//\]\]>',re.I) #匹配CDATA
re_script = re.compile('<\s*script[^>]*>[^<]*<\s*/\s*script\s*>',re.I)#Script
re_style = re.compile('<\s*style[^>]*>[^<]*<\s*/\s*style\s*>',re.I)#style
re_br = re.compile('<br\s*?/?>')#處理換行
re_h = re.compile('</?\w+[^>]*>')#HTML標簽
re_comment = re.compile('<!--[^>]*-->')#HTML注釋
s = re_cdata.sub('',htmlstr)#去掉CDATA
s = re_script.sub('',s) #去掉SCRIPT
s = re_style.sub('',s)#去掉style
s = re_br.sub('\n',s)#將br轉換為換行
s = re_h.sub('',s) #去掉HTML 標簽
s = re_comment.sub('',s)#去掉HTML注釋
#去掉多餘的空行
blank_line = re.compile('\n+')
s = blank_line.sub('\n',s)
#s = recover_html_char_entity(s)#替換實體
return s
## 替換常用HTML字符實體.
示例6: get_encodings_from_content
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def get_encodings_from_content(content):
"""Returns encodings from given content string.
:param content: bytestring to extract encodings from.
"""
warnings.warn((
'In requests 3.0, get_encodings_from_content will be removed. For '
'more information, please see the discussion on issue #2266. (This'
' warning should only appear once.)'),
DeprecationWarning)
charset_re = re.compile(r'<meta.*?charset=["\']*(.+?)["\'>]', flags=re.I)
pragma_re = re.compile(r'<meta.*?content=["\']*;?charset=(.+?)["\'>]', flags=re.I)
xml_re = re.compile(r'^<\?xml.*?encoding=["\']*(.+?)["\'>]')
return (charset_re.findall(content) +
pragma_re.findall(content) +
xml_re.findall(content))
示例7: ipinfo
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def ipinfo(host):
out = []
if not re.search(r'\d+\.\d+\.\d+\.\d+', host):
req = Requests()
# noinspection PyBroadException
try:
r = req.get('https://viewdns.info/iphistory/?domain={}'.format(host))
result = re.findall(r'(?<=<tr><td>)\d+\.\d+\.\d+\.\d+(?=</td><td>)', r.text, re.S | re.I)
if result:
for i in result:
if iscdn(i):
out.append(i)
except Exception:
pass
return out
示例8: getmatch
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def getmatch(self, haystack):
if not isinstance(haystack, basestring):
return None
flags = 0
if self.flags is not None:
if "i" in self.flags or "I" in self.flags:
flags |= re.I
if "l" in self.flags or "L" in self.flags:
flags |= re.L
if "m" in self.flags or "M" in self.flags:
flags |= re.M
if "s" in self.flags or "S" in self.flags:
flags |= re.S
if "u" in self.flags or "U" in self.flags:
flags |= re.U
if "x" in self.flags or "X" in self.flags:
flags |= re.X
if re.match(self.pattern, haystack, flags=flags) is None:
return None
elif self.to is None:
return Match(haystack, haystack)
else:
return Match(haystack, re.sub(self.pattern, self.to, haystack, flags=flags))
示例9: _select_options
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def _select_options(pat):
"""returns a list of keys matching `pat`
if pat=="all", returns all registered options
"""
# short-circuit for exact key
if pat in _registered_options:
return [pat]
# else look through all of them
keys = sorted(_registered_options.keys())
if pat == 'all': # reserved key
return keys
return [k for k in keys if re.search(pat, k, re.I)]
示例10: get_encoding
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def get_encoding(headers, content):
"""Get encoding from request headers or page head."""
encoding = None
content_type = headers.get('content-type')
if content_type:
_, params = cgi.parse_header(content_type)
if 'charset' in params:
encoding = params['charset'].strip("'\"")
if not encoding:
content = utils.pretty_unicode(content[:1000]) if six.PY3 else content
charset_re = re.compile(r'<meta.*?charset=["\']*(.+?)["\'>]',
flags=re.I)
pragma_re = re.compile(r'<meta.*?content=["\']*;?charset=(.+?)["\'>]',
flags=re.I)
xml_re = re.compile(r'^<\?xml.*?encoding=["\']*(.+?)["\'>]')
encoding = (charset_re.findall(content) +
pragma_re.findall(content) +
xml_re.findall(content))
encoding = encoding and encoding[0] or None
return encoding
示例11: __init__
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def __init__(self, proxies=None, **x509):
msg = "%(class)s style of invoking requests is deprecated. " \
"Use newer urlopen functions/methods" % {'class': self.__class__.__name__}
warnings.warn(msg, DeprecationWarning, stacklevel=3)
if proxies is None:
proxies = getproxies()
assert hasattr(proxies, 'keys'), "proxies must be a mapping"
self.proxies = proxies
self.key_file = x509.get('key_file')
self.cert_file = x509.get('cert_file')
self.addheaders = [('User-Agent', self.version)]
self.__tempfiles = []
self.__unlink = os.unlink # See cleanup()
self.tempcache = None
# Undocumented feature: if you assign {} to tempcache,
# it is used to cache files retrieved with
# self.retrieve(). This is not enabled by default
# since it does not work for changing documents (and I
# haven't got the logic to check expiration headers
# yet).
self.ftpcache = ftpcache
# Undocumented feature: you can use a different
# ftp cache by assigning to the .ftpcache member;
# in case you want logically independent URL openers
# XXX This is not threadsafe. Bah.
示例12: matchContent
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def matchContent(self, regex, attack=True):
if attack:
r = self.attackres
else: r = rq
if r is None:
return
# We may need to match multiline context in response body
if re.search(regex, r.text, re.I):
return True
return False
示例13: run_validation
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def run_validation(self, site_design, orchestrator=None):
# Check FQDN length is <= 255 characters per RFC 1035
node_list = site_design.baremetal_nodes or []
invalid_nodes = [
n for n in node_list if len(n.get_fqdn(site_design)) > 255
]
for n in invalid_nodes:
msg = "FQDN %s is invalid, greater than 255 characters." % n.get_fqdn(
site_design)
self.report_error(
msg, [n.doc_ref],
"RFC 1035 requires full DNS names to be < 256 characters.")
# Check each label in the domain name is <= 63 characters per RFC 1035
# and only contains A-Z,a-z,0-9,-
valid_label = re.compile('[a-z0-9-]{1,63}', flags=re.I)
for n in node_list:
domain_labels = n.get_fqdn(site_design).split('.')
for domain_label in domain_labels:
if not valid_label.fullmatch(domain_label):
msg = "FQDN %s is invalid - label '%s' is invalid." % (
n.get_fqdn(site_design), domain_label)
self.report_error(
msg, [n.doc_ref],
"RFC 1035 requires each label in a DNS name to be <= 63 characters and contain "
"only A-Z, a-z, 0-9, and hyphens.")
示例14: __init__
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def __init__(self):
# Setup validation pattern for external marker
UUIDv4_pattern = '^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$'
self.marker_re = re.compile(UUIDv4_pattern, re.I)
示例15: commentout_gfxboot
# 需要導入模塊: import re [as 別名]
# 或者: from re import I [as 別名]
def commentout_gfxboot(input_text):
return re.sub(r'(ui\s+.*?gfxboot\.c32.*)$', r'# \1', input_text,
flags=re.I | re.MULTILINE)