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


Python URLObject.with_hostname方法代码示例

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


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

示例1: test_with_hostname_replaces_hostname

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

示例2: main

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import with_hostname [as 别名]
def main():


	for i in range(0,1405):


		for item in open('/Users/chadsahlhoff/python/ADN/appnet-logger/bin/ADNLogs/'+ str(i) +'.json','r'):
			line = eval(item)
			entities = line['entities']

			print i

			links_in_entities = entities['links']

			if (len(links_in_entities) != 0):
				for indices in links_in_entities:
					url = indices['url']


					try:
						url = URLObject(url)
						url = unicode(url.with_hostname(url.hostname.lower()))
						
					except:
						url = None

					if url == None:
						break
						
					if url.endswith('.'):
						url=url[:-1]

					if url.endswith(','):
						url=url[:-1]

					if url.endswith('!'):
						url=url[:-1]

					if url.endswith('?'):
						url=url[:-1]

					if url.endswith('/'):
						url=url[:-1]

					post_id = line['id']
					link = None

					try:
						link = hyper_links.find({'_id':url})

					except:	
						print 'shiz its not there'
						
					if link == None:
						print 'link == None'
						insert_link = {'_id':url,'count':1, 'posts':[post_id]}
						hyper_links.insert(insert_link)

					else:
						
						hyper_links.update({'_id':url},{'$inc':{'count':1}, '$addToSet':{'posts':post_id}}, upsert=True)
开发者ID:sahlhoff,项目名称:Mentions,代码行数:63,代码来源:import_links.py

示例3: SpurlURLBuilder

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import with_hostname [as 别名]

#.........这里部分代码省略.........
        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)

    def handle_host(self, value):
        host = self.prepare_value(value)
        self.url = self.url.with_hostname(host)

    def handle_host_from(self, value):
        url = URLObject(value)
        self.url = self.url.with_hostname(url.hostname)

    def handle_path(self, value):
        path = self.prepare_value(value)
        self.url = self.url.with_path(path)

    def handle_path_from(self, value):
        url = URLObject(value)
        self.url = self.url.with_path(url.path)

    def handle_add_path(self, value):
        path_to_add = self.prepare_value(value)
        self.url = self.url.add_path(path_to_add)

    def handle_add_path_from(self, value):
        url = URLObject(value)
        path_to_add = url.path
        if path_to_add.startswith('/'):
            path_to_add = path_to_add[1:]
        self.url = self.url.add_path(path_to_add)

    def handle_fragment(self, value):
        fragment = self.prepare_value(value)
        self.url = self.url.with_fragment(fragment)

    def handle_fragment_from(self, value):
        url = URLObject(value)
        self.url = self.url.with_fragment(url.fragment)
开发者ID:albertkoch,项目名称:django-spurl,代码行数:69,代码来源:spurl.py

示例4: SpurlURLBuilder

# 需要导入模块: from urlobject import URLObject [as 别名]
# 或者: from urlobject.URLObject import with_hostname [as 别名]

#.........这里部分代码省略.........
        current_query = self.url.query.dict

        for key, value in query_to_trigger.items():

            # exact match of query -> unset it
            if key in current_query and query_to_trigger[key] == current_query[key]:
                active = True

            # check if current query has multiple items
            try:
                ext = current_query[key]
                ext = ext.split(',')
            except Exception as e:
                ext = None

            if ext and len(ext) > 1:

                if key in current_query and value in ext:
                    active = True

        self.url = active



    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)

    def handle_host(self, value):
        host = self.prepare_value(value)
        self.url = self.url.with_hostname(host)

    def handle_host_from(self, value):
        url = URLObject(value)
        self.url = self.url.with_hostname(url.hostname)

    def handle_path(self, value):
        path = self.prepare_value(value)
        self.url = self.url.with_path(path)

    def handle_path_from(self, value):
        url = URLObject(value)
        self.url = self.url.with_path(url.path)

    def handle_add_path(self, value):
        path_to_add = self.prepare_value(value)
        self.url = self.url.add_path(path_to_add)

    def handle_add_path_from(self, value):
        url = URLObject(value)
        path_to_add = url.path
        if path_to_add.startswith('/'):
            path_to_add = path_to_add[1:]
        self.url = self.url.add_path(path_to_add)

    def handle_fragment(self, value):
        fragment = self.prepare_value(value)
        self.url = self.url.with_fragment(fragment)

    def handle_fragment_from(self, value):
        url = URLObject(value)
        self.url = self.url.with_fragment(url.fragment)
开发者ID:hzlf,项目名称:openbroadcast.org,代码行数:69,代码来源:spurl.py


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