Skip to content

Commit 85bded3

Browse files
matteiusoz123
authored andcommitted
Add missing files from vendoring update.
1 parent ba73770 commit 85bded3

File tree

4 files changed

+173
-0
lines changed

4 files changed

+173
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
"""Functions brought over from jaraco.text.
2+
3+
These functions are not supposed to be used within `pipenv.patched.pip._internal`. These are
4+
helper functions brought over from `jaraco.text` to enable vendoring newer
5+
copies of `pkg_resources` without having to vendor `jaraco.text` and its entire
6+
dependency cone; something that our vendoring setup is not currently capable of
7+
handling.
8+
9+
License reproduced from original source below:
10+
11+
Copyright Jason R. Coombs
12+
13+
Permission is hereby granted, free of charge, to any person obtaining a copy
14+
of this software and associated documentation files (the "Software"), to
15+
deal in the Software without restriction, including without limitation the
16+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
17+
sell copies of the Software, and to permit persons to whom the Software is
18+
furnished to do so, subject to the following conditions:
19+
20+
The above copyright notice and this permission notice shall be included in
21+
all copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29+
IN THE SOFTWARE.
30+
"""
31+
32+
import functools
33+
import itertools
34+
35+
36+
def _nonblank(str):
37+
return str and not str.startswith("#")
38+
39+
40+
@functools.singledispatch
41+
def yield_lines(iterable):
42+
r"""
43+
Yield valid lines of a string or iterable.
44+
45+
>>> list(yield_lines(''))
46+
[]
47+
>>> list(yield_lines(['foo', 'bar']))
48+
['foo', 'bar']
49+
>>> list(yield_lines('foo\nbar'))
50+
['foo', 'bar']
51+
>>> list(yield_lines('\nfoo\n#bar\nbaz #comment'))
52+
['foo', 'baz #comment']
53+
>>> list(yield_lines(['foo\nbar', 'baz', 'bing\n\n\n']))
54+
['foo', 'bar', 'baz', 'bing']
55+
"""
56+
return itertools.chain.from_iterable(map(yield_lines, iterable))
57+
58+
59+
@yield_lines.register(str)
60+
def _(text):
61+
return filter(_nonblank, map(str.strip, text.splitlines()))
62+
63+
64+
def drop_comment(line):
65+
"""
66+
Drop comments.
67+
68+
>>> drop_comment('foo # bar')
69+
'foo'
70+
71+
A hash without a space may be in a URL.
72+
73+
>>> drop_comment('http://example.com/foo#bar')
74+
'http://example.com/foo#bar'
75+
"""
76+
return line.partition(" #")[0]
77+
78+
79+
def join_continuation(lines):
80+
r"""
81+
Join lines continued by a trailing backslash.
82+
83+
>>> list(join_continuation(['foo \\', 'bar', 'baz']))
84+
['foobar', 'baz']
85+
>>> list(join_continuation(['foo \\', 'bar', 'baz']))
86+
['foobar', 'baz']
87+
>>> list(join_continuation(['foo \\', 'bar \\', 'baz']))
88+
['foobarbaz']
89+
90+
Not sure why, but...
91+
The character preceeding the backslash is also elided.
92+
93+
>>> list(join_continuation(['goo\\', 'dly']))
94+
['godly']
95+
96+
A terrible idea, but...
97+
If no line is available to continue, suppress the lines.
98+
99+
>>> list(join_continuation(['foo', 'bar\\', 'baz\\']))
100+
['foo']
101+
"""
102+
lines = iter(lines)
103+
for item in lines:
104+
while item.endswith("\\"):
105+
try:
106+
item = item[:-2].strip() + next(lines)
107+
except StopIteration:
108+
return
109+
yield item
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright Jason R. Coombs
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to
5+
deal in the Software without restriction, including without limitation the
6+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7+
sell copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19+
IN THE SOFTWARE.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from __future__ import annotations
2+
3+
from typing import IO, Callable
4+
5+
6+
def get_fileno(file_like: IO[str]) -> int | None:
7+
"""Get fileno() from a file, accounting for poorly implemented file-like objects.
8+
9+
Args:
10+
file_like (IO): A file-like object.
11+
12+
Returns:
13+
int | None: The result of fileno if available, or None if operation failed.
14+
"""
15+
fileno: Callable[[], int] | None = getattr(file_like, "fileno", None)
16+
if fileno is not None:
17+
try:
18+
return fileno()
19+
except Exception:
20+
# `fileno` is documented as potentially raising a OSError
21+
# Alas, from the issues, there are so many poorly implemented file-like objects,
22+
# that `fileno()` can raise just about anything.
23+
return None
24+
return None
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014-2022 Anthon van der Neut, Ruamel bvba
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)