Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly match protocol #118

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions xbrl/helper/uri_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def resolve_uri(dir_uri: str, relative_uri: str) -> str:
@param relative_uri:
@return:
"""
if relative_uri.startswith('http'):
if relative_uri.startswith('http://') or relative_uri.startswith('https://'):
return relative_uri

# remove redundant characters in the relative uri
if relative_uri.startswith('/'): relative_uri = relative_uri[1:]
if relative_uri.startswith('./'): relative_uri = relative_uri[2:]

dir_uri = str(dir_uri)
if not dir_uri.startswith('http'):
if not dir_uri.startswith('http://') and not dir_uri.startswith('https://'):
# check if the dir_uri was really a path to a directory or a file
if '.' in dir_uri.split(os.sep)[-1]:
return os.path.normpath(os.path.dirname(dir_uri) + os.sep + relative_uri)
Expand All @@ -40,7 +40,7 @@ def resolve_uri(dir_uri: str, relative_uri: str) -> str:
dir_uri += '/'

absolute_uri = dir_uri + relative_uri
if not dir_uri.startswith('http'):
if not dir_uri.startswith('http://') and not dir_uri.startswith('https://'):
# make sure the path is correct
absolute_uri = os.path.normpath(absolute_uri)

Expand Down
6 changes: 3 additions & 3 deletions xbrl/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def parse_xbrl(instance_path: str, cache: HttpCache, instance_url: str or None =
schema_uri: str = schema_ref.attrib[XLINK_NS + 'href']
# check if the schema uri is relative or absolute
# submissions from SEC normally have their own schema files, whereas submissions from the uk have absolute schemas
if schema_uri.startswith('http'):
if schema_uri.startswith('http://') or schema_uri.startswith("https://"):
# fetch the taxonomy extension schema from remote
taxonomy: TaxonomySchema = parse_taxonomy_url(schema_uri, cache)
elif instance_url:
Expand Down Expand Up @@ -727,9 +727,9 @@ def parse_instance(self, uri: str, instance_url: str or None = None, encoding: s
:return:
"""
if uri.split('.')[-1] == 'xml' or uri.split('.')[-1] == 'xbrl':
return parse_xbrl_url(uri, self.cache) if uri.startswith('http') \
return parse_xbrl_url(uri, self.cache) if uri.startswith('http://') or uri.startswith('https://') \
else parse_xbrl(uri, self.cache, instance_url)
return parse_ixbrl_url(uri, self.cache) if uri.startswith('http') \
return parse_ixbrl_url(uri, self.cache) if uri.startswith('http://') or uri.startswith('https://') \
else parse_ixbrl(uri, self.cache, instance_url, encoding)

def __str__(self) -> str:
Expand Down
8 changes: 4 additions & 4 deletions xbrl/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def parse_taxonomy_url(schema_url: str, cache: HttpCache) -> TaxonomySchema:
:param cache: :class:`xbrl.cache.HttpCache` instance
:return: parsed :class:`xbrl.taxonomy.TaxonomySchema` object
"""
if not schema_url.startswith('http'): raise XbrlParseException(
if not schema_url.startswith('http://') and not schema_url.startswith('https://'): raise XbrlParseException(
'This function only parses remotely saved taxonomies. Please use parse_taxonomy to parse local taxonomy schemas')

schema_path: str = cache.cache_file(schema_url)
Expand All @@ -611,7 +611,7 @@ def parse_taxonomy(schema_path: str, cache: HttpCache, schema_url: str or None =
:return: parsed :class:`xbrl.taxonomy.TaxonomySchema` object
"""
schema_path = str(schema_path)
if schema_path.startswith('http'): raise XbrlParseException(
if schema_path.startswith('http://') or schema_path.startswith('https://'): raise XbrlParseException(
'This function only parses locally saved taxonomies. Please use parse_taxonomy_url to parse remote taxonomy schemas')
if not os.path.exists(schema_path):
raise TaxonomyNotFound(f"Could not find taxonomy schema at {schema_path}")
Expand All @@ -632,7 +632,7 @@ def parse_taxonomy(schema_path: str, cache: HttpCache, schema_url: str or None =
continue

# sometimes the import schema location is relative. i.e schemaLocation="xbrl-linkbase-2003-12-31.xsd"
if import_uri.startswith('http'):
if import_uri.startswith('http://') or import_uri.startswith('https://'):
# fetch the schema file from remote
taxonomy.imports.append(parse_taxonomy_url(import_uri, cache))
elif schema_url:
Expand Down Expand Up @@ -683,7 +683,7 @@ def parse_taxonomy(schema_path: str, cache: HttpCache, schema_url: str or None =
linkbase_uri)

# check if the linkbase url is relative
if linkbase_uri.startswith('http'):
if linkbase_uri.startswith('http://') or linkbase_uri.startswith('https://'):
# fetch the linkbase from remote
linkbase: Linkbase = parse_linkbase_url(linkbase_uri, linkbase_type, cache)
elif schema_url:
Expand Down
Loading