Skip to content

Commit

Permalink
Use scandir for PHP import lookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ssigwart committed Jul 6, 2019
1 parent 5dd336f commit 2e5f974
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/udl/skel/PHP/pylib/lang_php.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
if _xpcom_:
from xpcom.server import UnwrapObject

# Get scandir
scandir = None
try:
from scandir import scandir
except ImportError:
pass


#---- global data
Expand Down Expand Up @@ -1300,21 +1306,33 @@ def find_importables_in_dir(self, dir, env=None):
if not env:
env = self.mgr.env

dirs, nondirs = set(), set()
try:
names = os.listdir(dir)
if scandir:
for dirEntry in scandir(dir):
try:
if dirEntry.is_dir():
dirs.add(dirEntry.name)
else:
nondirs.add(dirEntry.name)
except UnicodeDecodeError:
# Hit a filename that cannot be encoded in the default encoding.
# Just skip it. (Bug 82268)
pass
else:
names = os.listdir(dir)
for name in names:
try:
if isdir(join(dir, name)):
dirs.add(name)
else:
nondirs.add(name)
except UnicodeDecodeError:
# Hit a filename that cannot be encoded in the default encoding.
# Just skip it. (Bug 82268)
pass
except OSError, ex:
return {}
dirs, nondirs = set(), set()
for name in names:
try:
if isdir(join(dir, name)):
dirs.add(name)
else:
nondirs.add(name)
except UnicodeDecodeError:
# Hit a filename that cannot be encoded in the default encoding.
# Just skip it. (Bug 82268)
pass

importables = {}
patterns = env.assoc_patterns_from_lang("PHP")
Expand Down

0 comments on commit 2e5f974

Please sign in to comment.