File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -346,5 +346,46 @@ def suspend_hooks():
346
346
enable_hooks ()
347
347
348
348
349
+ def os_path_join (a , * p ):
350
+ """
351
+ Replacement os.path.join from Python 3.3 (posixpath.py) which doesn't
352
+ add a byte-string to a unicode string as Python 2.7's does.
353
+
354
+ Join two or more pathname components, inserting '/' as needed.
355
+ If any component is an absolute path, all previous path components
356
+ will be discarded. An empty last part will result in a path that
357
+ ends with a separator."""
358
+ sep = _get_sep (a )
359
+ path = a
360
+ try :
361
+ for b in p :
362
+ if b .startswith (sep ):
363
+ path = b
364
+ elif not path or path .endswith (sep ):
365
+ path += b
366
+ else :
367
+ path += sep + b
368
+ except TypeError :
369
+ valid_types = all (isinstance (s , (str , bytes , bytearray ))
370
+ for s in (a , ) + p )
371
+ if valid_types :
372
+ # Must have a mixture of text and binary data
373
+ raise TypeError ("Can't mix strings and bytes in path "
374
+ "components." ) from None
375
+ raise
376
+ return path
377
+
378
+
379
+ def monkey_patch_stdlib ():
380
+ """
381
+ Patches out some bugs, like the dodgy os.path.join in Python 2.x,
382
+ which adds the byte-string '/' to unicode paths.
383
+ """
384
+ if not module in sys .modules :
385
+ __import__ (module )
386
+ modname , module = module , sys .modules [module ]
387
+
388
+
349
389
if not utils .PY3 :
350
390
enable_hooks ()
391
+ monkey_patch_stdlib ()
You can’t perform that action at this time.
0 commit comments