Issue #3187: Better support for "undecodable" filenames.  Code by Victor
Stinner, with small tweaks by GvR.
diff --git a/Lib/glob.py b/Lib/glob.py
index cd6c302..9529f7e 100644
--- a/Lib/glob.py
+++ b/Lib/glob.py
@@ -27,7 +27,7 @@
         return
     dirname, basename = os.path.split(pathname)
     if not dirname:
-        for name in glob1(os.curdir, basename):
+        for name in glob1(None, basename):
             yield name
         return
     if has_magic(dirname):
@@ -48,10 +48,10 @@
 
 def glob1(dirname, pattern):
     if not dirname:
-        dirname = os.curdir
-    if isinstance(pattern, str) and not isinstance(dirname, str):
-        dirname = str(dirname, sys.getfilesystemencoding() or
-                                   sys.getdefaultencoding())
+        if isinstance(pattern, bytes):
+            dirname = bytes(os.curdir, 'ASCII')
+        else:
+            dirname = os.curdir
     try:
         names = os.listdir(dirname)
     except os.error:
@@ -73,6 +73,11 @@
 
 
 magic_check = re.compile('[*?[]')
+magic_check_bytes = re.compile(b'[*?[]')
 
 def has_magic(s):
-    return magic_check.search(s) is not None
+    if isinstance(s, bytes):
+        match = magic_check_bytes.search(s)
+    else:
+        match = magic_check.search(s)
+    return match is not None