當前位置: 首頁>>代碼示例>>Python>>正文


Python cookie.CookieManager類代碼示例

本文整理匯總了Python中grab.cookie.CookieManager的典型用法代碼示例。如果您正苦於以下問題:Python CookieManager類的具體用法?Python CookieManager怎麽用?Python CookieManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CookieManager類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_from_cookie_list

    def test_from_cookie_list(self):
        cookie = create_cookie("foo", "bar", self.server.address)
        mgr = CookieManager.from_cookie_list([cookie])
        test_cookie = [x for x in mgr.cookiejar if x.name == "foo"][0]
        self.assertEqual(cookie.name, test_cookie.name)

        mgr = CookieManager.from_cookie_list([])
        self.assertEqual(0, len(list(mgr.cookiejar)))
開發者ID:fangjintang1989,項目名稱:grab,代碼行數:8,代碼來源:grab_cookies.py

示例2: test_from_cookie_list

    def test_from_cookie_list(self):
        cookie = create_cookie('foo', 'bar')
        mgr = CookieManager.from_cookie_list([cookie])
        test_cookie = [x for x in mgr.cookiejar if x.name == 'foo'][0]
        self.assertEqual(cookie.name, test_cookie.name)

        mgr = CookieManager.from_cookie_list([])
        self.assertEqual(0, len(list(mgr.cookiejar)))
開發者ID:julia-bikova,項目名稱:grab,代碼行數:8,代碼來源:grab_cookies.py

示例3: __init__

    def __init__(self, document_body=None,
                 transport=None, **kwargs):
        """
        Create Grab instance
        """

        self.meta = {}
        self._doc = None
        self.config = default_config()
        self.config['common_headers'] = self.common_headers()
        self.cookies = CookieManager()
        self.proxylist = ProxyList()
        self.exception = None

        # makes pylint happy
        self.request_counter = None
        self.request_head = None
        self.request_body = None
        self.request_method = None
        self.transport_param = transport
        self.transport = None

        self.reset()
        if kwargs:
            self.setup(**kwargs)
        if document_body is not None:
            self.setup_document(document_body)
開發者ID:lorien,項目名稱:grab,代碼行數:27,代碼來源:base.py

示例4: test_pickle_serialization

 def test_pickle_serialization(self):
     cookie = create_cookie('foo', 'bar')
     mgr = CookieManager.from_cookie_list([cookie])
     dump = pickle.dumps(mgr)
     mgr2 = pickle.loads(dump)
     self.assertEqual(list(mgr.cookiejar)[0].value,
                      list(mgr2.cookiejar)[0].value)
開發者ID:julia-bikova,項目名稱:grab,代碼行數:7,代碼來源:grab_cookies.py

示例5: load_config

    def load_config(self, config):
        """
        Configure grab instance with external config object.
        """

        self.config = copy_config(config, self.mutable_config_keys)
        if 'cookiejar_cookies' in config['state']:
            self.cookies = CookieManager.from_cookie_list(config['state']['cookiejar_cookies'])
開發者ID:Kuznitsin,項目名稱:grab,代碼行數:8,代碼來源:base.py

示例6: __init__

    def __init__(self, document_body=None,
                 transport='pycurl', **kwargs):
        """
        Create Grab instance
        """

        self.meta = {}
        self._doc = None
        self.config = default_config()
        self.config['common_headers'] = self.common_headers()
        self.cookies = CookieManager()
        self.proxylist = ProxyList()
        self.setup_transport(transport)
        self.reset()
        if kwargs:
            self.setup(**kwargs)
        if document_body is not None:
            self.setup_document(document_body)
開發者ID:ixtel,項目名稱:grab,代碼行數:18,代碼來源:base.py

示例7: Grab

class Grab(DeprecatedThings):

    __slots__ = (
        'request_head', 'request_body',
        #'request_log',
        'proxylist', 'config',
        'transport',
        'transport_param', 'request_method', 'request_counter',
        '__weakref__', 'cookies',
        'meta', 'exception',

        # Dirty hack to make it possible to inherit Grab from
        # multiple base classes with __slots__
        '_doc',
    )

    # Attributes which should be processed when clone
    # of Grab instance is creating
    clonable_attributes = ('request_head', 'request_body',
                           #'request_log',
                           'proxylist')

    # Complex config items which points to mutable objects
    mutable_config_keys = copy(MUTABLE_CONFIG_KEYS)

    #
    # Public methods
    #

    def __init__(self, document_body=None,
                 transport=None, **kwargs):
        """
        Create Grab instance
        """

        self.meta = {}
        self._doc = None
        self.config = default_config()
        self.config['common_headers'] = self.common_headers()
        self.cookies = CookieManager()
        self.proxylist = ProxyList()
        self.exception = None

        # makes pylint happy
        self.request_counter = None
        self.request_head = None
        self.request_body = None
        self.request_method = None
        self.transport_param = transport
        self.transport = None

        self.reset()
        if kwargs:
            self.setup(**kwargs)
        if document_body is not None:
            self.setup_document(document_body)

    def _get_doc(self):
        if self._doc is None:
            self._doc = Document(self)
        return self._doc

    def _set_doc(self, obj):
        self._doc = obj

    doc = property(_get_doc, _set_doc)

    def setup_transport(self, transport_param, reset=False):
        if self.transport is not None and not reset:
            raise error.GrabMisuseError(
                'Transport is already set up. Use'
                ' setup_transport(..., reset=True) to explicitly setup'
                ' new transport')
        if transport_param is None:
            transport_param = DEFAULT_TRANSPORT
        if isinstance(transport_param, six.string_types):
            if transport_param in TRANSPORT_ALIAS:
                transport_param = TRANSPORT_ALIAS[transport_param]
            if '.' not in transport_param:
                raise error.GrabMisuseError('Unknown transport: %s'
                                            % transport_param)
            else:
                mod_path, cls_name = transport_param.rsplit('.', 1)
                try:
                    cls = TRANSPORT_CACHE[(mod_path, cls_name)]
                except KeyError:
                    mod = __import__(mod_path, globals(), locals(), ['foo'])
                    cls = getattr(mod, cls_name)
                    TRANSPORT_CACHE[(mod_path, cls_name)] = cls
                self.transport = cls()
        elif isinstance(transport_param, collections.Callable):
            self.transport = transport_param()
        else:
            raise error.GrabMisuseError('Option `transport` should be string '
                                        'or class or callable. Got %s'
                                        % type(transport_param))

    def reset(self):
        """
        Reset all attributes which could be modified during previous request
#.........這裏部分代碼省略.........
開發者ID:lorien,項目名稱:grab,代碼行數:101,代碼來源:base.py

示例8: test_get_item

 def test_get_item(self):
     cookie = create_cookie("foo", "bar", self.server.address)
     mgr = CookieManager.from_cookie_list([cookie])
     self.assertEqual("bar", mgr["foo"])
     self.assertRaises(KeyError, lambda: mgr["zzz"])
開發者ID:fangjintang1989,項目名稱:grab,代碼行數:5,代碼來源:grab_cookies.py

示例9: test_get_item

 def test_get_item(self):
     cookie = create_cookie('foo', 'bar')
     mgr = CookieManager.from_cookie_list([cookie])
     self.assertEqual('bar', mgr['foo'])
     self.assertRaises(KeyError, lambda: mgr['zzz'])
開發者ID:julia-bikova,項目名稱:grab,代碼行數:5,代碼來源:grab_cookies.py

示例10: Grab

class Grab(DeprecatedThings):

    __slots__ = ('request_head', 'request_log', 'request_body',
                 'proxylist', 'config',
                 'transport',
                 'transport_param', 'request_method', 'request_counter',
                 '__weakref__', 'cookies',

                 # Dirty hack to make it possible to inherit Grab from
                 # multiple base classes with __slots__
                 '_doc',
                 )

    # Attributes which should be processed when clone
    # of Grab instance is creating
    clonable_attributes = ('request_head', 'request_log', 'request_body',
                           'proxylist')

    # Complex config items which points to mutable objects
    mutable_config_keys = copy(MUTABLE_CONFIG_KEYS)

    """
    Public methods
    """

    def __init__(self, document_body=None,
                 transport='grab.transport.curl.CurlTransport', **kwargs):
        """
        Create Grab instance
        """

        self._doc = None
        self.config = default_config()
        self.config['common_headers'] = self.common_headers()
        self.cookies = CookieManager()
        self.proxylist = ProxyList()

        self.setup_transport(transport)

        self.reset()
        if kwargs:
            self.setup(**kwargs)

        if document_body is not None:
            self.setup_document(document_body)

    def _get_doc(self):
        if self._doc is None:
            self._doc = Document(self)
        return self._doc

    def _set_doc(self, obj):
        self._doc = obj

    doc = property(_get_doc, _set_doc)

    def setup_transport(self, transport_param):
        self.transport_param = transport_param
        if isinstance(transport_param, six.string_types):
            mod_path, cls_name = transport_param.rsplit('.', 1)
            try:
                cls = TRANSPORT_CACHE[(mod_path, cls_name)]
            except KeyError:
                mod = __import__(mod_path, globals(), locals(), ['foo'])
                cls = getattr(mod, cls_name)
                TRANSPORT_CACHE[(mod_path, cls_name)] = cls
            self.transport = cls()
        elif isinstance(transport_param, collections.Callable):
            self.transport = transport_param()
        else:
            raise error.GrabMisuseError('Option `transport` should be string '
                                        'or callable. Got %s'
                                        % type(transport_param))

    def reset(self):
        """
        Reset all attributes which could be modified during previous request
        or which is not initialized yet if this is the new Grab instance.

        This methods is automatically called before each network request.
        """

        self.request_head = None
        self.request_log = None
        self.request_body = None

        self.request_method = None
        self.transport.reset()

    def clone(self, **kwargs):
        """
        Create clone of Grab instance.

        Cloned instance will have the same state: cookies, referrer, response
        document data

        :param **kwargs: overrides settings of cloned grab instance
        """

        g = Grab(transport=self.transport_param)
#.........這裏部分代碼省略.........
開發者ID:abael,項目名稱:grab,代碼行數:101,代碼來源:base.py


注:本文中的grab.cookie.CookieManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。