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
12import sys
23import warnings
34
@@ -89,19 +90,19 @@ def native(s):
8990
9091def path_string (s ):
9192 """
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
9394 path and which can be passed into an OpenSSL API accepting a filename.
9495
95- :param s: An instance of :py:class:`bytes` or :py:class:`unicode` .
96+ :param s: A path (valid for os.fspath) .
9697
9798 :return: An instance of :py:class:`bytes`.
9899 """
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 ())
103104 else :
104- raise TypeError ( "Path must be represented as bytes or unicode string" )
105+ return strpath
105106
106107
107108def byte_string (s ):
You can’t perform that action at this time.
0 commit comments