|
15 | 15 | else:
|
16 | 16 | import tomllib
|
17 | 17 |
|
| 18 | +from .helpers import extract_url_user_auth, guess_suffix_from_url |
18 | 19 |
|
19 | 20 | def clean_list(item: list, sort: bool = True) -> list:
|
20 | 21 | """Remove duplicate entries from a list."""
|
@@ -118,22 +119,35 @@ def _read_source(self):
|
118 | 119 | self.filename, extras = split_extras(self.filename)
|
119 | 120 | self.extras |= set(extras)
|
120 | 121 |
|
121 |
| - # store suffix for later parsing |
122 |
| - self._suffix = Path(self.filename).suffix |
123 |
| - |
124 | 122 | # read file contents into bytes
|
125 | 123 | _filename = self.filename
|
126 | 124 | if isinstance(_filename, str) and _filename.startswith("http"):
|
127 | 125 | import urllib.request
|
128 | 126 |
|
| 127 | + _token = None |
| 128 | + |
| 129 | + # site specific url parsing |
129 | 130 | if "/github.com/" in _filename:
|
130 | 131 | _filename = _filename.replace(
|
131 | 132 | "/github.com/", "/raw.githubusercontent.com/"
|
132 | 133 | )
|
133 | 134 | _filename = _filename.replace("/blob/", "/")
|
134 |
| - with urllib.request.urlopen(_filename) as f: |
| 135 | + elif "git.bam.de" in _filename or "gitlab.com" in _filename: |
| 136 | + _filename, _, _token = extract_url_user_auth(_filename) |
| 137 | + |
| 138 | + req = urllib.request.Request(_filename) |
| 139 | + if _token: |
| 140 | + req.add_header("PRIVATE-TOKEN", _token) |
| 141 | + |
| 142 | + # store suffix for later parsing |
| 143 | + self._suffix = guess_suffix_from_url(_filename) |
| 144 | + |
| 145 | + with urllib.request.urlopen(req) as f: |
135 | 146 | _contents: bytes = f.read() # read raw content into bytes
|
136 | 147 | else:
|
| 148 | + # store suffix for later parsing |
| 149 | + self._suffix = Path(self.filename).suffix |
| 150 | + |
137 | 151 | with open(_filename, "rb") as f:
|
138 | 152 | _contents: bytes = f.read()
|
139 | 153 |
|
|
0 commit comments