| 229 | |
| 230 | |
| 231 | class _PosixFlavour(_Flavour): |
| 232 | sep = '/' |
| 233 | altsep = '' |
| 234 | has_drv = False |
| 235 | pathmod = posixpath |
| 236 | |
| 237 | is_supported = (os.name != 'nt') |
| 238 | |
| 239 | def splitroot(self, part, sep=sep): |
| 240 | if part and part[0] == sep: |
| 241 | stripped_part = part.lstrip(sep) |
| 242 | # According to POSIX path resolution: |
| 243 | # http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11 |
| 244 | # "A pathname that begins with two successive slashes may be |
| 245 | # interpreted in an implementation-defined manner, although more |
| 246 | # than two leading slashes shall be treated as a single slash". |
| 247 | if len(part) - len(stripped_part) == 2: |
| 248 | return '', sep * 2, stripped_part |
| 249 | else: |
| 250 | return '', sep, stripped_part |
| 251 | else: |
| 252 | return '', '', part |
| 253 | |
| 254 | def casefold(self, s): |
| 255 | return s |
| 256 | |
| 257 | def casefold_parts(self, parts): |
| 258 | return parts |
| 259 | |
| 260 | def compile_pattern(self, pattern): |
| 261 | return re.compile(fnmatch.translate(pattern)).fullmatch |
| 262 | |
| 263 | def is_reserved(self, parts): |
| 264 | return False |
| 265 | |
| 266 | def make_uri(self, path): |
| 267 | # We represent the path using the local filesystem encoding, |
| 268 | # for portability to other applications. |
| 269 | bpath = bytes(path) |
| 270 | return 'file://' + urlquote_from_bytes(bpath) |
| 271 | |
| 272 | |
| 273 | _windows_flavour = _WindowsFlavour() |