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


Python parse.urlparse方法代码示例

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


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

示例1: parse_rommon_file_location

# 需要导入模块: from ansible.module_utils.six.moves.urllib import parse [as 别名]
# 或者: from ansible.module_utils.six.moves.urllib.parse import urlparse [as 别名]
def parse_rommon_file_location(rommon_file_location):
        rommon_url = urlparse(rommon_file_location)
        if rommon_url.scheme != 'tftp':
            raise ValueError('The ROMMON image must be downloaded from TFTP server, other protocols are not supported.')
        return rommon_url.netloc, rommon_url.path 
开发者ID:CiscoDevNet,项目名称:FTDAnsible,代码行数:7,代码来源:device.py

示例2: detect_no_proxy

# 需要导入模块: from ansible.module_utils.six.moves.urllib import parse [as 别名]
# 或者: from ansible.module_utils.six.moves.urllib.parse import urlparse [as 别名]
def detect_no_proxy(self, url):
        '''
        Detect if the 'no_proxy' environment variable is set and honor those locations.
        '''
        env_no_proxy = os.environ.get('no_proxy')
        if env_no_proxy:
            env_no_proxy = env_no_proxy.split(',')
            netloc = urlparse(url).netloc

            for host in env_no_proxy:
                if netloc.endswith(host) or netloc.split(':')[0].endswith(host):
                    # Our requested URL matches something in no_proxy, so don't
                    # use the proxy for this
                    return False
        return True 
开发者ID:lean-delivery,项目名称:ansible-role-jenkins,代码行数:17,代码来源:urls.py

示例3: maybe_add_ssl_handler

# 需要导入模块: from ansible.module_utils.six.moves.urllib import parse [as 别名]
# 或者: from ansible.module_utils.six.moves.urllib.parse import urlparse [as 别名]
def maybe_add_ssl_handler(url, validate_certs, ca_path=None):
    parsed = generic_urlparse(urlparse(url))
    if parsed.scheme == 'https' and validate_certs:
        if not HAS_SSL:
            raise NoSSLError('SSL validation is not available in your version of python. You can use validate_certs=False,'
                             ' however this is unsafe and not recommended')

        # create the SSL validation handler and
        # add it to the list of handlers
        return SSLValidationHandler(parsed.hostname, parsed.port or 443, ca_path=ca_path) 
开发者ID:lean-delivery,项目名称:ansible-role-jenkins,代码行数:12,代码来源:urls.py

示例4: __init__

# 需要导入模块: from ansible.module_utils.six.moves.urllib import parse [as 别名]
# 或者: from ansible.module_utils.six.moves.urllib.parse import urlparse [as 别名]
def __init__(self, args):
        self._args = args
        self._cloud_environment = None
        self._compute_client = None
        self._resource_client = None
        self._network_client = None

        self.debug = False
        if args.debug:
            self.debug = True

        self.credentials = self._get_credentials(args)
        if not self.credentials:
            self.fail("Failed to get credentials. Either pass as parameters, set environment variables, "
                      "or define a profile in ~/.azure/credentials.")

        # if cloud_environment specified, look up/build Cloud object
        raw_cloud_env = self.credentials.get('cloud_environment')
        if not raw_cloud_env:
            self._cloud_environment = azure_cloud.AZURE_PUBLIC_CLOUD  # SDK default
        else:
            # try to look up "well-known" values via the name attribute on azure_cloud members
            all_clouds = [x[1] for x in inspect.getmembers(azure_cloud) if isinstance(x[1], azure_cloud.Cloud)]
            matched_clouds = [x for x in all_clouds if x.name == raw_cloud_env]
            if len(matched_clouds) == 1:
                self._cloud_environment = matched_clouds[0]
            elif len(matched_clouds) > 1:
                self.fail("Azure SDK failure: more than one cloud matched for cloud_environment name '{0}'".format(raw_cloud_env))
            else:
                if not urlparse.urlparse(raw_cloud_env).scheme:
                    self.fail("cloud_environment must be an endpoint discovery URL or one of {0}".format([x.name for x in all_clouds]))
                try:
                    self._cloud_environment = azure_cloud.get_cloud_from_metadata_endpoint(raw_cloud_env)
                except Exception as e:
                    self.fail("cloud_environment {0} could not be resolved: {1}".format(raw_cloud_env, e.message))

        if self.credentials.get('subscription_id', None) is None:
            self.fail("Credentials did not include a subscription_id value.")
        self.log("setting subscription_id")
        self.subscription_id = self.credentials['subscription_id']

        if self.credentials.get('client_id') is not None and \
           self.credentials.get('secret') is not None and \
           self.credentials.get('tenant') is not None:
            self.azure_credentials = ServicePrincipalCredentials(client_id=self.credentials['client_id'],
                                                                 secret=self.credentials['secret'],
                                                                 tenant=self.credentials['tenant'],
                                                                 cloud_environment=self._cloud_environment)
        elif self.credentials.get('ad_user') is not None and self.credentials.get('password') is not None:
            tenant = self.credentials.get('tenant')
            if not tenant:
                tenant = 'common'
            self.azure_credentials = UserPassCredentials(self.credentials['ad_user'],
                                                         self.credentials['password'],
                                                         tenant=tenant,
                                                         cloud_environment=self._cloud_environment)
        else:
            self.fail("Failed to authenticate with provided credentials. Some attributes were missing. "
                      "Credentials must include client_id, secret and tenant or ad_user and password.") 
开发者ID:PacktPublishing,项目名称:Ansible-2-Cloud-Automation-Cookbook,代码行数:61,代码来源:azure_rm.py


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