Object representing a repository location
| 504 | |
| 505 | |
| 506 | class Location: |
| 507 | """Object representing a repository location""" |
| 508 | |
| 509 | # user@ (optional) |
| 510 | # user must not contain "@", ":" or "/". |
| 511 | # Quoting adduser error message: |
| 512 | # "To avoid problems, the username should consist only of letters, digits, |
| 513 | # underscores, periods, at signs and dashes, and not start with a dash |
| 514 | # (as defined by IEEE Std 1003.1-2001)." |
| 515 | # We use "@" as separator between username and hostname, so we must |
| 516 | # disallow it within the pure username part. |
| 517 | optional_user_re = r"(?:(?P<user>[^@:/]+)@)?" |
| 518 | |
| 519 | # host NAME, or host IP ADDRESS (v4 or v6, v6 must be in square brackets) |
| 520 | host_re = r""" |
| 521 | (?P<host>( |
| 522 | (?!\[)[^:/]+(?<!\]) # hostname or v4 addr, not containing : or / (does not match v6 addr: no brackets!) |
| 523 | | |
| 524 | \[[0-9a-fA-F:.]+\]) # ipv6 address in brackets |
| 525 | ) |
| 526 | """ |
| 527 | |
| 528 | # :port (optional) |
| 529 | optional_port_re = r"(?::(?P<port>\d+))?" |
| 530 | |
| 531 | # path may contain any chars. to avoid ambiguities with other regexes, |
| 532 | # it must not start with "//" nor with "scheme://" nor with "rclone:". |
| 533 | local_path_re = r""" |
| 534 | (?!(//|(ssh|socket|sftp|file)://|(rclone|s3|b2):)) |
| 535 | (?P<path>.+) |
| 536 | """ |
| 537 | |
| 538 | # abs_path must start with a slash (or drive letter on Windows). |
| 539 | abs_path_re = r"(?P<path>[A-Za-z]:/.+)" if is_win32 else r"(?P<path>/.+)" |
| 540 | |
| 541 | # path may or may not start with a slash. |
| 542 | abs_or_rel_path_re = r"(?P<path>.+)" |
| 543 | |
| 544 | # regexes for misc. kinds of supported location specifiers: |
| 545 | ssh_or_sftp_re = re.compile( |
| 546 | r"(?P<proto>(ssh|sftp))://" |
| 547 | + optional_user_re |
| 548 | + host_re |
| 549 | + optional_port_re |
| 550 | + r"/" # this is the separator, not part of the path! |
| 551 | + abs_or_rel_path_re, |
| 552 | re.VERBOSE, |
| 553 | ) |
| 554 | |
| 555 | # BorgStore REST server |
| 556 | # (http|https)://user:pass@host:port/ |
| 557 | http_re = re.compile( |
| 558 | r"(?P<proto>http|https)://" |
| 559 | + r"((?P<user>[^:@]+):(?P<pass>[^@]+)@)?" |
| 560 | + host_re |
| 561 | + optional_port_re |
| 562 | + r"(?P<path>/)", |
| 563 | re.VERBOSE, |
no outgoing calls