Python furl.furl() Examples
The following are 30
code examples of furl.furl().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
furl
, or try the search function
.
Example #1
Source File: util.py From trains with Apache License 2.0 | 6 votes |
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
Example #2
Source File: test_stats_game_finder_loader.py From pbpstats with MIT License | 6 votes |
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
Example #3
Source File: uris.py From snowflake-ingest-python with Apache License 2.0 | 6 votes |
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
Example #4
Source File: mock.py From pook with MIT License | 6 votes |
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))
Example #5
Source File: test_stats_boxscore_loader.py From pbpstats with MIT License | 6 votes |
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
Example #6
Source File: test_api.py From karrot-backend with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #7
Source File: dockerhub.py From cvmfs-singularity-sync with Apache License 2.0 | 6 votes |
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
Example #8
Source File: test_stats_pbp_loader.py From pbpstats with MIT License | 6 votes |
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
Example #9
Source File: test_stats_scoreboard_loader.py From pbpstats with MIT License | 6 votes |
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
Example #10
Source File: oauth.py From teambition-api with MIT License | 6 votes |
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
Example #11
Source File: repo.py From trains-agent with Apache License 2.0 | 6 votes |
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
Example #12
Source File: translator.py From trains-agent with Apache License 2.0 | 6 votes |
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
Example #13
Source File: helper.py From trains with Apache License 2.0 | 6 votes |
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)
Example #14
Source File: helper.py From trains with Apache License 2.0 | 6 votes |
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://'
Example #15
Source File: bucket_config.py From trains with Apache License 2.0 | 6 votes |
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)
Example #16
Source File: plugin.py From robotframework-seleniumtestability with Apache License 2.0 | 5 votes |
def add_authentication(url: str, user: str, password: str) -> str: """ For websites that require basic auth authentication, add user and password into the given url. Parameters: - ``url`` - url where user and password should be added to. - ``user`` - username - ``password`` - password """ data = furl(url) data.username = user data.password = password return data.tostr()
Example #17
Source File: plugin.py From robotframework-seleniumtestability with Apache License 2.0 | 5 votes |
def split_url_to_host_and_path(url: str) -> dict: """ Returs given url as dict with property "base" set to a protocol and hostname and "path" as the trailing path. This is useful when constructing requests sessions from urls used within SeleniumLibrary. """ data = furl(url) return {"base": str(data.copy().remove(path=True)), "path": str(data.path)}
Example #18
Source File: __init__.py From py-cfenv with MIT License | 5 votes |
def get_url(self, url='url', **keys): parsed = furl.furl(self.credentials.get(url, '')) for key, value in keys.items(): setattr(parsed, key, self.credentials.get(value)) return parsed.url
Example #19
Source File: test_stats_summary_loader.py From pbpstats with MIT License | 5 votes |
def test_web_loader_loads_data(self): with open( f"{self.data_directory}/game_details/stats_summary_{self.game_id}.json" ) as f: summary_response = json.loads(f.read()) base_url = "https://stats.nba.com/stats/boxscoresummaryv2" query_params = {"GameId": self.game_id} summary_url = furl(base_url).add(query_params).url responses.add(responses.GET, summary_url, json=summary_response, status=200) summary_loader = StatsNbaSummaryLoader(self.game_id, "web", self.data_directory) assert len(summary_loader.items) == 1 assert isinstance(summary_loader.items[0], StatsNbaGameItem) assert summary_loader.items[0].data == self.expected_first_item_data
Example #20
Source File: admin.py From silver with Apache License 2.0 | 5 votes |
def transactions(self, obj): if obj.transaction_xe_rate: url_base = 'admin:silver_transaction_changelist' url = furl(reverse(url_base)) url.add(args={obj.__class__.__name__.lower() + "__id__exact": obj.pk}) return '<a href="{url}" target="_blank">{total:.2f} {currency}</a>'.format( url=url.url, total=obj.total_in_transaction_currency, currency=obj.transaction_currency ) return None
Example #21
Source File: bucket_config.py From trains with Apache License 2.0 | 5 votes |
def _get_prefix_from_bucket_config(self, config): prefix = furl.furl(scheme="gs", netloc=config.bucket, path=config.subdir) return str(prefix)
Example #22
Source File: utils.py From django-functest with BSD 3-Clause "New" or "Revised" License | 5 votes |
def assertUrlsEqual(self, url, other_url=None): """ Asserts that the URLs match. Empty protocol or domain are ignored. """ if other_url is None: other_url = self.current_url url1 = furl(url) url2 = furl(other_url) self.assertEqual(url1.path, url2.path) self.assertEqual(url1.query, url2.query) if url1.netloc and url2.netloc: self.assertEqual(url1.netloc, url2.netloc) if url1.scheme and url2.scheme: self.assertEqual(url1.scheme, url2.scheme)
Example #23
Source File: bucket_config.py From trains with Apache License 2.0 | 5 votes |
def get_config_by_uri(self, uri): """ Get the credentials for a Google Storage bucket from the config :param uri: URI of bucket, directory or file :return: GSBucketConfig: bucket config """ res = ( config for config, prefix in self._prefixes if prefix is not None and uri.lower().startswith(prefix) ) try: return next(res) except StopIteration: pass parsed = furl.furl(uri) return GSBucketConfig( bucket=parsed.netloc, subdir=str(parsed.path), project=self._default_project, credentials_json=self._default_credentials, )
Example #24
Source File: test_endpoints_url.py From pubg-python with MIT License | 5 votes |
def test_seasons(): url = furl(BASE_URL).join('shards/steam/seasons').url assert api.seasons().endpoint.url == url
Example #25
Source File: mq.py From SpoofcheckSelfTest with Apache License 2.0 | 5 votes |
def create_mq_url(hostname, port, username=None, password=None): """ Creates a well formed amqp:// connection URI """ mq_url = furl() mq_url.scheme = "amqp" mq_url.host = hostname mq_url.port = port mq_url.username = username mq_url.password = password return str(mq_url)
Example #26
Source File: test_leaderboards.py From pubg-python with MIT License | 5 votes |
def test_leaderboard(mock, leaderboard_response): game_mode = 'squad-fpp' page_number = 0 url = furl(BASE_URL).join(ENDPOINT_PATH + '/' + game_mode).add( {'page[number]': page_number}).url mock.get(url, json=leaderboard_response) data = api.leaderboards(game_mode=game_mode).page(page_number).get() assert isinstance(data, Leaderboard) assert data.shard_id in Shard._value2member_map_ assert data.game_mode in GAME_MODE
Example #27
Source File: test_weapon_mastery.py From pubg-python with MIT License | 5 votes |
def test_match_get(mock, weapon_mastery_response): player_id = 'account.d1c920088e124f2393455e05c11a8775' url = furl(BASE_URL).join(ENDPOINT_PATH.format(player_id)).url mock.get(url, json=weapon_mastery_response) wm = api.weapon_mastery(player_id=player_id).get() assert isinstance(wm, Weaponmasterysummary) assert isinstance(wm.platform, str) assert isinstance(wm.weapon_summaries, dict) assert isinstance(wm.latest_match_id, str)
Example #28
Source File: test_samples.py From pubg-python with MIT License | 5 votes |
def test_match_get(mock, samples_response): match_id = '3095f3be-a327-491c-be17-6e4823821b2e' url = furl(BASE_URL).join(ENDPOINT_PATH).url mock.get(url, json=samples_response) sample = api.samples().get() match = sample.matches[0] assert isinstance(sample, Sample) assert isinstance(match, Match) assert match.id == match_id
Example #29
Source File: test_endpoints_url.py From pubg-python with MIT License | 5 votes |
def test_seasons_with_player_id(): season = api.seasons(season_id='season_id', player_id='player_id') endpoint = season.endpoint url = furl(BASE_URL).join( 'shards/steam/players/player_id/seasons/season_id').url assert endpoint.url == url
Example #30
Source File: crawl.py From Gerapy with MIT License | 5 votes |
def _generate_request(self, index, rule, link, response): """ generate request by rule :param index: rule index :param rule: rule object :param link: link object :return: new request object """ url = furl(link.url).add(rule.params).url if rule.params else link.url # init request body body = None # process by method if rule.method.upper() == 'POST': # if process_body defined, use its result if callable(rule.process_body): body = rule.process_body(response) # if data defined in rule, use data if rule.data: body = rule.data r = Request(url=url, method=rule.method, body=body, headers=rule.headers, priority=rule.priority, dont_filter=rule.dont_filter, callback=self._response_downloaded) # update meta args r.meta.update(**rule.meta) meta_items = ['dont_redirect', 'dont_retry', 'handle_httpstatus_list', 'handle_httpstatus_all', 'dont_cache', 'dont_obey_robotstxt', 'download_timeout', 'max_retry_times', 'proxy', 'render'] meta_args = {meta_item: getattr(rule, meta_item) for meta_item in meta_items if not getattr(rule, meta_item) is None} # update extra meta args r.meta.update(**meta_args) return r