当前位置: 首页>>代码示例>>Python>>正文


Python Resource.setParams方法代码示例

本文整理汇总了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
开发者ID:vandyvilla,项目名称:PyProfiler,代码行数:71,代码来源:url_parser.py


注:本文中的resource.Resource.setParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。