mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 00:32:57 -04:00
stdpy: add Python 3 stuff to glob module, remove re dependency
This commit is contained in:
parent
0bb81a43c9
commit
140644d8b6
@ -4,7 +4,6 @@ virtual file system. """
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
|
||||||
from direct.stdpy import file
|
from direct.stdpy import file
|
||||||
@ -76,7 +75,27 @@ def glob0(dirname, basename):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
magic_check = re.compile('[*?[]')
|
|
||||||
|
|
||||||
def has_magic(s):
|
def has_magic(s):
|
||||||
return magic_check.search(s) is not None
|
if isinstance(s, bytes):
|
||||||
|
return b'*' in s or b'?' in s or b'[' in s
|
||||||
|
else:
|
||||||
|
return '*' in s or '?' in s or '[' in s
|
||||||
|
|
||||||
|
def escape(pathname):
|
||||||
|
drive, pathname = os.path.splitdrive(pathname)
|
||||||
|
if sys.version_info >= (3, 0) and isinstance(pathname, bytes):
|
||||||
|
newpath = bytearray(drive)
|
||||||
|
for c in pathname:
|
||||||
|
if c == 42 or c == 63 or c == 91:
|
||||||
|
newpath += bytes((91, c, 93))
|
||||||
|
else:
|
||||||
|
newpath.append(c)
|
||||||
|
return bytes(newpath)
|
||||||
|
else:
|
||||||
|
newpath = drive
|
||||||
|
for c in pathname:
|
||||||
|
if c == '*' or c == '?' or c == '[':
|
||||||
|
newpath += '[' + c + ']'
|
||||||
|
else:
|
||||||
|
newpath += c
|
||||||
|
return newpath
|
||||||
|
Loading…
x
Reference in New Issue
Block a user