| 70 | |
| 71 | |
| 72 | def parse_scheme(scheme): |
| 73 | # type: (str) -> Union[str, ArchiveScheme.Value, VCSScheme] |
| 74 | match = re.match( |
| 75 | r""" |
| 76 | ^ |
| 77 | (?: |
| 78 | (?P<archive_scheme> |
| 79 | # Archives |
| 80 | ftp |
| 81 | | https? |
| 82 | ) |
| 83 | | |
| 84 | (?P<vcs_type> |
| 85 | # VCSs: https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support |
| 86 | bzr |
| 87 | | git |
| 88 | | hg |
| 89 | | svn |
| 90 | )\+(?P<vcs_scheme>.+) |
| 91 | ) |
| 92 | $ |
| 93 | """, |
| 94 | scheme, |
| 95 | re.VERBOSE, |
| 96 | ) |
| 97 | if not match: |
| 98 | return scheme |
| 99 | |
| 100 | archive_scheme = match.group("archive_scheme") |
| 101 | if archive_scheme: |
| 102 | return cast(ArchiveScheme.Value, ArchiveScheme.for_value(archive_scheme)) |
| 103 | |
| 104 | return VCSScheme(vcs=VCS.for_value(match.group("vcs_type")), scheme=match.group("vcs_scheme")) |
| 105 | |
| 106 | |
| 107 | @attr.s(frozen=True) |