@@ -22,7 +22,7 @@ def decode(s, format, **kwargs):
2222 options = kwargs .copy ()
2323 if format in ["b64" , "base64" ]:
2424 options .setdefault ("subformat" , "json" )
25- content = read_content (s , format , ** options )
25+ content = read_content (s , format , options )
2626 data = serializer .decode (content , ** options )
2727 return data
2828
@@ -76,43 +76,45 @@ def parse_s3_url(url):
7676 }
7777
7878
79- def read_content (s , format = None , ** options ):
79+ def read_content (s , format = None , options = None ):
8080 # s -> filepath or url or data
81- options .setdefault ("format" , format )
81+ # options.setdefault("format", format)
82+ options = options or {}
8283 s = s .strip ()
8384 if is_data (s ):
8485 return s
8586 elif is_url (s ):
86- return read_content_from_url (s , ** options )
87+ requests_options = options .pop ("requests_options" , None ) or {}
88+ return read_content_from_url (s , requests_options , format )
8789 elif is_s3 (s ):
88- return read_content_from_s3 (s , ** options )
90+ s3_options = options .pop ("s3_options" , None ) or {}
91+ return read_content_from_s3 (s , s3_options , format )
8992 elif is_filepath (s ):
90- return read_content_from_file (s , ** options )
93+ return read_content_from_file (s , format )
9194 # one-line data?!
9295 return s
9396
9497
95- def read_content_from_file (filepath , format = None , ** options ):
98+ def read_content_from_file (filepath , format = None ):
9699 binary_format = is_binary_format (format )
97100 if binary_format :
98101 return filepath
99102 return fsutil .read_file (filepath )
100103
101104
102- def read_content_from_s3 (url , s3_options , format = None , ** options ):
105+ def read_content_from_s3 (url , s3_options , format = None ):
103106 s3_url = parse_s3_url (url )
104107 dirpath = tempfile .gettempdir ()
105108 filename = fsutil .get_filename (s3_url ["key" ])
106109 filepath = fsutil .join_path (dirpath , filename )
107110 s3 = boto3 .client ("s3" , ** s3_options )
108111 s3 .download_file (s3_url ["bucket" ], s3_url ["key" ], filepath )
109112 s3 .close ()
110- content = read_content_from_file (filepath , format , ** options )
113+ content = read_content_from_file (filepath , format )
111114 return content
112115
113116
114- def read_content_from_url (url , requests_options = None , format = None , ** options ):
115- requests_options = requests_options or {}
117+ def read_content_from_url (url , requests_options , format = None ):
116118 binary_format = is_binary_format (format )
117119 if binary_format :
118120 dirpath = tempfile .gettempdir ()
0 commit comments