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


Python BuiltIn.convert_to_integer方法代码示例

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


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

示例1: RequestsKeywords

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import convert_to_integer [as 别名]
class RequestsKeywords(object):
    ROBOT_LIBRARY_SCOPE = 'Global'

    def __init__(self):
        self._cache = robot.utils.ConnectionCache('No sessions created')
        self.builtin = BuiltIn()
        self.debug = 0

    def _create_session(
            self,
            alias,
            url,
            headers,
            cookies,
            auth,
            timeout,
            max_retries,
            backoff_factor,
            proxies,
            verify,
            debug,
            disable_warnings):
        """ Create Session: create a HTTP session to a server

        `url` Base url of the server

        `alias` Robot Framework alias to identify the session

        `headers` Dictionary of default headers

        `auth` List of username & password for HTTP Basic Auth

        `timeout` Connection timeout
        
        `max_retries` The maximum number of retries each connection should attempt.
        
        `backoff_factor` The pause between for each retry

        `proxies` Dictionary that contains proxy urls for HTTP and HTTPS communication

        `verify` Whether the SSL cert will be verified. A CA_BUNDLE path can also be provided.

        `debug` Enable http verbosity option more information
                https://docs.python.org/2/library/httplib.html#httplib.HTTPConnection.set_debuglevel
        
        `disable_warnings` Disable requests warning useful when you have large number of testcases                
        """

        self.builtin.log('Creating session: %s' % alias, 'DEBUG')
        s = session = requests.Session()
        s.headers.update(headers)
        s.auth = auth if auth else s.auth
        s.proxies = proxies if proxies else s.proxies

        max_retries = self.builtin.convert_to_integer(max_retries)        

        if max_retries > 0:
            http = requests.adapters.HTTPAdapter(max_retries=Retry(total=max_retries, backoff_factor=backoff_factor))
            https = requests.adapters.HTTPAdapter(max_retries=Retry(total=max_retries, backoff_factor=backoff_factor))
            
            # Disable requests warnings, useful when you have large number of testcase
            # you will observe drastical changes in Robot log.html and output.xml files size 
            if disable_warnings:
                logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests
                logging.getLogger().setLevel(logging.ERROR)
                requests_log = logging.getLogger("requests")
                requests_log.setLevel(logging.ERROR)
                requests_log.propagate = True
            
            
            # Replace the session's original adapters
            s.mount('http://', http)
            s.mount('https://', https)

        # verify can be a Boolean or a String
        if isinstance(verify, bool):
            s.verify = verify
        elif isinstance(verify, unicode) or isinstance(verify, str):
            if verify.lower() == 'true' or verify.lower() == 'false':
                s.verify = self.builtin.convert_to_boolean(verify)
        else:
            # not a Boolean nor a String
            s.verify = verify

        # cant pass these into the Session anymore
        self.timeout = float(timeout) if timeout is not None else None
        self.cookies = cookies
        self.verify = verify

        s.url = url

        # Enable http verbosity
        if debug >= 1:
            self.debug = int(debug)
            httplib.HTTPConnection.debuglevel = self.debug

        self._cache.register(session, alias=alias)
        return session

    def create_session(self, alias, url, headers={}, cookies=None,
#.........这里部分代码省略.........
开发者ID:ajaymedikonda,项目名称:robotframework-requests,代码行数:103,代码来源:RequestsKeywords.py


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