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


Python URLObject.with_auth方法代码示例

本文整理汇总了Python中urlobject.URLObject.with_auth方法的典型用法代码示例。如果您正苦于以下问题:Python URLObject.with_auth方法的具体用法?Python URLObject.with_auth怎么用?Python URLObject.with_auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urlobject.URLObject的用法示例。


在下文中一共展示了URLObject.with_auth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_with_auth_with_two_args_replaces_whole_auth_string_with_username_and_password

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import with_auth [as 别名]
    def test_with_auth_with_two_args_replaces_whole_auth_string_with_username_and_password(self):
        # Replaces username-only auth string
        url = URLObject('https://[email protected]/')
        assert url.with_auth('zack', '1234') == 'https://zack:[email protected]/'

        # Replaces username and password.
        url = URLObject('https://alice:[email protected]/')
        assert url.with_auth('zack', '1234') == 'https://zack:[email protected]/'
开发者ID:vmalloc,项目名称:urlobject,代码行数:10,代码来源:urlobject_test.py

示例2: test_with_auth_with_two_args_adds_username_and_password

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import with_auth [as 别名]
 def test_with_auth_with_two_args_adds_username_and_password(self):
     url = URLObject('https://github.com/')
     assert url.with_auth('zack', '1234') == 'https://zack:[email protected]/'
开发者ID:vmalloc,项目名称:urlobject,代码行数:5,代码来源:urlobject_test.py

示例3: test_with_auth_with_one_arg_adds_username

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import with_auth [as 别名]
 def test_with_auth_with_one_arg_adds_username(self):
     url = URLObject('https://github.com/')
     assert url.with_auth('zack') == 'https://[email protected]/'
开发者ID:vmalloc,项目名称:urlobject,代码行数:5,代码来源:urlobject_test.py

示例4: test_with_auth_with_one_arg_replaces_whole_auth_string_with_username

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import with_auth [as 别名]
 def test_with_auth_with_one_arg_replaces_whole_auth_string_with_username(self):
     url = URLObject('https://alice:[email protected]/')
     assert url.with_auth('zack') == 'https://[email protected]/'
开发者ID:vmalloc,项目名称:urlobject,代码行数:5,代码来源:urlobject_test.py

示例5: SpurlURLBuilder

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import with_auth [as 别名]
class SpurlURLBuilder(object):

    def __init__(self, args, context, tags, filters):
        self.args = args
        self.context = context
        self.tags = tags
        self.filters = filters
        self.autoescape = self.context.autoescape
        self.url = URLObject()

    def build(self):
        for argument, value in self.args:
            self.handle_argument(argument, value)

        self.set_sensible_defaults()

        url = six.text_type(self.url)

        if self.autoescape:
            url = escape(url)

        return url

    def handle_argument(self, argument, value):
        argument = smart_str(argument, 'ascii')
        handler_name = 'handle_%s' % argument
        handler = getattr(self, handler_name, None)

        if handler is not None:
            value = value.resolve(self.context)
            handler(value)

    def handle_base(self, value):
        base = self.prepare_value(value)
        self.url = URLObject(base)

    def handle_auth(self, value):
        auth = self.prepare_value(value)
        self.url = self.url.with_auth(*auth.split(':', 1))

    def handle_secure(self, value):
        is_secure = convert_to_boolean(value)
        scheme = 'https' if is_secure else 'http'
        self.url = self.url.with_scheme(scheme)

    def handle_query(self, value):
        query = self.prepare_value(value)
        if isinstance(query, dict):
            query = QueryString().set_params(**query)
        self.url = self.url.with_query(QueryString(query))

    def handle_query_from(self, value):
        url = URLObject(value)
        self.url = self.url.with_query(url.query)

    def handle_add_query(self, value):
        query_to_add = self.prepare_value(value)
        if isinstance(query_to_add, six.string_types):
            query_to_add = QueryString(query_to_add).dict
        self.url = self.url.add_query_params(**query_to_add)

    def handle_add_query_from(self, value):
        url = URLObject(value)
        self.url = self.url.add_query_params(**url.query.dict)

    def handle_set_query(self, value):
        query_to_set = self.prepare_value(value)
        if isinstance(query_to_set, six.string_types):
            query_to_set = QueryString(query_to_set).dict
        self.url = self.url.set_query_params(**query_to_set)

    def handle_set_query_from(self, value):
        url = URLObject(value)
        self.url = self.url.set_query_params(**url.query.dict)

    def handle_remove_query_param(self, value):
        query_to_remove = self.prepare_value(value)
        self.url = self.url.del_query_param(query_to_remove)

    def handle_toggle_query(self, value):
        query_to_toggle = self.prepare_value(value)
        if isinstance(query_to_toggle, six.string_types):
            query_to_toggle = QueryString(query_to_toggle).dict
        current_query = self.url.query.dict
        for key, value in list(query_to_toggle.items()):
            if isinstance(value, six.string_types):
                value = value.split(',')
            first, second = value
            if key in current_query and first in current_query[key]:
                self.url = self.url.set_query_param(key, second)
            else:
                self.url = self.url.set_query_param(key, first)

    def handle_scheme(self, value):
        self.url = self.url.with_scheme(value)

    def handle_scheme_from(self, value):
        url = URLObject(value)
        self.url = self.url.with_scheme(url.scheme)

#.........这里部分代码省略.........
开发者ID:albertkoch,项目名称:django-spurl,代码行数:103,代码来源:spurl.py


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