File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55except ImportError :
66 from collections import Iterable
77
8+ try :
9+ # Python 3.4+
10+ from pathlib import PurePath
11+ except ImportError :
12+ PurePath = None
13+
814
915class FitParseError (ValueError ):
1016 pass
@@ -56,9 +62,13 @@ def fileish_open(fileish, mode):
5662 return open (fileish , mode )
5763 except TypeError :
5864 return io .BytesIO (fileish )
59- else :
60- # Python 3 - file contents
61- return io .BytesIO (fileish )
65+
66+ # Python 3 - pathlib obj
67+ if PurePath and isinstance (fileish , PurePath ):
68+ return fileish .open (mode )
69+
70+ # Python 3 - file contents
71+ return io .BytesIO (fileish )
6272
6373
6474def is_iterable (obj ):
Original file line number Diff line number Diff line change 55import sys
66import tempfile
77
8+ try :
9+ # Python 3.4+
10+ from pathlib import Path
11+ except ImportError :
12+ Path = None
13+
814from fitparse .utils import fileish_open , is_iterable
915
1016if sys .version_info >= (2 , 7 ):
@@ -38,6 +44,8 @@ def test_fopen(fileish):
3844 test_fopen (f .read ())
3945 with open (testfile ("nametest.FIT" ), 'rb' ) as f :
4046 test_fopen (io .BytesIO (f .read ()))
47+ if Path :
48+ test_fopen (Path (testfile ('nametest.FIT' )))
4149
4250 def test_fileish_open_write (self ):
4351
You can’t perform that action at this time.
0 commit comments