本文整理匯總了Python中string.rfind方法的典型用法代碼示例。如果您正苦於以下問題:Python string.rfind方法的具體用法?Python string.rfind怎麽用?Python string.rfind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類string
的用法示例。
在下文中一共展示了string.rfind方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parseJavaScriptCalls
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def parseJavaScriptCalls():
global database_js
"""
Parse the JavaScript and download the files
"""
for j in database_js:
jsName = j[j.rfind('/')+1:]
if not os.path.exists('local/js/' + jsName):
# first download the file
dl(j,'local/js/' + jsName)
try:
jsContent = open('local/js/' + jsName, 'r')
except IOError:
continue
parseJavaScriptContent(jsContent)
jsContent.close()
示例2: printexpr
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def printexpr(expr_string):
""" printexpr(expr) -
print the value of the expression, along with linenumber and filename.
"""
stack = extract_stack ( )[-2:][0]
actualCall = stack[3]
left = string.find ( actualCall, '(' )
right = string.rfind ( actualCall, ')' )
caller_globals,caller_locals = _caller_symbols()
expr = eval(expr_string,caller_globals,caller_locals)
varType = type( expr )
stderr.write("%s:%d> %s == %s (%s)\n" % (
stack[0], stack[1],
string.strip( actualCall[left+1:right] )[1:-1],
repr(expr), str(varType)[7:-2]))
示例3: lineReceived
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def lineReceived(self, line):
parts = string.split(line)
if not parts:
parts = ['']
if len(parts) == 1:
slash_w = 0
else:
slash_w = 1
user = parts[-1]
if '@' in user:
host_place = string.rfind(user, '@')
user = user[:host_place]
host = user[host_place+1:]
return self.forwardQuery(slash_w, user, host)
if user:
return self.getUser(slash_w, user)
else:
return self.getDomain(slash_w)
示例4: _fixupParents
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def _fixupParents(self, alogger):
"""
Ensure that there are either loggers or placeholders all the way
from the specified logger to the root of the logger hierarchy.
"""
name = alogger.name
i = string.rfind(name, ".")
rv = None
while (i > 0) and not rv:
substr = name[:i]
if not self.loggerDict.has_key(substr):
self.loggerDict[substr] = PlaceHolder(alogger)
else:
obj = self.loggerDict[substr]
if isinstance(obj, Logger):
rv = obj
else:
assert isinstance(obj, PlaceHolder)
obj.append(alogger)
i = string.rfind(name, ".", 0, i - 1)
if not rv:
rv = self.root
alogger.parent = rv
示例5: fetch
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def fetch(file):
if base_url in file:
dir = file[len(base_url) - 1:rfind(file, '/') + 1]
file = file[rfind(file, '/') + 1:]
elif 'http' in file:
return
else:
dir = '/'
process(dir + file)
base_dir = path.dirname(dir + file)
if base_dir != '/':
base_dir += '/'
tree = ElementTree.parse(out_dir + dir + file)
for element in tree.getiterator():
if element.tag.split('}')[1] == 'url':
if element.text[-4:] != '.xml':
if not 'http' in element.text:
process(base_dir + element.text)
else:
fetch(element.text)
示例6: makeRoot
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def makeRoot(urlLocal):
if allowedExtensions(urlLocal):
return urlLocal[0:urlLocal.rfind('/')+1]
return urlLocal
示例7: giveGoodURL
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def giveGoodURL(href, urlLocal):
"""
It should return a good url...
href = argument retrieven from the href...
"""
if 'javascript' in href:
return htmldecode(urlLocal)
if 'http://' in href or 'https://' in href:
if urlLocal in href:
return htmldecode(href)
else:
return urlLocal
if len(href) < 1:
return htmldecode(urlLocal)
if href[0] == '?' and '?' not in urlLocal and not allowedExtensions(urlLocal):
for e in allowed:
if '.'+e in urlLocal:
return htmldecode(urlLocal + href)
return htmldecode(urlLocal + '/' + href)
else:
# simple name
if allowedExtensions(urlLocal) or '?' in urlLocal:
return htmldecode(urlLocal[0:urlLocal.rfind('/')+1] + href)
else:
return htmldecode(urlLocal + '/' + href)
return htmldecode(href)
示例8: rfindFirstJSChars
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def rfindFirstJSChars(string):
b = [string.rfind(k) for k in jsChars]
return max(b)
示例9: collectintargz
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def collectintargz(target, source, env):
""" Puts all source files into a tar.gz file. """
# the rpm tool depends on a source package, until this is chagned
# this hack needs to be here that tries to pack all sources in.
sources = env.FindSourceFiles()
# filter out the target we are building the source list for.
#sources = [s for s in sources if not (s in target)]
sources = filter(lambda s, t=target: not (s in t), sources)
# find the .spec file for rpm and add it since it is not necessarily found
# by the FindSourceFiles function.
#sources.extend( [s for s in source if str(s).rfind('.spec')!=-1] )
spec_file = lambda s: string.rfind(str(s), '.spec') != -1
sources.extend( filter(spec_file, source) )
# as the source contains the url of the source package this rpm package
# is built from, we extract the target name
#tarball = (str(target[0])+".tar.gz").replace('.rpm', '')
tarball = string.replace(str(target[0])+".tar.gz", '.rpm', '')
try:
#tarball = env['SOURCE_URL'].split('/')[-1]
tarball = string.split(env['SOURCE_URL'], '/')[-1]
except KeyError as e:
raise SCons.Errors.UserError( "Missing PackageTag '%s' for RPM packager" % e.args[0] )
tarball = src_targz.package(env, source=sources, target=tarball,
PACKAGEROOT=env['PACKAGEROOT'], )
return (target, tarball)
示例10: rightmost_separator
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def rightmost_separator(path, sep, _altsep=_altsep):
rfind = string.rfind
return max(rfind(path, sep), rfind(path, _altsep))
示例11: splitext
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def splitext(path):
"Same as os.path.splitext() but faster."
sep = rightmost_separator(path, os.sep)
dot = string.rfind(path, '.')
# An ext is only real if it has at least one non-digit char
if dot > sep and not containsOnly(path[dot:], "0123456789."):
return path[:dot],path[dot:]
else:
return path,""
示例12: RegGetValue
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def RegGetValue(root, key):
"""This utility function returns a value in the registry
without having to open the key first. Only available on
Windows platforms with a version of Python that can read the
registry. Returns the same thing as
SCons.Util.RegQueryValueEx, except you just specify the entire
path to the value, and don't have to bother opening the key
first. So:
Instead of:
k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows\CurrentVersion')
out = SCons.Util.RegQueryValueEx(k,
'ProgramFilesDir')
You can write:
out = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir')
"""
# I would use os.path.split here, but it's not a filesystem
# path...
p = key.rfind('\\') + 1
keyp = key[:p-1] # -1 to omit trailing slash
val = key[p:]
k = RegOpenKeyEx(root, keyp)
return RegQueryValueEx(k,val)
示例13: my_import
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def my_import(mname):
if '.' in mname:
i = string.rfind(mname, '.')
parent = my_import(mname[:i])
fp, pathname, description = imp.find_module(mname[i+1:],
parent.__path__)
else:
fp, pathname, description = imp.find_module(mname)
return imp.load_module(mname, fp, pathname, description)
示例14: authentication_hash_validate
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def authentication_hash_validate():
"""
This function is called to check if a username /
password combination is valid.
"""
def last_occurence_delete(string, character):
index = string.rfind(character)
if index is None or index < 0:
return string
return string[:index] + string[index + 1:]
hash_response = str(flask.request.headers.get('Authorization', ''))
if len(hash_response) == 0:
return False
hash_challenge_list = []
# Check normal url
url = str(flask.request.url)
hash_challenge = get_url_authorization(url)
hash_challenge_list.append(hash_challenge)
# If hash at the end of the url, try alternate hash as well
url = last_occurence_delete(url, '/')
hash_challenge = get_url_authorization(url)
hash_challenge_list.append(hash_challenge)
if '?' in url:
url.replace('?', '/?')
hash_challenge = get_url_authorization(url)
hash_challenge_list.append(hash_challenge)
return hash_response in hash_challenge_list
示例15: parse_primitive_type
# 需要導入模塊: import string [as 別名]
# 或者: from string import rfind [as 別名]
def parse_primitive_type(col):
idx = string.find(col, '(')
ridx = string.rfind(col, ')')
if idx < 0 and ridx < 0:
return [col]
elif idx > 0 and ridx > 0:
type = col[: idx].strip()
specs = col[idx + 1 : ridx]
specs = specs.split(',')
specs = map(str.strip, specs)
return [type, specs]
else:
raise RuntimeError("Invalid primitive type: " + col)