Skip to content

Commit

Permalink
Intermediate changes
Browse files Browse the repository at this point in the history
commit_hash:6cd8e5f91ade498715c38402819917994afd2987
  • Loading branch information
robot-piglet committed Feb 10, 2025
1 parent 89d4cd1 commit ec2c9f8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions devtools/ya/yalibrary/fetcher/uri_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class MissingResourceError(Exception):
mute = True


class InvalidMappingError(Exception):
mute = True


class InvalidHttpUriException(Exception):
def __init__(self, reason, uri): # type: (str, str) -> None
msg = 'Wrong uri. {0}: {1}'.format(reason, uri)
Expand Down Expand Up @@ -102,6 +106,13 @@ def parse_resource_uri(resource_uri, force_accepted_schemas=None): # type: (str
raise InvalidUriSchemaException(accepted_schemas, resource_uri)


def resolve_url(url, extensions):
try:
return url.format(**extensions)
except Exception as e:
raise InvalidMappingError("Failed to resolve url '{}' using extensions {}: {!r}".format(url, extensions, e))


def get_mapped_parsed_uri_and_info(parsed_uri, mapping, resource_info):
# type: (ParsedResourceUri, dict, dict) -> tuple[ParsedResourceUri, dict]

Expand All @@ -114,6 +125,7 @@ def get_mapped_parsed_uri_and_info(parsed_uri, mapping, resource_info):
resource_info = mapping["resources_info"][resource_id]

new_url = mapping["resources"][resource_id]
new_url = resolve_url(new_url, mapping.get("extensions", {}))

new_parsed_uri = ParsedResourceUri(
resource_type=parsed_uri.resource_type,
Expand Down

0 comments on commit ec2c9f8

Please sign in to comment.