30
30
from urllib .request import urlopen , pathname2url
31
31
_urlopen = urlopen
32
32
from urllib .parse import urlparse as parse_url
33
- import urllib .parse as compat_parse
34
33
from urllib .parse import (uses_relative , uses_netloc , uses_params ,
35
34
urlencode , urljoin )
36
35
from urllib .error import URLError
37
- from http .client import HTTPException
36
+ from http .client import HTTPException # noqa
38
37
else :
39
38
from urllib2 import urlopen as _urlopen
40
- from urllib import urlencode , pathname2url
39
+ from urllib import urlencode , pathname2url # noqa
41
40
from urlparse import urlparse as parse_url
42
41
from urlparse import uses_relative , uses_netloc , uses_params , urljoin
43
- from urllib2 import URLError
44
- from httplib import HTTPException
45
- from contextlib import contextmanager , closing
46
- from functools import wraps
42
+ from urllib2 import URLError # noqa
43
+ from httplib import HTTPException # noqa
44
+ from contextlib import contextmanager , closing # noqa
45
+ from functools import wraps # noqa
47
46
48
47
# @wraps(_urlopen)
49
48
@contextmanager
@@ -66,6 +65,7 @@ class DtypeWarning(Warning):
66
65
67
66
try :
68
67
from boto .s3 import key
68
+
69
69
class BotoFileLikeReader (key .Key ):
70
70
"""boto Key modified to be more file-like
71
71
@@ -78,10 +78,12 @@ class BotoFileLikeReader(key.Key):
78
78
Also adds a `readline` function which will split the returned
79
79
values by the `\n ` character.
80
80
"""
81
+
81
82
def __init__ (self , * args , ** kwargs ):
82
83
encoding = kwargs .pop ("encoding" , None ) # Python 2 compat
83
84
super (BotoFileLikeReader , self ).__init__ (* args , ** kwargs )
84
- self .finished_read = False # Add a flag to mark the end of the read.
85
+ # Add a flag to mark the end of the read.
86
+ self .finished_read = False
85
87
self .buffer = ""
86
88
self .lines = []
87
89
if encoding is None and compat .PY3 :
@@ -121,7 +123,8 @@ def readline(self):
121
123
raise StopIteration
122
124
123
125
if self .encoding :
124
- self .buffer = "{}{}" .format (self .buffer , self .read (8192 ).decode (self .encoding ))
126
+ self .buffer = "{}{}" .format (
127
+ self .buffer , self .read (8192 ).decode (self .encoding ))
125
128
else :
126
129
self .buffer = "{}{}" .format (self .buffer , self .read (8192 ))
127
130
@@ -211,13 +214,15 @@ def _expand_user(filepath_or_buffer):
211
214
return os .path .expanduser (filepath_or_buffer )
212
215
return filepath_or_buffer
213
216
217
+
214
218
def _validate_header_arg (header ):
215
219
if isinstance (header , bool ):
216
220
raise TypeError ("Passing a bool to header is invalid. "
217
221
"Use header=None for no header or "
218
222
"header=int or list-like of ints to specify "
219
223
"the row(s) making up the column names" )
220
224
225
+
221
226
def _stringify_path (filepath_or_buffer ):
222
227
"""Return the argument coerced to a string if it was a pathlib.Path
223
228
or a py.path.local
@@ -263,8 +268,9 @@ def get_filepath_or_buffer(filepath_or_buffer, encoding=None,
263
268
else :
264
269
compression = None
265
270
# cat on the compression to the tuple returned by the function
266
- to_return = list (maybe_read_encoded_stream (req , encoding , compression )) + \
267
- [compression ]
271
+ to_return = (list (maybe_read_encoded_stream (req , encoding ,
272
+ compression )) +
273
+ [compression ])
268
274
return tuple (to_return )
269
275
270
276
if _is_s3_url (filepath_or_buffer ):
@@ -467,4 +473,4 @@ def _check_as_is(x):
467
473
# write to the target stream
468
474
self .stream .write (data )
469
475
# empty queue
470
- self .queue .truncate (0 )
476
+ self .queue .truncate (0 )
0 commit comments