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


Python furl.furl方法代碼示例

本文整理匯總了Python中furl.furl方法的典型用法代碼示例。如果您正苦於以下問題:Python furl.furl方法的具體用法?Python furl.furl怎麽用?Python furl.furl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在furl的用法示例。


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

示例1: path

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def path(self, path):
        """
        Defines a URL path to match.

        Only call this method if the URL has no path already defined.

        Arguments:
            path (str): URL path value to match. E.g: ``/api/users``.

        Returns:
            self: current Mock instance.
        """
        url = furl(self._request.rawurl)
        url.path = path
        self._request.url = url.url
        self.add_matcher(matcher('PathMatcher', path)) 
開發者ID:h2non,項目名稱:pook,代碼行數:18,代碼來源:mock.py

示例2: test_accept_invite_with_expired_invitation

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def test_accept_invite_with_expired_invitation(self):
        self.client.force_login(self.member)
        response = self.client.post(base_url, {'email': 'please@join.com', 'group': self.group.id})

        # make invitation expire
        i = Invitation.objects.get(id=response.data['id'])
        i.expires_at = timezone.now() - relativedelta(days=1)
        i.save()

        token = furl(re.search(r'(/#/signup.*)\n', mail.outbox[0].body).group(1)).fragment.args['invite']

        # accept the invite
        self.client.force_login(self.non_member)
        response = self.client.post(base_url + token + '/accept/')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(self.group.members.count(), 1) 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:18,代碼來源:test_api.py

示例3: add_auth

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def add_auth(cls, config, url):
        """
        Add username and password to URL if missing from URL and present in config.
        Does not modify ssh URLs.
        """
        try:
            parsed_url = furl(url)
        except ValueError:
            return url
        if parsed_url.scheme in ["", "ssh"] or parsed_url.scheme.startswith("git"):
            return parsed_url.url
        config_user = ENV_AGENT_GIT_USER.get() or config.get("agent.{}_user".format(cls.executable_name), None)
        config_pass = ENV_AGENT_GIT_PASS.get() or config.get("agent.{}_pass".format(cls.executable_name), None)
        if (
            (not (parsed_url.username and parsed_url.password))
            and config_user
            and config_pass
        ):
            parsed_url.set(username=config_user, password=config_pass)
        return parsed_url.url 
開發者ID:allegroai,項目名稱:trains-agent,代碼行數:22,代碼來源:repo.py

示例4: translate

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def translate(self, line):
        """
        If requirement is supported, download it to cache and return the download path
        """
        if not (self.enabled and self.is_supported_link(line)):
            return line
        command = self.config.command
        command.log('Downloading "{}" to pip cache'.format(line))
        url = furl(line)
        try:
            wheel_name = url.path.segments[-1]
        except IndexError:
            command.error('Could not parse wheel name of "{}"'.format(line))
            return line
        try:
            self.download(line)
            downloaded = Path(self.cache_dir, wheel_name).expanduser().as_uri()
        except Exception:
            command.error('Could not download wheel name of "{}"'.format(line))
            return line
        return downloaded 
開發者ID:allegroai,項目名稱:trains-agent,代碼行數:23,代碼來源:translator.py

示例5: remove_user_pass_from_url

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def remove_user_pass_from_url(url):
    # remove user / password, if we have it embedded in the git repo
    url = str(url)
    # noinspection PyBroadException
    try:
        url = furl(url).remove(username=True, password=True).tostr()
    except ValueError:
        # check if for any reason we have two @
        # (e.g. ssh://user@abc.com@domain.com/path or ssh://user@abc.com:pass@domain.com/path)
        if len(url.split('@')) >= 3:
            # noinspection PyBroadException
            try:
                url = furl(url.replace('@', '_', 1)).remove(username=True, password=True).tostr()
            except Exception:
                pass
    except Exception:
        pass
    return url 
開發者ID:allegroai,項目名稱:trains,代碼行數:20,代碼來源:util.py

示例6: _get_prefix_from_bucket_config

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def _get_prefix_from_bucket_config(self, config):
        scheme = "s3"
        prefix = furl.furl()

        if config.host:
            prefix.set(
                scheme=scheme,
                netloc=config.host.lower(),
                path=config.bucket.lower() if config.bucket else "",
            )
        else:
            prefix.set(scheme=scheme, path=config.bucket.lower())
            bucket = prefix.path.segments[0]
            prefix.path.segments.pop(0)
            prefix.set(netloc=bucket)

        return str(prefix) 
開發者ID:allegroai,項目名稱:trains,代碼行數:19,代碼來源:bucket_config.py

示例7: _resolve_base_url

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def _resolve_base_url(cls, base_url):
        parsed = urlparse(base_url)
        if parsed.scheme == _Boto3Driver.scheme:
            conf = cls._s3_configurations.get_config_by_uri(base_url)
            bucket = conf.bucket
            if not bucket:
                parts = Path(parsed.path.strip('/')).parts
                if parts:
                    bucket = parts[0]
            return '/'.join(x for x in ('s3:/', conf.host, bucket) if x)
        elif parsed.scheme == _AzureBlobServiceStorageDriver.scheme:
            conf = cls._azure_configurations.get_config_by_uri(base_url)
            if not conf:
                raise StorageError("Can't find azure configuration for {}".format(base_url))
            return str(furl(base_url).set(path=conf.container_name))
        elif parsed.scheme == _GoogleCloudStorageDriver.scheme:
            conf = cls._gs_configurations.get_config_by_uri(base_url)
            return str(furl(scheme=parsed.scheme, netloc=conf.bucket))
        elif parsed.scheme == 'http':
            return 'http://'
        elif parsed.scheme == 'https':
            return 'https://'
        else:  # if parsed.scheme == 'file':
            # if we do not know what it is, we assume file
            return 'file://' 
開發者ID:allegroai,項目名稱:trains,代碼行數:27,代碼來源:helper.py

示例8: test_upload

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def test_upload(self, test_path, config, **_):
        bucket_url = str(furl(scheme=self.scheme, netloc=config.bucket, path=config.subdir))
        bucket = self.get_container(container_name=bucket_url, config=config).bucket

        test_obj = bucket

        if test_path:
            if not test_path.endswith('/'):
                test_path += '/'

            blob = bucket.blob(test_path)

            if blob.exists():
                test_obj = blob

        permissions_to_test = ('storage.objects.get', 'storage.objects.update')
        return set(test_obj.test_iam_permissions(permissions_to_test)) == set(permissions_to_test) 
開發者ID:allegroai,項目名稱:trains,代碼行數:19,代碼來源:helper.py

示例9: get_authorize_url

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def get_authorize_url(self, redirect_uri, state='', lang='zh'):
        """
        獲取授權地址

        詳情請參考
        http://docs.teambition.com/wiki/oauth2#oauth2-authorize

        :param redirect_uri: 授權回調地址
        :param state: 原樣返回給客戶端
        :param lang: 語言類型,可選 zh, en,默認為 zh
        :return: 授權地址
        """
        oauth2_url = furl('https://account.teambition.com/oauth2/authorize')
        oauth2_url.add(args={
            'client_id': self.client_id,
            'redirect_uri': redirect_uri,
            'state': state,
            'lang': lang
        })
        return oauth2_url.url 
開發者ID:jxtech,項目名稱:teambition-api,代碼行數:22,代碼來源:oauth.py

示例10: test_web_loader_loads_data

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def test_web_loader_loads_data(self):
        with open(
            f'{self.data_directory}/schedule/stats_{self.league}_{self.date.replace("/", "_")}.json'
        ) as f:
            scoreboard_response = json.loads(f.read())
        base_url = f"https://stats.gleague.nba.com/stats/scoreboardV2"
        query_params = {"DayOffset": 0, "LeagueID": "20", "gameDate": self.date}
        scoreboard_url = furl(base_url).add(query_params).url
        responses.add(
            responses.GET, scoreboard_url, json=scoreboard_response, status=200
        )

        scoreboard_loader = StatsNbaScoreboardLoader(
            self.date, self.league, self.data_directory, "web"
        )
        assert len(scoreboard_loader.items) == 7
        assert isinstance(scoreboard_loader.items[0], StatsNbaGameItem)
        assert scoreboard_loader.items[0].data == self.expected_first_item_data 
開發者ID:dblackrun,項目名稱:pbpstats,代碼行數:20,代碼來源:test_stats_scoreboard_loader.py

示例11: test_web_loader_loads_data

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def test_web_loader_loads_data(self):
        with open(f"{self.data_directory}/pbp/stats_{self.game_id}.json") as f:
            pbp_response = json.loads(f.read())
        base_url = "https://stats.nba.com/stats/playbyplayv2"
        query_params = {
            "GameId": self.game_id,
            "StartPeriod": 0,
            "EndPeriod": 10,
            "RangeType": 2,
            "StartRange": 0,
            "EndRange": 55800,
        }
        pbp_url = furl(base_url).add(query_params).url
        responses.add(responses.GET, pbp_url, json=pbp_response, status=200)

        pbp_loader = StatsNbaPbpLoader(self.game_id, "web", self.data_directory)
        assert len(pbp_loader.items) == 540
        assert isinstance(pbp_loader.items[0], StatsNbaPbpItem)
        assert pbp_loader.items[0].data == self.expected_first_item_data 
開發者ID:dblackrun,項目名稱:pbpstats,代碼行數:21,代碼來源:test_stats_pbp_loader.py

示例12: test_web_loader_loads_data

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def test_web_loader_loads_data(self):
        with open(
            f'{self.data_directory}/schedule/stats_{self.league}_{self.season.replace("-", "_")}_{self.season_type.replace(" ", "_")}.json'
        ) as f:
            scoreboard_response = json.loads(f.read())
        base_url = f"https://stats.nba.com/stats/leaguegamefinder"
        query_params = {
            "PlayerOrTeam": "T",
            "gtPTS": 1,
            "Season": self.season,
            "SeasonType": self.season_type,
            "LeagueID": "00",
        }
        scoreboard_url = furl(base_url).add(query_params).url
        responses.add(
            responses.GET, scoreboard_url, json=scoreboard_response, status=200
        )

        scoreboard_loader = StatsNbaGameFinderLoader(
            self.league, self.season, self.season_type, "web", self.data_directory
        )
        assert len(scoreboard_loader.items) == 1230
        assert isinstance(scoreboard_loader.items[0], StatsNbaGameItem)
        assert scoreboard_loader.items[0].data == self.expected_first_item_data 
開發者ID:dblackrun,項目名稱:pbpstats,代碼行數:26,代碼來源:test_stats_game_finder_loader.py

示例13: test_web_loader_loads_data

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def test_web_loader_loads_data(self):
        with open(
            f"{self.data_directory}/game_details/stats_boxscore_{self.game_id}.json"
        ) as f:
            boxscore_response = json.loads(f.read())
        boxscore_base_url = "https://stats.nba.com/stats/boxscoretraditionalv2"
        boxscore_query_params = {
            "EndPeriod": 10,
            "EndRange": 55800,
            "GameId": self.game_id,
            "RangeType": 2,
            "StartPeriod": 0,
            "StartRange": 0,
        }
        boxscore_url = furl(boxscore_base_url).add(boxscore_query_params).url
        responses.add(responses.GET, boxscore_url, json=boxscore_response, status=200)

        boxscore_loader = StatsNbaBoxscoreLoader(
            self.game_id, "web", self.data_directory
        )
        assert len(boxscore_loader.items) == 21
        assert isinstance(boxscore_loader.items[0], StatsNbaBoxscoreItem)
        assert boxscore_loader.items[0].data == self.expected_first_item_data 
開發者ID:dblackrun,項目名稱:pbpstats,代碼行數:25,代碼來源:test_stats_boxscore_loader.py

示例14: _make_base_url

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def _make_base_url(self, uuid: UUID = None) -> furl:
        """
        _makeBaseURL - generates the common base URL for all of our requests
        :param uuid: a UUID we want to attach to the
        :return: the furl wrapper around our unfinished base url
        """
        base = furl()  # Create an uninitialized base URI object
        base.host = self.host  # set the host name
        base.port = self.port  # set the port number
        base.scheme = self.scheme  # set the access scheme

        # if we have no uuid to attach to this request, generate one
        if uuid is None:
            uuid = uuid4()

        # Set the request id parameter uuid
        base.args[REQUEST_ID_PARAMETER] = str(uuid)

        return base 
開發者ID:snowflakedb,項目名稱:snowflake-ingest-python,代碼行數:21,代碼來源:uris.py

示例15: parse_url

# 需要導入模塊: import furl [as 別名]
# 或者: from furl import furl [as 別名]
def parse_url(url):
    """Parses a url into the base url and the query params

    Args:
        url (str): url with query string, or not

    Returns:
        (str, `dict` of `lists`): url, query (dict of values)
    """
    f = furl(url)
    query = f.args
    query = {a[0]: a[1] for a in query.listitems()}
    f.remove(query=True).path.normalize()
    url = f.url

    return url, query 
開發者ID:opensciencegrid,項目名稱:cvmfs-singularity-sync,代碼行數:18,代碼來源:dockerhub.py


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