本文整理汇总了Python中string.rstrip方法的典型用法代码示例。如果您正苦于以下问题:Python string.rstrip方法的具体用法?Python string.rstrip怎么用?Python string.rstrip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string
的用法示例。
在下文中一共展示了string.rstrip方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: look_for_pythondoc
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def look_for_pythondoc(self, type, token, start, end, line):
if type == tokenize.COMMENT and string.rstrip(token) == "##":
# found a comment: set things up for comment processing
self.comment_start = start
self.comment = []
return self.process_comment_body
else:
# deal with "bare" subjects
if token == "def" or token == "class":
self.subject_indent = self.indent
self.subject_parens = 0
self.subject_start = self.comment_start = None
self.subject = []
return self.process_subject(type, token, start, end, line)
return self.look_for_pythondoc
##
# (Token handler) Processes a comment body. This handler adds
# comment lines to the current comment.
示例2: getsites
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def getsites(lang):
try:
page_counter=0
while page_counter < int(arg_page_end):
s.send("PONG %s\r\n" % line[1])
time.sleep(3)
results_web = 'http://www.google.com/search?q='+str(query)+'&hl='+str(lang)+'&lr=&ie=UTF-8&start='+repr(page_counter)+'&sa=N'
request_web = urllib2.Request(results_web)
request_web.add_header('User-Agent',random.choice(agents))
opener_web = urllib2.build_opener()
text = opener_web.open(request_web).read()
if re.search("403 Forbidden", text):
s.send("PRIVMSG %s :%s\r\n" % (CHAN, "[-] Received Captcha... Damn that sucks!"))
break
names = re.findall(('<cite>+[\w\d\?\/\.\=\s\-]+=+[\d]+[\w\d\?\/\.\=\s\-]+</cite>'),text.replace("<b>","").replace("</b>",""))
for name in names:
name = re.sub(" - \d+k - </cite>","",name.replace("<cite>","")).replace("</cite>","")
name = name.rstrip(" -")
sites.append(name)
page_counter +=10
except IOError:
s.send("PRIVMSG %s :%s\r\n" % (CHAN, "[-] Can't connect to Google Web!"))
示例3: visitNode_a_listing
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def visitNode_a_listing(self, node):
fileName = os.path.join(self.currDir, node.getAttribute('href'))
self.writer('\\begin{verbatim}\n')
lines = map(string.rstrip, open(fileName).readlines())
skipLines = int(node.getAttribute('skipLines') or 0)
lines = lines[skipLines:]
self.writer(text.removeLeadingTrailingBlanks('\n'.join(lines)))
self.writer('\\end{verbatim}')
# Write a caption for this source listing
fileName = os.path.basename(fileName)
caption = domhelpers.getNodeText(node)
if caption == fileName:
caption = 'Source listing'
self.writer('\parbox[b]{\linewidth}{\\begin{center}%s --- '
'\\begin{em}%s\\end{em}\\end{center}}'
% (latexEscape(caption), latexEscape(fileName)))
示例4: visitNode_a_listing
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def visitNode_a_listing(self, node):
fileName = os.path.join(self.currDir, node.getAttribute('href'))
self.writer('\\begin{verbatim}\n')
lines = map(string.rstrip, open(fileName).readlines())
lines = lines[int(node.getAttribute('skipLines', 0)):]
self.writer(text.removeLeadingTrailingBlanks('\n'.join(lines)))
self.writer('\\end{verbatim}')
# Write a caption for this source listing
fileName = os.path.basename(fileName)
caption = domhelpers.getNodeText(node)
if caption == fileName:
caption = 'Source listing'
self.writer('\parbox[b]{\linewidth}{\\begin{center}%s --- '
'\\begin{em}%s\\end{em}\\end{center}}'
% (latexEscape(caption), latexEscape(fileName)))
示例5: getdoc
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def getdoc(object):
"""Get the doc string or comments for an object."""
result = inspect.getdoc(object) or inspect.getcomments(object)
return result and re.sub('^ *\n', '', rstrip(result)) or ''
示例6: splitdoc
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def splitdoc(doc):
"""Split a doc string into a synopsis line (if any) and the rest."""
lines = split(strip(doc), '\n')
if len(lines) == 1:
return lines[0], ''
elif len(lines) >= 2 and not rstrip(lines[1]):
return lines[0], join(lines[2:], '\n')
return '', join(lines, '\n')
示例7: getdocloc
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def getdocloc(self, object):
"""Return the location of module docs or None"""
try:
file = inspect.getabsfile(object)
except TypeError:
file = '(built-in)'
docloc = os.environ.get("PYTHONDOCS",
"http://docs.python.org/library")
basedir = os.path.join(sys.exec_prefix, "lib",
"python"+sys.version[0:3])
if (isinstance(object, type(os)) and
(object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
'marshal', 'posix', 'signal', 'sys',
'thread', 'zipimport') or
(file.startswith(basedir) and
not file.startswith(os.path.join(basedir, 'site-packages')))) and
object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
if docloc.startswith("http://"):
docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
else:
docloc = os.path.join(docloc, object.__name__ + ".html")
else:
docloc = None
return docloc
# -------------------------------------------- HTML documentation generator
示例8: indent
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def indent(self, text, prefix=' '):
"""Indent text by prepending a given prefix to each line."""
if not text: return ''
lines = split(text, '\n')
lines = map(lambda line, prefix=prefix: prefix + line, lines)
if lines: lines[-1] = rstrip(lines[-1])
return join(lines, '\n')
示例9: section
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def section(self, title, contents):
"""Format a section with a given heading."""
return self.bold(title) + '\n' + rstrip(self.indent(contents)) + '\n\n'
# ---------------------------------------------- type-specific routines
示例10: getdoc
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def getdoc(object):
"""Get the doc string or comments for an object."""
result = inspect.getdoc(object) or inspect.getcomments(object)
result = _encode(result)
return result and re.sub('^ *\n', '', rstrip(result)) or ''
示例11: getdocloc
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def getdocloc(self, object,
basedir=os.path.join(sys.exec_prefix, "lib",
"python"+sys.version[0:3])):
"""Return the location of module docs or None"""
try:
file = inspect.getabsfile(object)
except TypeError:
file = '(built-in)'
docloc = os.environ.get("PYTHONDOCS",
"https://docs.python.org/library")
basedir = os.path.normcase(basedir)
if (isinstance(object, type(os)) and
(object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
'marshal', 'posix', 'signal', 'sys',
'thread', 'zipimport') or
(file.startswith(basedir) and
not file.startswith(os.path.join(basedir, 'site-packages')))) and
object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
if docloc.startswith(("http://", "https://")):
docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__.lower())
else:
docloc = os.path.join(docloc, object.__name__.lower() + ".html")
else:
docloc = None
return docloc
# -------------------------------------------- HTML documentation generator
示例12: _update
# 需要导入模块: import string [as 别名]
# 或者: from string import rstrip [as 别名]
def _update(self):
import string
self._index = {}
try:
f = _open(self._dirfile)
except IOError:
pass
else:
while 1:
line = string.rstrip(f.readline())
if not line:
break
key, (pos, siz) = eval(line)
self._index[key] = (pos, siz)
f.close()