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


Python utils.add_dict_to_cookiejar函数代码示例

本文整理汇总了Python中requests.utils.add_dict_to_cookiejar函数的典型用法代码示例。如果您正苦于以下问题:Python add_dict_to_cookiejar函数的具体用法?Python add_dict_to_cookiejar怎么用?Python add_dict_to_cookiejar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: login

    def login(self):
        """Login method used for logging in before doing a search and torrent downloads."""
        cookie_dict = dict_from_cookiejar(self.session.cookies)
        if cookie_dict.get('session'):
            return True

        if self.cookies:
            add_dict_to_cookiejar(self.session.cookies, dict(x.rsplit('=', 1) for x in self.cookies.split(';')))

        cookie_dict = dict_from_cookiejar(self.session.cookies)
        if cookie_dict.get('session'):
            return True

        login_params = {
            'submit': 'Login',
            'username': self.username,
            'password': self.password,
            'keeplogged': 1,
        }

        response = self.get_url(self.urls['login'], post_data=login_params, returns='text')
        if not response:
            logger.log(u"Unable to connect to provider", logger.WARNING)
            return False

        if re.search('<title>Login :: BJ-Share</title>', response):
            logger.log(u"Invalid username or password. Check your settings", logger.WARNING)
            return False

        return True
开发者ID:shtrom,项目名称:SickRage,代码行数:30,代码来源:bjshare.py

示例2: add_cookies_from_ui

    def add_cookies_from_ui(self):
        """
        Adds the cookies configured from UI to the providers requests session
        :return: A dict with the the keys result as bool and message as string
        """

        # This is the generic attribute used to manually add cookies for provider authentication
        if self.enable_cookies:
            if self.cookies:
                cookie_validator = re.compile(r'^(\w+=\w+)(;\w+=\w+)*$')
                if not cookie_validator.match(self.cookies):
                    ui.notifications.message('Failed to validate cookie for provider {provider}'.format(provider=self.name),
                                             'Cookie is not correctly formatted: {0}'.format(self.cookies))
                    return {'result': False,
                            'message': 'Cookie is not correctly formatted: {0}'.format(self.cookies)}

                # cookie_validator got at least one cookie key/value pair, let's return success
                add_dict_to_cookiejar(self.session.cookies, dict(x.rsplit('=', 1) for x in self.cookies.split(';')))
                return {'result': True,
                        'message': ''}

            else:  # Else is not needed, but placed it here for readability
                ui.notifications.message('Failed to validate cookie for provider {provider}'.format(provider=self.name),
                                         'No Cookies added from ui for provider: {0}'.format(self.name))
                return {'result': False,
                        'message': 'No Cookies added from ui for provider: {0}'.format(self.name)}

        return {'result': False,
                'message': 'Adding cookies is not supported for provider: {0}'.format(self.name)}
开发者ID:Eiber,项目名称:SickRage-Medusa,代码行数:29,代码来源:GenericProvider.py

示例3: _getRSSData

    def _getRSSData(self):
        logger.log(u"Cache update URL: %s" % self.provider.url, logger.DEBUG)

        if self.provider.cookies:
            add_dict_to_cookiejar(self.provider.session.cookies, dict(x.rsplit('=', 1) for x in self.provider.cookies.split(';')))

        return self.getRSSFeed(self.provider.url)
开发者ID:Indigo744,项目名称:SickRage,代码行数:7,代码来源:rsstorrent.py

示例4: add_cookies_from_ui

    def add_cookies_from_ui(self):
        """
        Adds the cookies configured from UI to the providers requests session
        :return: A tuple with the the (success result, and a descriptive message in str)
        """

        # This is the generic attribute used to manually add cookies for provider authentication
        if self.enable_cookies and self.cookies:
            cookie_validator = re.compile(r'^(\w+=\w+)(;\w+=\w+)*$')
            if not cookie_validator.match(self.cookies):
                return False, 'Cookie is not correctly formatted: {0}'.format(self.cookies)
            add_dict_to_cookiejar(self.session.cookies, dict(x.rsplit('=', 1) for x in self.cookies.split(';')))
            return True, 'torrent cookie'

        return False, 'No Cookies added from ui for provider: {0}'.format(self.name)
开发者ID:NickMolloy,项目名称:SickRage,代码行数:15,代码来源:GenericProvider.py

示例5: add_cookies_from_ui

    def add_cookies_from_ui(self):
        """
        Adds the cookies configured from UI to the providers requests session
        :return: A tuple with the the (success result, and a descriptive message in str)
        """

        # This is the generic attribute used to manually add cookies for provider authentication
        if self.enable_cookies and self.cookies:
            cookie_validator = re.compile(r'^(\w+=\w+)(;\w+=\w+)*$')
            if cookie_validator.match(self.cookies):
                add_dict_to_cookiejar(sickrage.srCore.srWebSession.cookies,
                                      dict(x.rsplit('=', 1) for x in self.cookies.split(';')))
                return True

        return False
开发者ID:djenniex,项目名称:SickBeard-TVRage,代码行数:15,代码来源:__init__.py

示例6: test_add_dict_to_cookiejar

def test_add_dict_to_cookiejar(cookiejar):
    """Ensure add_dict_to_cookiejar works for
    non-RequestsCookieJar CookieJars
    """
    cookiedict = {'test': 'cookies',
                  'good': 'cookies'}
    cj = add_dict_to_cookiejar(cookiejar, cookiedict)
    cookies = dict((cookie.name, cookie.value) for cookie in cj)
    assert cookiedict == cookies
开发者ID:PoNote,项目名称:requests,代码行数:9,代码来源:test_utils.py

示例7: add_cookies_from_ui

    def add_cookies_from_ui(self):
        """
        Add the cookies configured from UI to the providers requests session.

        :return: A dict with the the keys result as bool and message as string
        """
        # Added exception for rss torrent providers, as for them adding cookies initial should be optional.
        from medusa.providers.torrent.rss.rsstorrent import TorrentRssProvider
        if isinstance(self, TorrentRssProvider) and not self.cookies:
            return {'result': True,
                    'message': 'This is a TorrentRss provider without any cookies provided. '
                               'Cookies for this provider are considered optional.'}

        # This is the generic attribute used to manually add cookies for provider authentication
        if not self.enable_cookies:
            return {'result': False,
                    'message': 'Adding cookies is not supported for provider: {0}'.format(self.name)}

        if not self.cookies:
            return {'result': False,
                    'message': 'No Cookies added from ui for provider: {0}'.format(self.name)}

        cookie_validator = re.compile(r'^([\w%]+=[\w%]+)(;[\w%]+=[\w%]+)*$')
        if not cookie_validator.match(self.cookies):
            ui.notifications.message(
                'Failed to validate cookie for provider {provider}'.format(provider=self.name),
                'Cookie is not correctly formatted: {0}'.format(self.cookies))
            return {'result': False,
                    'message': 'Cookie is not correctly formatted: {0}'.format(self.cookies)}

        if not all(req_cookie in [x.rsplit('=', 1)[0] for x in self.cookies.split(';')]
                   for req_cookie in self.required_cookies):
            return {
                'result': False,
                'message': "You haven't configured the requied cookies. Please login at {provider_url}, "
                           'and make sure you have copied the following cookies: {required_cookies!r}'
                           .format(provider_url=self.name, required_cookies=self.required_cookies)
            }

        # cookie_validator got at least one cookie key/value pair, let's return success
        add_dict_to_cookiejar(self.session.cookies, dict(x.rsplit('=', 1) for x in self.cookies.split(';')))
        return {'result': True,
                'message': ''}
开发者ID:pymedusa,项目名称:SickRage,代码行数:43,代码来源:generic_provider.py

示例8: login

    def login(self):
        if any(dict_from_cookiejar(self.session.cookies).values()):
            return True

        login_params = {
            'username': self.username,
            'password': self.password,
        }

        if self._uid and self._hash:
            add_dict_to_cookiejar(self.session.cookies, self.cookies)
        else:
            response = self.get_url(self.urls['login'], post_data=login_params, returns='text')
            if not response:
                logger.log('Unable to connect to provider', logger.WARNING)
                return False

            if re.search('/logout.php', response):
                try:
                    if dict_from_cookiejar(self.session.cookies)['uid'] and \
                            dict_from_cookiejar(self.session.cookies)['pass']:
                        self._uid = dict_from_cookiejar(self.session.cookies)['uid']
                        self._hash = dict_from_cookiejar(self.session.cookies)['pass']

                        self.cookies = {'uid': self._uid,
                                        'pass': self._hash}
                        return True
                except Exception:
                    logger.log('Unable to login to provider (cookie)', logger.WARNING)

                    return False
            else:
                if re.search('Username does not exist in the userbase or the account is not confirmed yet.', response) or \
                    re.search('Username or password is incorrect. If you have an account here please use the'
                              ' recovery system or try again.', response):
                    logger.log('Invalid username or password. Check your settings', logger.WARNING)

                if re.search('DDoS protection by CloudFlare', response):
                    logger.log('Unable to login to provider due to CloudFlare DDoS javascript check', logger.WARNING)

                    return False
开发者ID:Eiber,项目名称:SickRage-Medusa,代码行数:41,代码来源:freshontv.py

示例9: validateRSS

    def validateRSS(self):

        try:
            if self.cookies:
                cookie_validator = re.compile(r"^(\w+=\w+)(;\w+=\w+)*$")
                if not cookie_validator.match(self.cookies):
                    return False, 'Cookie is not correctly formatted: ' + self.cookies

            # pylint: disable=protected-access
            # Access to a protected member of a client class
            data = self.cache._getRSSData()['entries']
            if not data:
                return False, 'No items found in the RSS feed ' + self.url

            (title, url) = self._get_title_and_url(data[0])

            if not title:
                return False, 'Unable to get title from first item'

            if not url:
                return False, 'Unable to get torrent url from first item'

            if url.startswith('magnet:') and re.search(r'urn:btih:([\w]{32,40})', url):
                return True, 'RSS feed Parsed correctly'
            else:
                if self.cookies:
                    add_dict_to_cookiejar(self.session.cookies,
                                                         dict(x.rsplit('=', 1) for x in self.cookies.split(';')))
                torrent_file = self.get_url(url, need_bytes=True)
                try:
                    bdecode(torrent_file)
                except Exception as e:
                    self.dumpHTML(torrent_file)
                    return False, 'Torrent link is not a valid torrent file: ' + ex(e)

            return True, 'RSS feed Parsed correctly'

        except Exception as e:
            return False, 'Error when trying to load RSS: ' + ex(e)
开发者ID:lastdevonearth,项目名称:SickRage,代码行数:39,代码来源:rsstorrent.py

示例10: login

    def login(self):

        if any(dict_from_cookiejar(self.session.cookies).values()):
            return True

        if self._uid and self._hash:
            add_dict_to_cookiejar(self.session.cookies, self.cookies)
        else:

            login_params = {
                'username': self.username,
                'password': self.password,
                'submit.x': 0,
                'submit.y': 0
            }

            response = self.get_url(self.urls['login'], post_data=login_params, timeout=30)
            if not response:
                logger.log(u"Unable to connect to provider", logger.WARNING)
                return False

            if re.search('You tried too often', response):
                logger.log(u"Too many login access attempts", logger.WARNING)
                return False

            try:
                if dict_from_cookiejar(self.session.cookies)['uid'] and dict_from_cookiejar(self.session.cookies)['pass']:
                    self._uid = dict_from_cookiejar(self.session.cookies)['uid']
                    self._hash = dict_from_cookiejar(self.session.cookies)['pass']

                    self.cookies = {'uid': self._uid,
                                    'pass': self._hash}
                    return True
            except Exception:
                pass

            logger.log(u"Unable to obtain cookie", logger.WARNING)
            return False
开发者ID:lastdevonearth,项目名称:SickRage,代码行数:38,代码来源:torrentday.py

示例11: login

    def login(self):
        if any(dict_from_cookiejar(self.session.cookies).values()):
            return True

        if self._uid and self._hash:
            add_dict_to_cookiejar(self.session.cookies, self.cookies)
        else:
            login_params = {'username': self.username,
                            'password': self.password,
                            'login': 'submit'}

            response = self.get_url(self.urls['login'], post_data=login_params, timeout=30)
            if not response:
                logger.log(u"Unable to connect to provider", logger.WARNING)
                return False

            if re.search('/logout.php', response):

                try:
                    if dict_from_cookiejar(self.session.cookies)['uid'] and dict_from_cookiejar(self.session.cookies)['pass']:
                        self._uid = dict_from_cookiejar(self.session.cookies)['uid']
                        self._hash = dict_from_cookiejar(self.session.cookies)['pass']

                        self.cookies = {'uid': self._uid,
                                        'pass': self._hash}
                        return True
                except Exception:
                    logger.log(u"Unable to login to provider (cookie)", logger.WARNING)
                    return False

            else:
                if re.search('Username does not exist in the userbase or the account is not confirmed yet.', response):
                    logger.log(u"Invalid username or password. Check your settings", logger.WARNING)

                if re.search('DDoS protection by CloudFlare', response):
                    logger.log(u"Unable to login to provider due to CloudFlare DDoS javascript check", logger.WARNING)

                    return False
开发者ID:Hydrog3n,项目名称:SickRage,代码行数:38,代码来源:freshontv.py

示例12: login

    def login(self):
        if any(dict_from_cookiejar(self.session.cookies).values()):
            return True

        if self._uid and self._hash:
            add_dict_to_cookiejar(self.session.cookies, self.cookies)
        else:
            login_params = {"username": self.username, "password": self.password, "login": "submit"}

            response = self.get_url(self.urls["login"], post_data=login_params, returns="text")
            if not response:
                logger.log(u"Unable to connect to provider", logger.WARNING)
                return False

            if re.search("/logout.php", response):

                try:
                    if (
                        dict_from_cookiejar(self.session.cookies)["uid"]
                        and dict_from_cookiejar(self.session.cookies)["pass"]
                    ):
                        self._uid = dict_from_cookiejar(self.session.cookies)["uid"]
                        self._hash = dict_from_cookiejar(self.session.cookies)["pass"]

                        self.cookies = {"uid": self._uid, "pass": self._hash}
                        return True
                except Exception:
                    logger.log(u"Unable to login to provider (cookie)", logger.WARNING)
                    return False

            else:
                if re.search("Username does not exist in the userbase or the account is not confirmed yet.", response):
                    logger.log(u"Invalid username or password. Check your settings", logger.WARNING)

                if re.search("DDoS protection by CloudFlare", response):
                    logger.log(u"Unable to login to provider due to CloudFlare DDoS javascript check", logger.WARNING)

                    return False
开发者ID:Comptezero,项目名称:SickRage,代码行数:38,代码来源:freshontv.py

示例13: validateRSS

    def validateRSS(self):  # pylint: disable=too-many-return-statements

        try:
            if self.cookies:
                cookie_validator = re.compile(r'^(\w+=\w+)(;\w+=\w+)*$')
                if not cookie_validator.match(self.cookies):
                    return False, 'Cookie is not correctly formatted: {0}'.format(self.cookies)
                add_dict_to_cookiejar(self.session.cookies, dict(x.rsplit('=', 1) for x in self.cookies.split(';')))

            # pylint: disable=protected-access
            # Access to a protected member of a client class
            data = self.cache._get_rss_data()['entries']
            if not data:
                return False, 'No items found in the RSS feed {0}'.format(self.url)

            title, url = self._get_title_and_url(data[0])

            if not title:
                return False, 'Unable to get title from first item'

            if not url:
                return False, 'Unable to get torrent url from first item'

            if url.startswith('magnet:') and re.search(r'urn:btih:([\w]{32,40})', url):
                return True, 'RSS feed Parsed correctly'
            else:
                torrent_file = self.get_url(url, returns='content')
                try:
                    bencode.bdecode(torrent_file)
                except (bencode.BTL.BTFailure, Exception) as error:
                    self.dumpHTML(torrent_file)
                    return False, 'Torrent link is not a valid torrent file: {0}'.format(error)

            return True, 'RSS feed Parsed correctly'

        except Exception as error:
            return False, 'Error when trying to load RSS: {0}'.format(ex(error))
开发者ID:Elettronik,项目名称:SickRage,代码行数:37,代码来源:rsstorrent.py

示例14: _get_rss_data

    def _get_rss_data(self):
        if self.provider.cookies:
            add_dict_to_cookiejar(self.provider.session.cookies, dict(x.rsplit('=', 1) for x in self.provider.cookies.split(';')))

        return self.get_rss_feed(self.provider.url)
开发者ID:Elettronik,项目名称:SickRage,代码行数:5,代码来源:rsstorrent.py


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