本文整理汇总了Python中re.re_sub函数的典型用法代码示例。如果您正苦于以下问题:Python re_sub函数的具体用法?Python re_sub怎么用?Python re_sub使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了re_sub函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: escape_script_tag
def escape_script_tag(text):
return re_sub(
r'<script>',
'<script>',
re_sub(
r'</script>',
'</script>',
text,
flags=RE_IGNORECASE
),
flags=RE_IGNORECASE
)
开发者ID:AliKSanderZ,项目名称:demo-code,代码行数:12,代码来源:utils.py
示例2: sanitize_seq
def sanitize_seq(seq, alphabet):
alphdict = alphabet.todict()
assert(len(GAPS) > 0 and len(seq) > 0 and len(alphdict) > 0)
try:
seq = str(seq)
seq = seq.upper()
seq = re_sub(r'[%s]' % GAPS, '-', seq)
seq = re_sub(r'[^%s]' % ''.join(alphdict.keys()), 'X', seq)
except TypeError:
raise RuntimeError(
'something is amiss with things:\n GAPS = %s\n seq = %s\n alphabet = %s\n' % (
GAPS, seq, alphdict)
)
return seq
开发者ID:BioinformaticsArchive,项目名称:idepi,代码行数:14,代码来源:_common.py
示例3: applyConfig
def applyConfig(self, ret = False):
if ret == True:
data = {'isMounted': False,
'mountusing': False,
'active': False,
'ip': False,
'sharename': False,
'sharedir': False,
'username': False,
'password': False,
'mounttype': False,
'options': False,
'hdd_replacement': False}
data['mountusing'] = self.mountusingConfigEntry.value
data['active'] = self.activeConfigEntry.value
data['ip'] = self.ipConfigEntry.getText()
data['sharename'] = re_sub('\\W', '', self.sharenameConfigEntry.value)
if self.sharedirConfigEntry.value.startswith('/'):
data['sharedir'] = self.sharedirConfigEntry.value[1:]
else:
data['sharedir'] = self.sharedirConfigEntry.value
data['options'] = self.optionsConfigEntry.value
data['mounttype'] = self.mounttypeConfigEntry.value
data['username'] = self.usernameConfigEntry.value
data['password'] = self.passwordConfigEntry.value
data['hdd_replacement'] = self.hdd_replacementConfigEntry.value
self.applyConfigRef = None
self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _('Please wait for activation of your network mount...'), type=MessageBox.TYPE_INFO, enable_input=False)
iAutoMount.automounts[self.sharenameConfigEntry.value] = data
iAutoMount.writeMountsConfig()
iAutoMount.getAutoMountPoints(self.applyConfigDataAvail)
else:
self.close()
开发者ID:OUARGLA86,项目名称:enigma2,代码行数:33,代码来源:MountEdit.py
示例4: read_article
def read_article(hashed=None, keyword=None):
global HASHED
hashed = int(hashed)
if keyword:
like_keyword(keyword)
articles = list()
more_articles = list()
with Bot() as b:
if hashed:
link = None
try:
link = DEHASHED[hashed]
except KeyError:
for article in b.database["articles"]:
if hashed == hash(article):
link = article
break
if link:
b.update_article(link, read=True)
article = dict(b.database["articles"][link])
article['source'] = __get_source_domain(link)
article['date'] = time.ctime(article['release'])
original_content = markdown.markdown(escape(article['content']))
spaned_content = []
for paragraph in [p for p in RE_PARAGRAPHS.findall(original_content) if p]:
sentences = [s for s in RE_SENTENCES.findall(paragraph) if s]
if not sentences:
continue
elif len(sentences) == 1:
spaned_content.append("<p><span>%s</span></p>" % sentences[0])
else:
spaned_content.append(
"<p>%s</p>" % \
("<span>%s</span>"*3 % \
(sentences[0], "".join(sentences[1:-2]), sentences[-1]))
)
article['spaned_content'] = " ".join(spaned_content)
if keyword:
article['spaned_content'] = re_sub(r"(%s)" % keyword,
r"<strong>\1</strong>", article['spaned_content'],
flags=IGNORECASE)
articles.append(article)
unread_with_keyword = lambda x: not x["read"] and keyword in x["keywords"]
more_articles = sorted([x for x in b.database["articles"].values()
if unread_with_keyword(x)],
key=b.relevance_of_article)
HASHED.update({hash(x["link"]): x["link"] for x in more_articles})
return render_template("read.html",
style=url_for("static", filename="default.css"),
articles=articles,
more_articles=more_articles,
hashed=HASHED,
keyword=keyword)
开发者ID:pschwede,项目名称:AnchorBot,代码行数:60,代码来源:web.py
示例5: replace_entities
def replace_entities( text ): #{
""" Replaces HTML/XML character references and entities in a text string with
actual Unicode characters.
@param text The HTML (or XML) source text.
@return The plain text, as a Unicode string, if necessary.
>>> a = '<a href="/abc?a=50&amp;b=test">'
>>> print replace_entities( a )
<a href="/abc?a=50&b=test">
"""
def fixup(m):
text = m.group(0)
if text[:2] == "&#":
# character reference
try:
if text[:3] == "&#x":
return unichr(int(text[3:-1], 16))
else:
return unichr(int(text[2:-1]))
except ValueError:
pass
else:
# named entity
try:
text = unichr(name2codepoint[text[1:-1]])
except KeyError:
pass
return text # leave as is
return re_sub("&#?\w+;", fixup, string(text))
开发者ID:MuratSagdicoglu,项目名称:btce-trollbox,代码行数:30,代码来源:btce-trollbox.py
示例6: ok
def ok(self):
current = self["config"].getCurrent()
if current == self.sharenameEntry or current == self.sharedirEntry or current == self.sharedirEntry or current == self.optionsEntry or current == self.usernameEntry or current == self.passwordEntry:
if current[1].help_window.instance is not None:
current[1].help_window.instance.hide()
sharename = re_sub("\W", "", self.sharenameConfigEntry.value)
if self.sharedirConfigEntry.value.startswith("/"):
sharedir = self.sharedirConfigEntry.value[1:]
else:
sharedir = self.sharedirConfigEntry.value
sharexists = False
for data in self.mounts:
if self.mounts[data]['sharename'] == sharename:
if self.mounts[data]['sharedir'] != sharedir:
sharexists = True
break
if sharexists:
self.session.open(MessageBox, _("A mount entry with this name already exists!\nand is not this share folder, please use a different name.\n"), type = MessageBox.TYPE_INFO )
elif self.old_sharename != self.sharenameConfigEntry.value:
self.session.openWithCallback(self.updateConfig, MessageBox, _("You have changed the share name!\nUpdate existing entry and continue?\n"), default=False )
elif self.mounts.has_key(sharename) is True:
self.session.openWithCallback(self.updateConfig, MessageBox, _("A mount entry with this name already exists!\nUpdate existing entry and continue?\n"), default=False )
else:
self.session.openWithCallback(self.applyConfig, MessageBox, _("Are you sure you want to save this network mount?\n\n") )
开发者ID:mx3L,项目名称:enigma2-plugins,代码行数:27,代码来源:MountEdit.py
示例7: deal_title
def deal_title(self, text):
# print(text)
dealers = [
# trim and remove Creole in head
['\\s*[\\*#=\\|]*\\s*(.+?)\\s*$', '\\1'],
# \t to space
['(?<!\\\\)\\\\t', ' '],
# \\ to \
['\\\\\\\\', '\\\\'],
# *=|
['\\|(\\s*[\\*#=\\|]*)?\\s*', ' '],
# |$
['\\|\\s*$', ''],
# \\text\\
['\\*{2}(.+)\\*{2}', '\\1'],
# __text__
['_{2}(.+)_{2}', '\\1'],
# //text//
['\\/{2}(.+)\\/{2}', '\\1'],
# ""text""
['"{2}(.+)"{2}', '\\1'],
# --text--
['-{2}(.+)-{2}', '\\1'],
# ~~text~~
['~{2}(.+)~{2}', '\\1'],
# remove invalid chrs
['[\\\\/:*?"<>|]',' ']
]
for [fnd,repl] in dealers:
# print(fnd+', '+repl)
text = re_sub(fnd,repl,text)
return text.strip()
开发者ID:qjebbs,项目名称:sublime_diagram_plugin,代码行数:32,代码来源:plantuml.py
示例8: _storeArticle
def _storeArticle(article):
"""
_safeArticle(Dict) -> Bool
private help method to safe an aticle
param article:Dict -
"""
# try:
#make a path according to the article's topics
path = re_sub('http://www.spiegel.de/','', article['link']).split('/')
filename = path.pop(-1)
storePath = os_path_join(BASE_PATH,os_path_join(*path))
#create directories
if not os_path_exists(storePath):
os_makedirs(storePath)
#write article as json to the file
with open(os_path_join(storePath, filename),'w') as o:
json.dump(article, o)
#write the article name to the log
if os_path_isfile(BASE_PATH + 'article_log'):
log = open(BASE_PATH + 'article_log','a')
else:
log = open(BASE_PATH + 'article_log','w')
log.write(article['link'] + '\n')
log.close()
return True
开发者ID:pyfn,项目名称:SpiegelCollector,代码行数:27,代码来源:DataManager.py
示例9: applyConfig
def applyConfig(self, ret = False):
if ret:
if self._cfgMounttype.value == 'nfs':
data = iAutoMount.DEFAULT_OPTIONS_NFS
else:
data = iAutoMount.DEFAULT_OPTIONS_CIFS
data['active'] = self._cfgActive.value
data['ip'] = self._cfgIp.getText()
data['sharename'] = re_sub("\W", "", self._cfgSharename.value)
# "\W" matches everything that is "not numbers, letters, or underscores",where the alphabet defaults to ASCII.
if self._cfgSharedir.value.startswith("/"):
data['sharedir'] = self._cfgSharedir.value[1:]
else:
data['sharedir'] = self._cfgSharedir.value
data['options'] = self._cfgOptions.value
data['mounttype'] = self._cfgMounttype.value
data['username'] = self._cfgUsername.value
data['password'] = self._cfgPassword.value
data['hdd_replacement'] = self._cfgHddReplacement.value
self._applyConfigMsgBox = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait while I'm saving your network mount..."), type = MessageBox.TYPE_INFO, enable_input = False)
iAutoMount.mounts[self._cfgSharename.value] = data
iAutoMount.save()
iAutoMount.reload(self.applyConfigDataAvail)
else:
self.close()
开发者ID:dpuschek,项目名称:enigma2-plugins,代码行数:25,代码来源:MountEdit.py
示例10: applyConfig
def applyConfig(self, ret = False):
if (ret == True):
data = { 'isMounted': False, 'mountusing': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, \
'username': False, 'password': False, 'mounttype' : False, 'options' : False, 'hdd_replacement' : False }
data['mountusing'] = self.mountusingConfigEntry.value
data['active'] = self.activeConfigEntry.value
data['ip'] = self.ipConfigEntry.getText()
data['sharename'] = re_sub("\W", "", self.sharenameConfigEntry.value)
# "\W" matches everything that is "not numbers, letters, or underscores",where the alphabet defaults to ASCII.
if self.sharedirConfigEntry.value.startswith("/"):
data['sharedir'] = self.sharedirConfigEntry.value[1:]
else:
data['sharedir'] = self.sharedirConfigEntry.value
data['options'] = self.optionsConfigEntry.value
data['mounttype'] = self.mounttypeConfigEntry.value
data['username'] = self.usernameConfigEntry.value
data['password'] = self.passwordConfigEntry.value
data['hdd_replacement'] = self.hdd_replacementConfigEntry.value
self.applyConfigRef = None
self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network mount..."), type = MessageBox.TYPE_INFO, enable_input = False)
iAutoMount.automounts[self.sharenameConfigEntry.value] = data
iAutoMount.writeMountsConfig()
iAutoMount.getAutoMountPoints(self.applyConfigDataAvail, True)
else:
self.close()
开发者ID:Firestorm552,项目名称:enigma2-plugins,代码行数:25,代码来源:MountEdit.py
示例11: getMesg
def getMesg(self, smtpData):
global outDIR, verbose, flagM
if flagM:# Get header/text/html?
msg = message_from_string(smtpData)
# Use regex to clean up timestamp for pathname
msgDIR = os.path.join(outDIR, re_sub('[:,-]','',msg.get("date").replace(' ','_')))
if debug: print "msgDIR: ", msgDIR
if os.path.isdir(msgDIR) == False: os.makedirs(msgDIR, 0755)
fh = open(os.path.join(msgDIR, "header"),'w')
# For each header item
for i in msg.items():
if debug: print("%s: %s" % (i[0], i[1]))
# Write field and value
fh.write("%s: %s\n" % (i[0], i[1]))
fh.close()
for part in msg.walk():
# Open these files to append just in case there's more than one of this content type. Don't overwrite!
#RFC6838 & http://www.iana.org/assignments/media-types/media-types.xhtml
if (part.get_content_type() == "text/plain"):
if debug or verbose: print "\tSaving text... "
if debug: print part.get_payload(decode=True)
fh = open(os.path.join(msgDIR, "message_text"),'a')
fh.write(part.get_payload(decode=True))
fh.close()
elif (part.get_content_type() == "text/html"):
if debug or verbose: print "\tSaving HTML... "
if debug: print part.get_payload(decode=True)
fh = open(os.path.join(msgDIR, "message_HTML"),'a')
fh.write(part.get_payload(decode=True))
fh.close()
else:
msgDIR = outDIR
self.getAttach(smtpData, msgDIR)# Get attachments now
开发者ID:CyberTaoFlow,项目名称:smtpae,代码行数:34,代码来源:smtpae.py
示例12: main
def main(args=None):
if args is None:
args = sys_argv[1:]
parser = ArgumentParser(description='')
parser.add_argument('TREE', type=PathType)
parser.add_argument('FEATURES', type=feattype)
ns = parser.parse_args(args)
tree, alignment, colnames, _ = PhyloGzFile.read(ns.TREE)
icolnames = [(idx, colname) for idx, colname in enumerate(colnames) if int(NUMERIC.sub('', colname)) in ns.FEATURES]
for r in alignment:
# labels has length of icolnames plus the ic50
labels = [None] * (len(icolnames) + 1)
i = 1
for idx, colname in icolnames:
if len(colnames) > 1:
labels[i] = colname + r.seq[idx]
else:
labels[i] = r.seq[idx]
i += 1
try:
labels[0] = '%.3g' % mean(seqrecord_get_values(r))
except ValueError:
if not (len(r.id) > 4 and r.id[:4].lower() == 'node'):
print(r)
labels.pop(0)
# include the ':' here to make sure we grab the end of the label
tree = re_sub(r'([,()])' + r.id + r'(?:_[0-9]+)?:', r'\g<1>' + '_'.join(labels) + ':', tree)
print(tree)
return 0
开发者ID:BioinformaticsArchive,项目名称:idepi,代码行数:35,代码来源:_tree.py
示例13: gallery
def gallery(offset=0, number=12, since=259200, keyword=None):
"""Arrangement of unread articles."""
global HASHED, DEHASHED
offset = int(offset)
number = int(number)
back_then = int(since)
HASHED = dict()
DEHASHED = dict()
with Bot() as b:
articles = b.hot_articles(offset, number, since, keyword)
watched_keywords = frozenset(b.database["keyword_clicks"].keys())
for article in articles:
link = article["link"]
if not article["keywords"]:
b.update_article(link, read=True)
continue
# generate and remember hash values
HASHED[link] = hash(link)
DEHASHED[hash(link)] = link
# split headline into links
split_headline = unicode(escape(article["title"].lower())).split(" ")
sorted_kwords = sorted(article["keywords"], key=len, reverse=True)
linked_headline = []
contained_watched_keywords = watched_keywords & set(sorted_kwords)
for word in split_headline:
kwords = [kw for kw in sorted_kwords if kw.lower() in word.lower()]
if not kwords:
continue
template = r"""<a href="/read/%s/because/of/\1" target="_blank">\1</a>"""
if word in contained_watched_keywords:
template = "<i>%s</i>" % template
linked_headline.append(
re_sub(r"(%s)" % kwords[0],
template % HASHED[link],
word,
flags=IGNORECASE))
if not linked_headline:
continue
article["linked_headline"] = " ".join(linked_headline)
[int(k) for k in HASHED.values()]
# prepare data sets for gallery
scores = {a["link"]: b.relevance_of_article(a) for a in articles}
scores["all"] = sum([b.relevance_of_article(x) for x in articles])
content = render_template("gallery.html",
style=url_for("static", filename="default.css"),
articles=articles,
new_offset=offset + 1,
hashed=HASHED,
scores=scores)
return content
开发者ID:pschwede,项目名称:AnchorBot,代码行数:59,代码来源:web.py
示例14: plot_save_regressions
def plot_save_regressions(regressions_for_noise_amount, net_filename):
from pylab import (imshow,subplot,bar,xticks,xlim,axhline,title,
xlabel,ylabel,arange,show,cm,figure,savefig,save,imsave)
name = net_filename.rsplit('.', 1)[0]
# how many noise levels we have to draw
N = len(regressions_for_noise_amount)
print("Will plot for for {} noise levels...".format(N))
ind = arange(N) # the x locations for the groups
print("ind = {}".format(ind))
width = 0.35 # the width of the bars
# projection id -> name, as returned into tuples by http://ffnet.sourceforge.net/apidoc.html#ffnet.ffnet.test
y_name = ["slope",
"intercept",
"r-value",
"p-value",
"slope stderr",
"estim. stderr"]
for projection_id in range(6): # todo has bug? how do i select the data
#subplot(11 + projection_id * 100) # a new plot
figure()
projection_name = y_name[projection_id]
ylabel(projection_name)
print("Plotting for projection: " + projection_name)
projections = regressions_for_noise_amount.T[projection_id]
print("Projections on {} tuple field ({}) = {}".format(projection_id, projection_name, projections))
title(projection_name + " for noise levels...") # todo change me?
for i in ind:
bar(i, projections[i], width, color='b') # plot it
# bar(ind, projections[ind], width, color='b') # plot it
xticks(ind+width/2., range(0, N)) # todo print noise levels
xlim(-width,N-width)
axhline(linewidth=1, color='black')
xlabel("Noise amount")
# debug uncomment to look at graphs
# show()
plot_output_formats = ['png', 'eps']
for format in plot_output_formats:
plot_name = re_sub(
"[^a-z]",
"_",
y_name[projection_id].lower() )
plot_filename = "{}_plot_{}.{}".format(
name,
plot_name,
format)
savefig(plot_filename, orientation='portrait')
print("Saved plot as: {}.".format(plot_filename))
开发者ID:barthez,项目名称:letters-recognition-nn,代码行数:59,代码来源:train.py
示例15: updateKey
def updateKey(self):
key = ''
if self.url != '':
# Use regex to extract update_key
regex = r"^.*update.php\?([0-9A-Za-z=]*)$"
key = re_sub(regex, r'\1', self.url)
return key
开发者ID:DJSymBiotiX,项目名称:python-dyndns,代码行数:8,代码来源:Retreive.py
示例16: splitReadheader
def splitReadheader(self, alignedRead, dontTrustSamFlags=False):
"""Split the read header to determine the common part of a pair and it's pair ref"""
query = re_sub("[_/\.][12]$", '', alignedRead.qname) # this will not affect illumina headers
if dontTrustSamFlags:
# try work out pairing info from the read header itself
try:
end = int(re_sub(".*[_/\.]",'', alignedRead.qname))
except:
return (query, None)
if end != 1 and end != 2:
return (query, None)
else:
if alignedRead.is_read1:
end = 1
else:
end = 2
return (query, end)
开发者ID:minillinim,项目名称:BamTyper,代码行数:17,代码来源:utilities.py
示例17: check_url_fname
def check_url_fname(fname, fname_max_len):
"""Check file name given in URL after last slash / and remove not allowed
chars"""
# Remove unprinted chars and strip it
fname = re_sub("[\x00-\x19/]", "", fname).strip()
if len(fname) > fname_max_len:
return 0
return fname
开发者ID:warstranger,项目名称:Simple-File-Server,代码行数:9,代码来源:sfutils.py
示例18: fetch
def fetch(self):
"""
Fetch the WebFinger profile and return the XML document.
"""
template_url = self._get_template()
target_url = re_sub(
"\{uri\}", quote_plus(self.request_email.scheme + ":" + self.request_email.path), template_url
)
return etree.parse(urlopen(target_url))
开发者ID:Zauberstuhl,项目名称:pyaspora,代码行数:9,代码来源:protocol.py
示例19: add_schedule
def add_schedule(schedule, element):
name = normalize("NFKD", unicode(element.string)).strip()
if len(name):
times = re_findall("\d*[,.:]\d{2}", name)
timetable = []
for time in times:
hour, minute = re_sub("[,.]", ":", time).split(":")
if len(hour):
timetable.append("{:02d}:{:s}".format(int(hour), minute))
schedule.append({"time": timetable, "name": name})
开发者ID:a-rank,项目名称:avaandmed,代码行数:10,代码来源:utils.py
示例20: getvendorexact
def getvendorexact(raw,vendors_str):
brand='Other'
vendors=vendors_str.split(',')
sep_title=re_sub(r'([\(\)\[\]\{\},])', ' \1 ', raw)
title_words=sep_title.lower()
for brnd in vendors:
if brnd.lower() in title_words:
brand=brnd
break
return brand
开发者ID:Shreksan,项目名称:olx,代码行数:10,代码来源:get_items_nadavi.py
注:本文中的re.re_sub函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论