本文整理汇总了Python中purl.URL.add_path_segment方法的典型用法代码示例。如果您正苦于以下问题:Python URL.add_path_segment方法的具体用法?Python URL.add_path_segment怎么用?Python URL.add_path_segment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类purl.URL
的用法示例。
在下文中一共展示了URL.add_path_segment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UnicodeTests
# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import add_path_segment [as 别名]
class UnicodeTests(TestCase):
def setUp(self):
self.base = URL('http://127.0.0.1/')
self.text = u'ć'
self.bytes = self.text.encode('utf8')
def test_set_unicode_query_param_value(self):
url = self.base.query_param('q', self.text)
self.assertEqual(self.text, url.query_param('q'))
def test_set_bytestring_query_param_value(self):
url = self.base.query_param('q', self.bytes)
self.assertEqual(self.text, url.query_param('q'))
def test_set_unicode_query_param_key(self):
url = self.base.query_param(self.text, 'value')
self.assertEqual('value', url.query_param(self.text))
def test_set_bytestring_query_param_key(self):
url = self.base.query_param(self.bytes, 'value')
self.assertEqual('value', url.query_param(self.text))
def test_append_unicode_query_param(self):
url = self.base.append_query_param('q', self.text)
self.assertEqual(self.text, url.query_param('q'))
def test_append_bytestring_query_param(self):
url = self.base.append_query_param('q', self.bytes)
self.assertEqual(self.text, url.query_param('q'))
def test_set_unicode_query_params(self):
url = self.base.query_params({'q': self.text})
self.assertEqual(self.text, url.query_param('q'))
def test_set_bytestring_query_params(self):
url = self.base.query_params({'q': self.bytes})
self.assertEqual(self.text, url.query_param('q'))
def test_add_unicode_path_segment(self):
url = self.base.add_path_segment(self.text)
self.assertEqual(self.text, url.path_segment(0))
def test_add_bytestring_path_segment(self):
url = self.base.add_path_segment(self.bytes)
self.assertEqual(self.text, url.path_segment(0))
def test_add_bytestring_path_segment(self):
url = self.base.add_path_segment(self.bytes)
self.assertEqual(self.text, url.path_segment(0))
def test_add_unicode_fragment(self):
url = self.base.fragment(self.text)
self.assertEqual(self.text, url.fragment())
示例2: get_resource_url
# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import add_path_segment [as 别名]
def get_resource_url(self, id=None, action=None):
"""
Get a base URL for the resource with the given id and/or action.
:return: A string URL with the full path to the resource
"""
base_url = URL(Configuration.BASE_API_URL).add_path_segment(self._resource_name)
if id:
base_url = base_url.add_path_segment(id)
if action:
base_url = base_url.add_path_segment(action)
return base_url.as_string()