Escape all special characters.
(pathname)
| 259 | return pattern == '**' |
| 260 | |
| 261 | def escape(pathname): |
| 262 | """Escape all special characters. |
| 263 | """ |
| 264 | # Escaping is done by wrapping any of "*?[" between square brackets. |
| 265 | # Metacharacters do not work in the drive part and shouldn't be escaped. |
| 266 | drive, pathname = os.path.splitdrive(pathname) |
| 267 | if isinstance(pathname, bytes): |
| 268 | pathname = magic_check_bytes.sub(br'[\1]', pathname) |
| 269 | else: |
| 270 | pathname = magic_check.sub(r'[\1]', pathname) |
| 271 | return drive + pathname |
| 272 | |
| 273 | |
| 274 | _special_parts = ('', '.', '..') |