本文整理汇总了Python中resource.Resource.setParams方法的典型用法代码示例。如果您正苦于以下问题:Python Resource.setParams方法的具体用法?Python Resource.setParams怎么用?Python Resource.setParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource.Resource
的用法示例。
在下文中一共展示了Resource.setParams方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parseUrl
# 需要导入模块: from resource import Resource [as 别名]
# 或者: from resource.Resource import setParams [as 别名]
def parseUrl(self, url):
debug = False
if debug: print url
if url.find('?') == -1:
path = url
para = ''
else:
path = url[:url.find('?')]
para = url[url.find('?'):][1:]
params = {}
pattern = ''
regex_path = ''
cur_node = self.url_tree.root
# start processing url:
comps = path.split('/')
for index in range(len(comps)):
item = comps[index]
if item == '':
continue
# check lang code:
if index == 1:
if util.matchRegex('[a-z][a-z](-[A-Z][A-Z])?', item):
pattern += '/<pattern.lang>'
regex_path += '/([a-z][a-z](-[A-Z][A-Z])?)'
continue
# walk the url tree:
if item in cur_node.children:
cur_node = cur_node.children[item]
pattern += '/' + item
regex_path += '/' + item
else:
token = ''
match = False
for child in cur_node.children.keys():
# check for placeholder:
if util.matchRegex('<[\S]+>', child):
#print 'match:', child
if token == '':
token = '/' + child
param_token = '/([a-zA-Z0-9._-]+)'
match = True
# only one regex match.
#else:
# reg += '|' + child
# store param value.(only one)
params[child] = item
cur_node = cur_node.children[child]
break
if match:
pattern += token
regex_path += param_token
else:
pattern += '/' + item
regex_path += '/' + item
if debug: print 'url pattern: ', pattern
res = Resource(pattern)
#res.setRegexPath(regex_path)
if para != '':
parts = para.split('&')
for part in parts:
if part.find('=') == -1:
continue
name = part.split('=')[0]
value = part.split('=')[1]
params[name] = value
res.setParams(params)
return res