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


Python parse.urlparse方法代码示例

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


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

示例1: save_file

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def save_file(self, local_file_path=None, remote_file_path=None, file_obj=None):
        """
        保存本地文件至weed_fs文件系统
        {"name":"test.csv","size":425429}
        """
        assign = self._get_assign()
        url = 'http://%s/%s' % (assign['url'], assign['fid'])

        if local_file_path:
            file_obj = open(local_file_path, 'rb')
        elif remote_file_path:
            headers = {'Host': urlparse(remote_file_path).netloc}  # 防反爬, 指定图片 Host
            headers.update(self.request_headers)
            res = requests.get(remote_file_path, headers=headers, timeout=REQUESTS_TIME_OUT)
            if res.status_code == 200:
                file_obj = res.content
            else:
                raise Exception('File does not exist')
        elif not file_obj:
            raise Exception('File does not exist')

        res = requests.post(url, files={'file': file_obj}, timeout=REQUESTS_TIME_OUT)
        return dict(res.json(), **assign) 
开发者ID:zhanghe06,项目名称:news_spider,代码行数:25,代码来源:weed_fs.py

示例2: token_stage

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def token_stage():
    # find out where this account is
    xframe, user_discovery_uri, resource = do_autodiscover(config['domain'])

    # Get the inbound token as posted from a form
    token = request.form['access_token']
    state = request.form['session_state']

    # discover which web server we have been assigned to
    user_discovery_data = do_user_discovery(resource, token, config)

    # Link to the current session server resource (we need a token for this.)
    instance_url = user_discovery_data['_links']['applications']['href']

    instance_parts = urlparse(instance_url)
    instance_resource = '{0}://{1}'.format(instance_parts.scheme, instance_parts.netloc)

    url = grant_flow_token(config['client_id'],
                                     config['redirect_uri'] + '/directsession',
                                     instance_resource, state, token)

    return redirect(url) 
开发者ID:tonybaloney,项目名称:pyucwa,代码行数:24,代码来源:http.py

示例3: api_request

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def api_request(url, method="get", params=None, ret_key=None):
    params = params or {}
    resp = None
    try:
        method = method.lower()
        params = build_api_key(urlparse(url).path, params)
        if method == "get":
            resp = getattr(requests, method)(url, params=params)
        else:
            resp = getattr(requests, method)(url, data=params)
        if resp.status_code != 200:
            return abort(resp.status_code, resp.json().get("message"))
        resp = resp.json()
        if ret_key is not None:
            return resp.get(ret_key)
        return resp
    except Exception as e:
        code = e.code if hasattr(e, "code") else None
        if isinstance(code, int) and resp is not None:
            return abort(code, resp.json().get("message"))
        current_app.logger.warning(url)
        current_app.logger.warning(params)
        current_app.logger.error(str(e))
        return abort(500, "server unknown error") 
开发者ID:pycook,项目名称:cmdb,代码行数:26,代码来源:http_cli.py

示例4: decode_url_connection_string

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def decode_url_connection_string(conn_str):
    """URL connection string into more useful parts"""
    parse_result = urlparse(conn_str)

    try:
        decoded = dict()
        decoded['scheme'] = parse_result.scheme
        decoded['username'] = parse_result.username
        decoded['password'] = parse_result.password
        decoded['hostname'] = parse_result.hostname
        decoded['port'] = parse_result.port
        decoded['database'] = __split_db_and_table_path(parse_result.path)[0]
        # decoded['table'] = __split_db_and_table_path(parse_result.path)[1]

        if any(v in {None, ''} for k, v in decoded.items()):
            return None
    except IndexError:
        return None

    return decoded 
开发者ID:dsaidgovsg,项目名称:airflow-pipeline,代码行数:22,代码来源:connstr.py

示例5: decode_simple_url_conn_string

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def decode_simple_url_conn_string(conn_str):
    """URL connection string into more useful parts"""
    parse_result = urlparse(conn_str)

    try:
        decoded = dict()
        decoded['scheme'] = parse_result.scheme
        decoded['hostname'] = parse_result.hostname
        decoded['port'] = parse_result.port
        decoded['path'] = parse_result.path

        if any(v in {None, ''} and (k in ('scheme', 'hostname', 'path'))
               for k, v in decoded.items()):
            return None
    except IndexError:
        return None

    return decoded 
开发者ID:dsaidgovsg,项目名称:airflow-pipeline,代码行数:20,代码来源:connstr.py

示例6: _make_qr

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def _make_qr(builder, oauth, meta, config_dict, lets_connect, secret=None):
    # type: (Gtk.builder, str, Metadata, dict, bool, Any) -> None
    image = builder.get_object('totp-qr-image')
    if not secret:
        secret = gen_base32()
    host = urlparse(meta.api_base_uri).netloc
    uri = "otpauth://totp/{user_id}@{host}?secret={secret}&issuer={host}".format(user_id=meta.user_id, host=host,
                                                                                 secret=secret)
    qr = qrcode.QRCode(box_size=7, border=2)
    qr.add_data(uri)
    qr.make()
    img = qr.make_image()

    pixbuf = pil2pixbuf(img)
    image.set_from_pixbuf(pixbuf)
    GLib.idle_add(lambda: _parse_user_input(builder, oauth, meta, config_dict=config_dict,
                                            lets_connect=lets_connect, secret=secret))


# ui thread 
开发者ID:eduvpn,项目名称:python-eduvpn-client,代码行数:22,代码来源:totp_enroll.py

示例7: authorize

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def authorize(auth_url, user, password):
    browser = mechanicalsoup.StatefulBrowser(raise_on_404=True)
    logger.info("opening auth_url")
    response = browser.open(auth_url)
    assert(response.ok)
    browser.select_form('form[action="/vpn-user-portal/_form/auth/verify"]')
    browser["userName"] = user
    browser["userPass"] = password
    logger.info("logging in")
    response = browser.submit_selected()
    assert(response.ok)
    form = browser.select_form()
    if 'action' in form.form.attrs and form.form.attrs['action'] == '/vpn-user-portal/_two_factor/auth/verify/totp':
        raise EduvpnAuthException("otp enabled")
    assert(urlparse(browser.get_url()).path == "/vpn-user-portal/_oauth/authorize")  # make sure is the right page
    form = browser.select_form()
    form.form.select('button[value="yes"]')
    logger.info("authorising app")
    response = browser.submit_selected()
    assert(response.ok) 
开发者ID:eduvpn,项目名称:python-eduvpn-client,代码行数:22,代码来源:online.py

示例8: str_to_url

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def str_to_url(value):
    """
    Returns a UUID(value) if the value provided is a str.

    :param value: str or UUID object
    :return: UUID object
    """
    return urlparse(value) if isinstance(value, string_types) else value 
开发者ID:genomoncology,项目名称:related,代码行数:10,代码来源:converters.py

示例9: to_json_dict

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def to_json_dict(self, skip_id=False):
        if self.url is not None:
            try:
                url_parsed = urlparse(self.url)
                netloc = url_parsed.netloc
            except Exception as e:
                logger.error(e)
                netloc = None
        else:
            netloc = None

        d = {
            'unique_name': self.unique_name,
            'name': self.name,
            'url': self.url,
            'is_builtin': self.is_builtin,
            'netloc': netloc,
            'version': self.version,
            'enable_acl': self.enable_acl,
            'enable_hmac': self.enable_hmac,
            'require_login': self.require_login,
            'async_http_connect_timeout': self.async_http_connect_timeout,
            'async_http_request_timeout': self.async_http_request_timeout,
            'memo': self.memo,
        }

        if hasattr(self, 'enable'):
            d['enable'] = self.enable

        # 是否要过滤id
        if not skip_id:
            d['id'] = self.id

        if hasattr(self, 'acl_rules'):
            d['acl_rules'] = [t.to_json_dict(skip_id) for t in self.acl_rules]

        return d 
开发者ID:restran,项目名称:fomalhaut-panel,代码行数:39,代码来源:models.py

示例10: prepare_url

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def prepare_url(self):
        url_parsed = urlparse(self.raw_base_url)
        items = url_parsed.path.split('/')
        if len(items) > 0:
            item = items[-1]
            items = items[:-1]
            new_path = '/'.join(items)
        else:
            item = ''
            new_path = url_parsed.path
        url = urlunparse((url_parsed.scheme, url_parsed.netloc, new_path, '', '', ''))

        if item.endswith('.php'):
            self.site_lang = 'php'
        elif item.endswith('.asp'):
            self.site_lang = 'asp'
        elif item.endswith('.aspx'):
            self.site_lang = 'aspx'

        if self.site_lang != '':
            logger.info('site_lang: %s' % self.site_lang)
        self.base_url = url
        self.first_item = item
        logger.info('base_url: %s' % url)
        logger.info('first_item: %s' % item) 
开发者ID:restran,项目名称:hacker-scripts,代码行数:27,代码来源:scanner.py

示例11: get_update_url

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def get_update_url(url, data):
    """
    获取更新后的url
    :param url:
    :param data:
    :return:
    """
    result = urlparse(url)
    query_payload = dict(parse_qsl(result.query), **data)
    query_param = urlencode(query_payload)
    return urlunparse((result.scheme, result.netloc, result.path, result.params, query_param, result.fragment)) 
开发者ID:zhanghe06,项目名称:news_spider,代码行数:13,代码来源:url.py

示例12: get_url_query_param

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def get_url_query_param(url, param):
    """
    获取url参数值
    :param url:
    :param param:
    :return:
    """
    result = urlparse(url)
    return dict(parse_qsl(result.query)).get(param) 
开发者ID:zhanghe06,项目名称:news_spider,代码行数:11,代码来源:url.py

示例13: allow_url

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def allow_url(url, allow_domains):
    url_parse = urlparse(url)
    result = False
    for domain in allow_domains:
        if url_parse.netloc.endswith(domain):
            result = True
    return result 
开发者ID:zhanghe06,项目名称:news_spider,代码行数:9,代码来源:url.py

示例14: do_autodiscover

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def do_autodiscover(domain):
    r = requests.get('https://webdir.online.lync.com/autodiscover/autodiscoverservice.svc/root?originalDomain=%s' % domain)
    discovery = r.json()
    path = discovery['_links']['user']['href']
    domain = urlparse(path)
    host = '{0}://{1}'.format(domain.scheme, domain.netloc)
    return (discovery['_links']['xframe']['href'], path, host) 
开发者ID:tonybaloney,项目名称:pyucwa,代码行数:9,代码来源:actions.py

示例15: get_file

# 需要导入模块: from future.moves.urllib import parse [as 别名]
# 或者: from future.moves.urllib.parse import urlparse [as 别名]
def get_file(self, url='', path=''):
        '''It is possible to mimic FTP bulk data downloads using the \
                HTTP-based data distribution server at https://oceandata.sci.gsfc.nasa.gov.

        :param url: a single file name which can be obtained by calling #file_search() \
                an example would be \
                https://oceandata.sci.gsfc.nasa.gov/cgi/getfile/O1997001.L3b_DAY_CHL.nc
        :type url: :mod:`string`

        :param path: Destination directory into which the granule \
                needs to be downloaded.
        :type path: :mod:`string`

        :returns: a file object downloaded from the \
                HTTP-based data distribution server at https://oceandata.sci.gsfc.nasa.gov.

        '''
        try:
            # url = GET_URL
            if url:
                url = url
            else:
                raise Exception("'file' parameter is required!")
            file = os.path.basename(urlparse(url).path)
            if path == '':
                path = os.path.join(os.path.dirname(__file__), file)
            else:
                path = path + '/' + file
            urlretrieve(url, path)
            print("Downloaded '%s' to '%s'" % (file, path))
            return file

        except Exception as e:
            print(e)
            raise 
开发者ID:nasa,项目名称:podaacpy,代码行数:37,代码来源:oceancolor.py


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