File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change
1
+ import os
1
2
import sys
2
3
import warnings
3
4
@@ -89,19 +90,19 @@ def native(s):
89
90
90
91
def path_string (s ):
91
92
"""
92
- Convert a Python string to a :py:class:`bytes` string identifying the same
93
+ Convert a Python path to a :py:class:`bytes` string identifying the same
93
94
path and which can be passed into an OpenSSL API accepting a filename.
94
95
95
- :param s: An instance of :py:class:`bytes` or :py:class:`unicode` .
96
+ :param s: A path (valid for os.fspath) .
96
97
97
98
:return: An instance of :py:class:`bytes`.
98
99
"""
99
- if isinstance ( s , bytes ):
100
- return s
101
- elif isinstance (s , str ):
102
- return s .encode (sys .getfilesystemencoding ())
100
+ strpath = os . fspath ( s ) # returns str or bytes
101
+
102
+ if isinstance (strpath , str ):
103
+ return strpath .encode (sys .getfilesystemencoding ())
103
104
else :
104
- raise TypeError ( "Path must be represented as bytes or unicode string" )
105
+ return strpath
105
106
106
107
107
108
def byte_string (s ):
You can’t perform that action at this time.
0 commit comments