本文整理汇总了Python中re.recompile函数的典型用法代码示例。如果您正苦于以下问题:Python recompile函数的具体用法?Python recompile怎么用?Python recompile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了recompile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __parse_output
def __parse_output(self):
rr_regex = recompile(self.avg_read_rate_key)
wr_regex = recompile(self.avg_write_rate_key)
lines = self._output.split("\n")
for line in lines:
if rr_regex.match(line):
self._result_map[self.avg_read_map_key] = self.__extract_rate(line)
if wr_regex.match(line):
self._result_map[self.avg_write_map_key] = self.__extract_rate(line)
示例2: changeNameRegex
def changeNameRegex(flag, regex):
"""Set regular expression used for flagging elements based on atom names.
See :ref:`element-flags` for the default list of flags."""
if flag not in EDITORS:
raise ValueError('{0:s} is not an editable flag'.format(repr(flag)))
try:
recompile(regex)
except Exception as err:
raise ValueError('{0:s} is not a valid regular expression, {1:s}'
.format(repr(regex), str(err)))
else:
changeDefinitions(**{flag: regex})
示例3: purge_faulty_drives
def purge_faulty_drives(self):
dev_entry_re = recompile ("^dev")
# walk the dev-sdX entries in the sysfs for a raid device and remove any
# that are faulty.
md_rootdir = '/sys/block/%s/md/' % self.get_devname()
try:
dir = listdir(md_rootdir)
for d in dir:
if dev_entry_re.match (d):
state_entry = '%s%s/state' % (md_rootdir, d)
try:
state = '%s' % get_sysfs_param(state_entry)
except (IOError, OSError):
# ignore and continue
continue
if state == "faulty":
rlog_debug ('Cleaning up stale device [%s] reference in array [%s]' % (
d, self.get_devname()))
# we found a disk that should have been removed but wasnt
if not set_sysfs_param (state_entry, 'remove'):
rlog_notice ('Unable to remove faulty device [%s] from array [%s]' % (
self.get_devname(),
d))
except (IOError, OSError):
# make sure we keep on going if we have a problem, we want to try to
# fix any inconsistancies found
pass
示例4: get_files_from_image
def get_files_from_image(motherboard):
base_ipmi_file_loc = '/opt/hal/lib/ipmi'
ipmi_config_path = '%s/ipmi.xml' % base_ipmi_file_loc
if not exists (ipmi_config_path):
raise GeneralError('IPMI configuration file %s does not exist' % ipmi_config_path)
dom = parse (ipmi_config_path)
entries = dom.getElementsByTagName('mobo')
if not entries:
raise GeneralError ('Invalid IPMI configuration file %s' % ipmi_config_path)
for entry in entries:
# look for the mobo tag and find the
# entry that matches our motherboard via the regex in the xml
# node
entry_name_pattern = entry.getAttribute('name')
if entry_name_pattern != '':
re = recompile(entry_name_pattern)
if re.match(motherboard):
try:
sdr = entry.getElementsByTagName('sdr')[0].getAttribute('fname')
fw = entry.getElementsByTagName('fw')[0].getAttribute('fname')
except IndexError:
raise GeneralError ('Invalid ipmi xml file for motherboard: %s' %
motherboard)
return ('%s/%s' % (base_ipmi_file_loc, fw),
'%s/%s' % (base_ipmi_file_loc, sdr))
return (None, None)
示例5: get_bot_information
def get_bot_information(self, file_data):
ret = {}
try:
p = recompile(r'var[\s]+\$config[\s]*=[\s]*array[\s]*\([\s]*(\"[^\"]*\"[\s]*=>.*,?[\s]*)*(//)?\);', MULTILINE)
result = p.search(file_data)
if result is None:
return {}
ret = self.get_config_values(result.group(0))
uris = []
server = ret['server'] if 'server' in ret else None
server_pass = ret['pass'] if "pass" in ret else None
port = int(ret['port']) if 'port' in ret else 6667
chan = ret['chan'] if 'chan' in ret else None
chan2 = ret['chan2'] if 'chan2' in ret else None
key = ret['key'] if 'key' in ret else server_pass
uris.append("pbot://{0}:{1}/?{2}".format(server, port, urlencode({"server_pass": server_pass,
"chan": chan, "channel_pass": key})))
if chan2 is not None:
uris.append("pbot://{0}:{1}/?{2}".format(server, port, urlencode({"server_pass": server_pass,
"chan": chan2, "channel_pass": key})))
ret['c2s'] = []
for uri in uris:
ret['c2s'].append({"c2_uri": uri})
except KeyboardInterrupt:
raise
except:
pass
return ret
示例6: updateDefinitions
def updateDefinitions():
"""Update definitions and set some global variables. This function must be
called at the end of the module."""
global DEFINITIONS, AMINOACIDS, BACKBONE, TIMESTAMP
DEFINITIONS = {}
user = SETTINGS.get('flag_definitions', {})
# nucleics
nucleic = set()
for key in ['nucleobase', 'nucleoside', 'nucleotide']:
aset = set(user.get(key, DEFAULTS[key]))
nucleic.update(aset)
DEFINITIONS[key] = aset
DEFINITIONS['nucleic'] = nucleic
# heteros
for key in ['water', 'lipid', 'ion', 'sugar', 'heme',
'at', 'cg', 'purine', 'pyrimidine',]:
DEFINITIONS[key] = set(user.get(key, DEFAULTS[key]))
DEFINITIONS['backbone'] = DEFINITIONS['bb'] = set(user.get(key,
DEFAULTS['bb']))
DEFINITIONS['backbonefull'] = DEFINITIONS['bbfull'] = set(user.get(key,
DEFAULTS['bbfull']))
# element regex
for key in ['hydrogen', 'carbon', 'nitrogen', 'oxygen', 'sulfur']:
DEFINITIONS[key] = recompile(user.get(key, DEFAULTS[key]))
try:
nonstd = SETTINGS[NONSTANDARD_KEY]
except KeyError:
nonstd = NONSTANDARD
DEFINITIONS.update(CATEGORIZED)
else:
for cat in CATEGORIES:
for key in CATEGORIES[cat]:
DEFINITIONS[key] = set(DEFAULTS[key])
DEFINITIONS['charged'] = set(DEFINITIONS['acidic'])
DEFINITIONS['charged'].update(DEFINITIONS['basic'])
for resi, props in nonstd.iteritems():
for prop in props:
DEFINITIONS[prop].add(resi)
DEFINITIONS['stdaa'] = DEFAULTS['stdaa']
DEFINITIONS['nonstdaa'] = set(nonstd)
AMINOACIDS = set(DEFINITIONS['stdaa'])
AMINOACIDS.update(DEFINITIONS['nonstdaa'])
DEFINITIONS['protein'] = DEFINITIONS['aminoacid'] = AMINOACIDS
BACKBONE = DEFINITIONS['bb']
global TIMESTAMP
TIMESTAMP = SETTINGS.get('flag_timestamp', 0)
示例7: get_links_from_pattern
def get_links_from_pattern(self, pat, links):
pattern = recompile('^'+pat.upper())
ret = []
for l in links:
if pattern.search(l.tnv_string.upper()):
ret.append(l)
return ret
示例8: get_config_values
def get_config_values(self, config):
try:
p = recompile(r'[\'"](?P<key>[^\'"]+)[\'"][\s]*=>[\s]*[\'"](?P<value>[^\'"]+)[\'"]', MULTILINE)
results = p.findall(config)
ret = {}
for pair in results:
ret[pair[0]] = pair[1]
return ret
except:
return {}
示例9: get_config_values
def get_config_values(self, config):
try:
p = recompile(r'[\'"](?P<key>[^\'"]+)[\'"][\s]*=>[\s]*[\'"](?P<value>[^\'"]+)[\'"]', MULTILINE)
results = p.findall(config)
ret = {}
for pair in results:
ret[unicode(pair[0], errors='ignore')] = unicode(pair[1], errors='ignore')
return ret
except:
return {}
示例10: get_mactab
def get_mactab(self, nics, cards, out_path, gateway_naming):
out_file = None
if out_path != "":
out_file = open(out_path, "w")
pci_links = self.make_pci_links()
# XXX:munir: Dump this to debug the PCI bus patterns. Easiest way
# I found to figure interface patterns
# for p in pci_links:
# p.printo()
ob_links = self.get_links_from_pattern(self.mobo.onboard_pattern, pci_links)
if len(ob_links) == 0:
ifc = ifconfig(arg="-a")
link = recompile("Link")
for l in ifc:
lk = link.search(l, 1)
if lk:
parts = l.split()
if len(parts) > 4:
print >> out_file, "primary", parts[4]
return
if self.mobo.num_ifs == 2:
if self.mobo.primary_first:
primary = ob_links[0]
aux = ob_links[1]
else:
primary = ob_links[1]
aux = ob_links[0]
dev_map_list = [{"device": primary, "name": "primary"}, {"device": aux, "name": "aux"}]
else:
# we only have primary no aux
primary = ob_links[0]
dev_map_list = [{"device": primary, "name": "primary"}]
(map, nic_brand_state) = self.get_address_map(nics, cards, gateway_naming, return_map=True, get_branding=False)
for a in map:
for nic in dev_map_list:
if nic["device"].memory_base == a[2]:
print >> out_file, nic["name"], a[1]
if self.mobo.part_num == "VM":
self.get_mactab_vm_slots(nics, cards, pci_links, map, out_file, gateway_naming)
return
for (n, s) in self.mobo.slot_patterns:
l = self.get_links_from_pattern(s, pci_links)
if l != []:
card = self.get_card_from_link(nics, cards, l[0])
self._print_rename_pairs(card, l, map, int(n), out_file, gateway_naming, False)
示例11: get_bot_information
def get_bot_information(self, file_data):
ret = {}
try:
p = recompile(r'var[\s]+\$config[\s]*=[\s]*array[\s]*\([\s]*(\"[^\"]*\"[\s]*=>.*,?[\s]*)*(//)?\);', MULTILINE)
result = p.search(file_data)
if result is None:
return {}
ret = self.get_config_values(result.group(0))
except:
pass
return ret
示例12: get_mobo_hint
def get_mobo_hint():
base_info = dmidecode(' | grep -A 6 \"Base Board\"')
mobo_family = {}
mkey = ''
pkey = ''
mb = recompile("^\s+Manufacturer:\s+([\w\-]+).*$")
pr = recompile("^\s+Product\sName:\s+([\w\-]+).*$")
for b in base_info:
mmb = mb.match(b)
mpr = pr.match(b)
if mmb:
mkey = mmb.group(1)
if mpr:
pkey = mpr.group(1)
for m in mobos:
for k in m.name_keys:
man = "sent"
ks = k.split()
if len(ks) >= 2:
man = ks[0]
prod = ks[1]
else:
prod = ks[0]
# Virtual model motherboard config entry, skip it
if m.virtual == "true" or m.isbob == "true":
continue
if man == "sent":
if prod.upper() == pkey.upper():
mobo_family[m.part_num] = 1
else:
if man.upper() == mkey.upper() and \
prod.upper() == pkey.upper():
mobo_family[m.part_num] = 1
print ",".join(mobo_family.keys())
示例13: __init__
def __init__(self, infile, comment="#", sep=" ", field=(1,2), regexp=None):
self.infile = infile
self.comment = comment
if regexp:
from re import compile as recompile
self.regexp = recompile(regexp)
self.__read_line = self.__read_line_regexp
else:
self.sep = sep
self.field = field
self.__read_line = self.__read_line_cut
return
示例14: __init__
def __init__(self, call, **kwargs):
"""EventHandler initialization
PARAM: <func> function call for handling line when matched"""
if not callable(call):
raise RuntimeError
self.nick = recompile(kwargs.get('nick', '.*'))
"""nick to match
FORMAT: <module:regex>"""
self.ident = recompile(kwargs.get('ident', '.*'))
"""ident to match
FORMAT: <module:regex>"""
self.hostname = recompile(kwargs.get('hostname', '.*'))
"""hostname to match
FORMAT: <module:regex>"""
self.command = recompile(kwargs.get('command', '.*'))
"""command to match
FORMAT: <module:regex>"""
self.argument = recompile(kwargs.get('argument', '.*'))
"""argument to match
FORMAT: <module:regex>"""
self.message = recompile(kwargs.get('message', '.*'))
"""message to match (this is the final part of the message)
FORMAT: <module:regex>"""
self.call = call
"""the function to call if there is a match
示例15: __init__
def __init__ (self, header, skip_secondary=True):
print("\nParsing sam sequences")
# Store defined variables
self.header = header
self.skip_secondary = skip_secondary
# counters
self.count = {"total":0, "invalid":0, "primary":0, "secondary":0}
# For cigar to tuple code conversion
self.cigar_to_code = {'M':0, 'I':1, 'D':2, 'N':3, 'S':4, 'H':5, 'P':6, '=':7, 'X':8}
self.cigar_regex = recompile("(\d+)([MIDNSHP=X])")