@@ -286,11 +286,12 @@ def __str__(self) -> str:
286
286
file_name : str = self .instance_url .split ('/' )[- 1 ]
287
287
return "{} with {} facts" .format (file_name , len (self .facts ))
288
288
289
- def json (self , file_path : str = None , override_fact_ids : bool = True ) -> str or None :
289
+ def json (self , file_path : str = None , override_fact_ids : bool = True , ** kwargs ) -> str or None :
290
290
"""
291
291
Converts the instance document into json format
292
292
:param file_path: if a path is given the function will store the json there
293
293
:param override_fact_ids:
294
+ :param kwargs: additional arguments for the json parser
294
295
:return: string (serialized json) or None (if file_path was given)
295
296
296
297
https://www.xbrl.org/Specification/xbrl-json/REC-2021-10-13/xbrl-json-REC-2021-10-13.html
@@ -308,9 +309,9 @@ def json(self, file_path: str = None, override_fact_ids: bool = True) -> str or
308
309
json_dict ['facts' ][fact_id ] = fact .json ()
309
310
if file_path :
310
311
with open (file_path , 'w' , encoding = 'utf8' ) as f :
311
- return json .dump (json_dict , f )
312
+ return json .dump (json_dict , f , ** kwargs )
312
313
else :
313
- return json .dumps (json_dict )
314
+ return json .dumps (json_dict , ** kwargs )
314
315
315
316
316
317
def parse_xbrl_url (instance_url : str , cache : HttpCache ) -> XbrlInstance :
@@ -409,16 +410,17 @@ def parse_xbrl(instance_path: str, cache: HttpCache, instance_url: str or None =
409
410
return XbrlInstance (instance_url if instance_url else instance_path , taxonomy , facts , context_dir , unit_dir )
410
411
411
412
412
- def parse_ixbrl_url (instance_url : str , cache : HttpCache ) -> XbrlInstance :
413
+ def parse_ixbrl_url (instance_url : str , cache : HttpCache , encoding : str or None = None ) -> XbrlInstance :
413
414
"""
414
415
Parses a inline XBRL (iXBRL) instance file.
415
416
416
417
:param cache: HttpCache instance
417
418
:param instance_url: url to the instance file(on the internet)
419
+ :param encoding: specifies the encoding of the file
418
420
:return: parsed XbrlInstance object containing all facts with additional information
419
421
"""
420
422
instance_path : str = cache .cache_file (instance_url )
421
- return parse_ixbrl (instance_path , cache , instance_url )
423
+ return parse_ixbrl (instance_path , cache , instance_url , encoding )
422
424
423
425
424
426
def parse_ixbrl (instance_path : str , cache : HttpCache , instance_url : str or None = None , encoding = None , schema_root = None ) -> XbrlInstance :
@@ -708,7 +710,7 @@ class XbrlParser:
708
710
def __init__ (self , cache : HttpCache ):
709
711
self .cache = cache
710
712
711
- def parse_instance (self , uri : str , instance_url : str or None = None ) -> XbrlInstance :
713
+ def parse_instance (self , uri : str , instance_url : str or None = None , encoding : str or None = None ) -> XbrlInstance :
712
714
"""
713
715
Parses a xbrl instance (either xbrl or ixbrl)
714
716
@@ -721,11 +723,14 @@ def parse_instance(self, uri: str, instance_url: str or None = None) -> XbrlInst
721
723
i.e: https://www.sec.gov/Archives/edgar/data/320193/000032019320000096/aapl-20200926.
722
724
:param instance_url: this parameter overrides the above described behaviour. If you also provide the url where the
723
725
instance document was downloaded, the parser can fetch relative imports using this base url
726
+ :param encoding: specifies the encoding of the file
724
727
:return:
725
728
"""
726
729
if uri .split ('.' )[- 1 ] == 'xml' or uri .split ('.' )[- 1 ] == 'xbrl' :
727
- return parse_xbrl_url (uri , self .cache ) if uri .startswith ('http' ) else parse_xbrl (uri , self .cache , instance_url )
728
- return parse_ixbrl_url (uri , self .cache ) if uri .startswith ('http' ) else parse_ixbrl (uri , self .cache , instance_url )
730
+ return parse_xbrl_url (uri , self .cache ) if uri .startswith ('http' ) \
731
+ else parse_xbrl (uri , self .cache , instance_url )
732
+ return parse_ixbrl_url (uri , self .cache ) if uri .startswith ('http' ) \
733
+ else parse_ixbrl (uri , self .cache , instance_url , encoding )
729
734
730
735
def __str__ (self ) -> str :
731
736
return 'XbrlParser with cache dir at {}' .format (self .cache .cache_dir )
0 commit comments