File tree Expand file tree Collapse file tree 4 files changed +10
-10
lines changed Expand file tree Collapse file tree 4 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -62,20 +62,22 @@ def _handle_gzip(file_obj, mode):
62
62
return gzip .GzipFile (fileobj = file_obj , mode = mode )
63
63
64
64
65
- def compression_wrapper (file_obj , mode ):
65
+ def compression_wrapper (file_obj , mode , filename = None ):
66
66
"""
67
67
This function will wrap the file_obj with an appropriate
68
68
[de]compression mechanism based on the extension of the filename.
69
69
70
70
file_obj must either be a filehandle object, or a class which behaves
71
- like one. It must have a .name attribute.
71
+ like one. It must have a .name attribute unless ``filename`` is given .
72
72
73
73
If the filename extension isn't recognized, will simply return the original
74
74
file_obj.
75
- """
76
75
76
+ """
77
77
try :
78
- _ , ext = os .path .splitext (file_obj .name )
78
+ if filename is None :
79
+ filename = file_obj .name
80
+ _ , ext = os .path .splitext (filename )
79
81
except (AttributeError , TypeError ):
80
82
logger .warning (
81
83
'unable to transparently decompress %r because it '
Original file line number Diff line number Diff line change @@ -163,7 +163,7 @@ def extract_examples_from_readme_rst(indent=' '):
163
163
start = lines .index ('.. _doctools_before_examples:\n ' )
164
164
end = lines .index (".. _doctools_after_examples:\n " )
165
165
lines = lines [start + 4 :end - 2 ]
166
- return '' .join ([indent + re .sub ('^ ' , '' , l ) for l in lines ])
166
+ return '' .join ([indent + re .sub ('^ ' , '' , line ) for line in lines ])
167
167
except Exception :
168
168
return indent + 'See README.rst'
169
169
Original file line number Diff line number Diff line change @@ -721,7 +721,7 @@ def test_readline_iter(self):
721
721
722
722
reader = smart_open .smart_open ("s3://mybucket/mykey" , "rb" )
723
723
724
- actual_lines = [l .decode ("utf-8" ) for l in reader ]
724
+ actual_lines = [line .decode ("utf-8" ) for line in reader ]
725
725
self .assertEqual (2 , len (actual_lines ))
726
726
self .assertEqual (lines [0 ], actual_lines [0 ])
727
727
self .assertEqual (lines [1 ], actual_lines [1 ])
@@ -1273,9 +1273,7 @@ def write_callback(request):
1273
1273
1274
1274
1275
1275
class CompressionFormatTest (unittest .TestCase ):
1276
- """
1277
- Test that compression
1278
- """
1276
+ """Test transparent (de)compression."""
1279
1277
1280
1278
def write_read_assertion (self , suffix ):
1281
1279
test_file = make_buffer (name = 'file' + suffix )
Original file line number Diff line number Diff line change @@ -218,7 +218,7 @@ def test_readline_iter(self):
218
218
219
219
reader = smart_open .smart_open ("s3://mybucket/mykey" , "rb" )
220
220
221
- actual_lines = [l .decode ("utf-8" ) for l in reader ]
221
+ actual_lines = [line .decode ("utf-8" ) for line in reader ]
222
222
self .assertEqual (2 , len (actual_lines ))
223
223
self .assertEqual (lines [0 ], actual_lines [0 ])
224
224
self .assertEqual (lines [1 ], actual_lines [1 ])
You can’t perform that action at this time.
0 commit comments