@@ -98,7 +98,7 @@ public static PythonTuple _getdiskusage([NotNone] string path) {
9898 private static extern int GetFinalPathNameByHandle ( [ In ] SafeFileHandle hFile , [ Out ] StringBuilder lpszFilePath , [ In ] int cchFilePath , [ In ] int dwFlags ) ;
9999
100100 [ SupportedOSPlatform ( "windows" ) , PythonHidden ( PlatformsAttribute . PlatformFamily . Unix ) ]
101- public static string _getfinalpathname ( [ NotNone ] string path ) {
101+ public static string _getfinalpathname ( CodeContext /*!*/ context , [ NotNone ] string path ) {
102102 var hFile = CreateFile ( path , 0 , 0 , IntPtr . Zero , OPEN_EXISTING , FILE_FLAG_BACKUP_SEMANTICS , IntPtr . Zero ) ;
103103 if ( hFile . IsInvalid ) {
104104 throw GetLastWin32Error ( path ) ;
@@ -112,6 +112,20 @@ public static string _getfinalpathname([NotNone] string path) {
112112 return sb . ToString ( ) ;
113113 }
114114
115+ [ SupportedOSPlatform ( "windows" ) , PythonHidden ( PlatformsAttribute . PlatformFamily . Unix ) ]
116+ public static Bytes _getfinalpathname ( CodeContext /*!*/ context , [ NotNone ] Bytes path )
117+ => _getfinalpathname ( context , path . ToFsString ( context ) ) . ToFsBytes ( context ) ;
118+
119+ [ SupportedOSPlatform ( "windows" ) , PythonHidden ( PlatformsAttribute . PlatformFamily . Unix ) ]
120+ public static object _getfinalpathname ( CodeContext /*!*/ context , object ? path ) {
121+ return ToFsPath ( context , path , nameof ( path ) ) switch {
122+ string s => _getfinalpathname ( context , s ) ,
123+ Extensible < string > es => _getfinalpathname ( context , es . Value ) ,
124+ Bytes b => _getfinalpathname ( context , b ) ,
125+ _ => throw new InvalidOperationException ( ) ,
126+ } ;
127+ }
128+
115129 public static string _getfullpathname ( CodeContext /*!*/ context , [ NotNone ] string /*!*/ path ) {
116130 PlatformAdaptationLayer pal = context . LanguageContext . DomainManager . Platform ;
117131
@@ -189,8 +203,14 @@ static bool IsWindows() {
189203 public static Bytes _getfullpathname ( CodeContext /*!*/ context , [ NotNone ] Bytes path )
190204 => _getfullpathname ( context , path . ToFsString ( context ) ) . ToFsBytes ( context ) ;
191205
192- public static Bytes _getfullpathname ( CodeContext /*!*/ context , object ? path )
193- => _getfullpathname ( context , ConvertToFsString ( context , path , nameof ( path ) ) ) . ToFsBytes ( context ) ;
206+ public static object _getfullpathname ( CodeContext /*!*/ context , object ? path ) {
207+ return ToFsPath ( context , path , nameof ( path ) ) switch {
208+ string s => _getfullpathname ( context , s ) ,
209+ Extensible < string > es => _getfullpathname ( context , es . Value ) ,
210+ Bytes b => _getfullpathname ( context , b ) ,
211+ _ => throw new InvalidOperationException ( ) ,
212+ } ;
213+ }
194214
195215#if FEATURE_PROCESS
196216 public static void abort ( ) {
@@ -2244,7 +2264,7 @@ private static Encoding _getFileSystemEncoding(CodeContext context) {
22442264
22452265 private static Bytes ToFsBytes ( this string s , CodeContext context ) => Bytes . Make ( _getFileSystemEncoding ( context ) . GetBytes ( s ) ) ;
22462266
2247- private static string ConvertToFsString ( CodeContext context , object ? o , string argname , [ CallerMemberName ] string ? methodname = null , string ? orType = null ) {
2267+ private static object ToFsPath ( CodeContext context , object ? o , string argname , [ CallerMemberName ] string ? methodname = null , string ? orType = null ) {
22482268 if ( o is not Bytes && o is IBufferProtocol bp ) {
22492269 if ( orType is null )
22502270 PythonOps . Warn ( context , PythonExceptions . DeprecationWarning , "{0}: {1} should be string, bytes or os.PathLike, not {2}" , methodname , argname , PythonOps . GetPythonTypeName ( o ) ) ;
@@ -2253,7 +2273,7 @@ private static string ConvertToFsString(CodeContext context, object? o, string a
22532273 o = new Bytes ( bp ) ; // accepts FULL_RO buffers in CPython
22542274 }
22552275
2256- if ( PythonOps . TryToFsPathDecoded ( context , o , out var res ) )
2276+ if ( PythonOps . TryToFsPath ( context , o , out var res ) )
22572277 return res ;
22582278
22592279 if ( orType is null )
@@ -2262,6 +2282,9 @@ private static string ConvertToFsString(CodeContext context, object? o, string a
22622282 throw PythonOps . TypeError ( "{0}: {1} should be string, bytes, os.PathLike or {3}, not {2}" , methodname , argname , PythonOps . GetPythonTypeName ( o ) , orType ) ;
22632283 }
22642284
2285+ private static string ConvertToFsString ( CodeContext context , object ? o , string argname , [ CallerMemberName ] string ? methodname = null , string ? orType = null )
2286+ => PythonOps . DecodeFsPath ( context , ToFsPath ( context , o , argname , methodname , orType ) ) ;
2287+
22652288 private static void CheckOptionalArgsCount ( int numRegParms , int numOptPosParms , int numKwParms , int numOptPosArgs , int numKwArgs , [ CallerMemberName ] string ? methodname = null ) {
22662289 if ( numOptPosArgs > numOptPosParms )
22672290 throw PythonOps . TypeErrorForOptionalArgumentCountMismatch ( methodname ?? "<unknown>" , numRegParms + numOptPosParms , numRegParms + numOptPosArgs , positional : true ) ;
0 commit comments