Escape all special characters.
(pathname)
| 237 | return pattern == '**' |
| 238 | |
| 239 | def escape(pathname): |
| 240 | """Escape all special characters. |
| 241 | """ |
| 242 | # Escaping is done by wrapping any of "*?[" between square brackets. |
| 243 | # Metacharacters do not work in the drive part and shouldn't be escaped. |
| 244 | drive, pathname = os.path.splitdrive(pathname) |
| 245 | if isinstance(pathname, bytes): |
| 246 | pathname = magic_check_bytes.sub(br'[\1]', pathname) |
| 247 | else: |
| 248 | pathname = magic_check.sub(r'[\1]', pathname) |
| 249 | return drive + pathname |
| 250 | |
| 251 | |
| 252 | _dir_open_flags = os.O_RDONLY | getattr(os, 'O_DIRECTORY', 0) |