本文整理汇总了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))
示例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)
示例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
示例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
示例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
示例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)
示例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://'
示例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)
示例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
示例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
示例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
示例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
示例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
示例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
示例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