Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- env-llmeval/lib/python3.10/site-packages/colorama/__init__.py +7 -0
- env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/__init__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/ansi.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/ansitowin32.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/initialise.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/win32.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/winterm.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/ansi.py +102 -0
- env-llmeval/lib/python3.10/site-packages/colorama/ansitowin32.py +277 -0
- env-llmeval/lib/python3.10/site-packages/colorama/initialise.py +121 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/__init__.py +1 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/ansi_test.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/ansitowin32_test.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/initialise_test.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/isatty_test.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/utils.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/winterm_test.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/ansi_test.py +76 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/ansitowin32_test.py +294 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/initialise_test.py +189 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/isatty_test.py +57 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/utils.py +49 -0
- env-llmeval/lib/python3.10/site-packages/colorama/tests/winterm_test.py +131 -0
- env-llmeval/lib/python3.10/site-packages/colorama/win32.py +180 -0
- env-llmeval/lib/python3.10/site-packages/colorama/winterm.py +195 -0
- env-llmeval/lib/python3.10/site-packages/packaging/_parser.py +356 -0
- env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/INSTALLER +1 -0
- env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/LICENSE +175 -0
- env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/METADATA +122 -0
- env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/RECORD +42 -0
- env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/WHEEL +5 -0
- env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/top_level.txt +1 -0
- env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/PKG-INFO +114 -0
- env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/SOURCES.txt +22 -0
- env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/dependency_links.txt +1 -0
- env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/installed-files.txt +33 -0
- env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/requires.txt +4 -0
- env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/top_level.txt +1 -0
- env-llmeval/lib/python3.10/site-packages/tcolorpy/__init__.py +21 -0
- env-llmeval/lib/python3.10/site-packages/tcolorpy/__main__.py +63 -0
- env-llmeval/lib/python3.10/site-packages/tcolorpy/__pycache__/__init__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/tcolorpy/__pycache__/__main__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/tcolorpy/__pycache__/__version__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/tcolorpy/__pycache__/_const.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/tcolorpy/__pycache__/_truecolor.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/tcolorpy/__version__.py +6 -0
- env-llmeval/lib/python3.10/site-packages/tcolorpy/_const.py +70 -0
- env-llmeval/lib/python3.10/site-packages/tcolorpy/_truecolor.py +249 -0
- env-llmeval/lib/python3.10/site-packages/tcolorpy/py.typed +0 -0
env-llmeval/lib/python3.10/site-packages/colorama/__init__.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
from .initialise import init, deinit, reinit, colorama_text, just_fix_windows_console
|
3 |
+
from .ansi import Fore, Back, Style, Cursor
|
4 |
+
from .ansitowin32 import AnsiToWin32
|
5 |
+
|
6 |
+
__version__ = '0.4.6'
|
7 |
+
|
env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (459 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/ansi.cpython-310.pyc
ADDED
Binary file (2.99 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/ansitowin32.cpython-310.pyc
ADDED
Binary file (8.5 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/initialise.cpython-310.pyc
ADDED
Binary file (2.24 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/win32.cpython-310.pyc
ADDED
Binary file (4.45 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/__pycache__/winterm.cpython-310.pyc
ADDED
Binary file (5.15 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/ansi.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
'''
|
3 |
+
This module generates ANSI character codes to printing colors to terminals.
|
4 |
+
See: http://en.wikipedia.org/wiki/ANSI_escape_code
|
5 |
+
'''
|
6 |
+
|
7 |
+
CSI = '\033['
|
8 |
+
OSC = '\033]'
|
9 |
+
BEL = '\a'
|
10 |
+
|
11 |
+
|
12 |
+
def code_to_chars(code):
|
13 |
+
return CSI + str(code) + 'm'
|
14 |
+
|
15 |
+
def set_title(title):
|
16 |
+
return OSC + '2;' + title + BEL
|
17 |
+
|
18 |
+
def clear_screen(mode=2):
|
19 |
+
return CSI + str(mode) + 'J'
|
20 |
+
|
21 |
+
def clear_line(mode=2):
|
22 |
+
return CSI + str(mode) + 'K'
|
23 |
+
|
24 |
+
|
25 |
+
class AnsiCodes(object):
|
26 |
+
def __init__(self):
|
27 |
+
# the subclasses declare class attributes which are numbers.
|
28 |
+
# Upon instantiation we define instance attributes, which are the same
|
29 |
+
# as the class attributes but wrapped with the ANSI escape sequence
|
30 |
+
for name in dir(self):
|
31 |
+
if not name.startswith('_'):
|
32 |
+
value = getattr(self, name)
|
33 |
+
setattr(self, name, code_to_chars(value))
|
34 |
+
|
35 |
+
|
36 |
+
class AnsiCursor(object):
|
37 |
+
def UP(self, n=1):
|
38 |
+
return CSI + str(n) + 'A'
|
39 |
+
def DOWN(self, n=1):
|
40 |
+
return CSI + str(n) + 'B'
|
41 |
+
def FORWARD(self, n=1):
|
42 |
+
return CSI + str(n) + 'C'
|
43 |
+
def BACK(self, n=1):
|
44 |
+
return CSI + str(n) + 'D'
|
45 |
+
def POS(self, x=1, y=1):
|
46 |
+
return CSI + str(y) + ';' + str(x) + 'H'
|
47 |
+
|
48 |
+
|
49 |
+
class AnsiFore(AnsiCodes):
|
50 |
+
BLACK = 30
|
51 |
+
RED = 31
|
52 |
+
GREEN = 32
|
53 |
+
YELLOW = 33
|
54 |
+
BLUE = 34
|
55 |
+
MAGENTA = 35
|
56 |
+
CYAN = 36
|
57 |
+
WHITE = 37
|
58 |
+
RESET = 39
|
59 |
+
|
60 |
+
# These are fairly well supported, but not part of the standard.
|
61 |
+
LIGHTBLACK_EX = 90
|
62 |
+
LIGHTRED_EX = 91
|
63 |
+
LIGHTGREEN_EX = 92
|
64 |
+
LIGHTYELLOW_EX = 93
|
65 |
+
LIGHTBLUE_EX = 94
|
66 |
+
LIGHTMAGENTA_EX = 95
|
67 |
+
LIGHTCYAN_EX = 96
|
68 |
+
LIGHTWHITE_EX = 97
|
69 |
+
|
70 |
+
|
71 |
+
class AnsiBack(AnsiCodes):
|
72 |
+
BLACK = 40
|
73 |
+
RED = 41
|
74 |
+
GREEN = 42
|
75 |
+
YELLOW = 43
|
76 |
+
BLUE = 44
|
77 |
+
MAGENTA = 45
|
78 |
+
CYAN = 46
|
79 |
+
WHITE = 47
|
80 |
+
RESET = 49
|
81 |
+
|
82 |
+
# These are fairly well supported, but not part of the standard.
|
83 |
+
LIGHTBLACK_EX = 100
|
84 |
+
LIGHTRED_EX = 101
|
85 |
+
LIGHTGREEN_EX = 102
|
86 |
+
LIGHTYELLOW_EX = 103
|
87 |
+
LIGHTBLUE_EX = 104
|
88 |
+
LIGHTMAGENTA_EX = 105
|
89 |
+
LIGHTCYAN_EX = 106
|
90 |
+
LIGHTWHITE_EX = 107
|
91 |
+
|
92 |
+
|
93 |
+
class AnsiStyle(AnsiCodes):
|
94 |
+
BRIGHT = 1
|
95 |
+
DIM = 2
|
96 |
+
NORMAL = 22
|
97 |
+
RESET_ALL = 0
|
98 |
+
|
99 |
+
Fore = AnsiFore()
|
100 |
+
Back = AnsiBack()
|
101 |
+
Style = AnsiStyle()
|
102 |
+
Cursor = AnsiCursor()
|
env-llmeval/lib/python3.10/site-packages/colorama/ansitowin32.py
ADDED
@@ -0,0 +1,277 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
import re
|
3 |
+
import sys
|
4 |
+
import os
|
5 |
+
|
6 |
+
from .ansi import AnsiFore, AnsiBack, AnsiStyle, Style, BEL
|
7 |
+
from .winterm import enable_vt_processing, WinTerm, WinColor, WinStyle
|
8 |
+
from .win32 import windll, winapi_test
|
9 |
+
|
10 |
+
|
11 |
+
winterm = None
|
12 |
+
if windll is not None:
|
13 |
+
winterm = WinTerm()
|
14 |
+
|
15 |
+
|
16 |
+
class StreamWrapper(object):
|
17 |
+
'''
|
18 |
+
Wraps a stream (such as stdout), acting as a transparent proxy for all
|
19 |
+
attribute access apart from method 'write()', which is delegated to our
|
20 |
+
Converter instance.
|
21 |
+
'''
|
22 |
+
def __init__(self, wrapped, converter):
|
23 |
+
# double-underscore everything to prevent clashes with names of
|
24 |
+
# attributes on the wrapped stream object.
|
25 |
+
self.__wrapped = wrapped
|
26 |
+
self.__convertor = converter
|
27 |
+
|
28 |
+
def __getattr__(self, name):
|
29 |
+
return getattr(self.__wrapped, name)
|
30 |
+
|
31 |
+
def __enter__(self, *args, **kwargs):
|
32 |
+
# special method lookup bypasses __getattr__/__getattribute__, see
|
33 |
+
# https://stackoverflow.com/questions/12632894/why-doesnt-getattr-work-with-exit
|
34 |
+
# thus, contextlib magic methods are not proxied via __getattr__
|
35 |
+
return self.__wrapped.__enter__(*args, **kwargs)
|
36 |
+
|
37 |
+
def __exit__(self, *args, **kwargs):
|
38 |
+
return self.__wrapped.__exit__(*args, **kwargs)
|
39 |
+
|
40 |
+
def __setstate__(self, state):
|
41 |
+
self.__dict__ = state
|
42 |
+
|
43 |
+
def __getstate__(self):
|
44 |
+
return self.__dict__
|
45 |
+
|
46 |
+
def write(self, text):
|
47 |
+
self.__convertor.write(text)
|
48 |
+
|
49 |
+
def isatty(self):
|
50 |
+
stream = self.__wrapped
|
51 |
+
if 'PYCHARM_HOSTED' in os.environ:
|
52 |
+
if stream is not None and (stream is sys.__stdout__ or stream is sys.__stderr__):
|
53 |
+
return True
|
54 |
+
try:
|
55 |
+
stream_isatty = stream.isatty
|
56 |
+
except AttributeError:
|
57 |
+
return False
|
58 |
+
else:
|
59 |
+
return stream_isatty()
|
60 |
+
|
61 |
+
@property
|
62 |
+
def closed(self):
|
63 |
+
stream = self.__wrapped
|
64 |
+
try:
|
65 |
+
return stream.closed
|
66 |
+
# AttributeError in the case that the stream doesn't support being closed
|
67 |
+
# ValueError for the case that the stream has already been detached when atexit runs
|
68 |
+
except (AttributeError, ValueError):
|
69 |
+
return True
|
70 |
+
|
71 |
+
|
72 |
+
class AnsiToWin32(object):
|
73 |
+
'''
|
74 |
+
Implements a 'write()' method which, on Windows, will strip ANSI character
|
75 |
+
sequences from the text, and if outputting to a tty, will convert them into
|
76 |
+
win32 function calls.
|
77 |
+
'''
|
78 |
+
ANSI_CSI_RE = re.compile('\001?\033\\[((?:\\d|;)*)([a-zA-Z])\002?') # Control Sequence Introducer
|
79 |
+
ANSI_OSC_RE = re.compile('\001?\033\\]([^\a]*)(\a)\002?') # Operating System Command
|
80 |
+
|
81 |
+
def __init__(self, wrapped, convert=None, strip=None, autoreset=False):
|
82 |
+
# The wrapped stream (normally sys.stdout or sys.stderr)
|
83 |
+
self.wrapped = wrapped
|
84 |
+
|
85 |
+
# should we reset colors to defaults after every .write()
|
86 |
+
self.autoreset = autoreset
|
87 |
+
|
88 |
+
# create the proxy wrapping our output stream
|
89 |
+
self.stream = StreamWrapper(wrapped, self)
|
90 |
+
|
91 |
+
on_windows = os.name == 'nt'
|
92 |
+
# We test if the WinAPI works, because even if we are on Windows
|
93 |
+
# we may be using a terminal that doesn't support the WinAPI
|
94 |
+
# (e.g. Cygwin Terminal). In this case it's up to the terminal
|
95 |
+
# to support the ANSI codes.
|
96 |
+
conversion_supported = on_windows and winapi_test()
|
97 |
+
try:
|
98 |
+
fd = wrapped.fileno()
|
99 |
+
except Exception:
|
100 |
+
fd = -1
|
101 |
+
system_has_native_ansi = not on_windows or enable_vt_processing(fd)
|
102 |
+
have_tty = not self.stream.closed and self.stream.isatty()
|
103 |
+
need_conversion = conversion_supported and not system_has_native_ansi
|
104 |
+
|
105 |
+
# should we strip ANSI sequences from our output?
|
106 |
+
if strip is None:
|
107 |
+
strip = need_conversion or not have_tty
|
108 |
+
self.strip = strip
|
109 |
+
|
110 |
+
# should we should convert ANSI sequences into win32 calls?
|
111 |
+
if convert is None:
|
112 |
+
convert = need_conversion and have_tty
|
113 |
+
self.convert = convert
|
114 |
+
|
115 |
+
# dict of ansi codes to win32 functions and parameters
|
116 |
+
self.win32_calls = self.get_win32_calls()
|
117 |
+
|
118 |
+
# are we wrapping stderr?
|
119 |
+
self.on_stderr = self.wrapped is sys.stderr
|
120 |
+
|
121 |
+
def should_wrap(self):
|
122 |
+
'''
|
123 |
+
True if this class is actually needed. If false, then the output
|
124 |
+
stream will not be affected, nor will win32 calls be issued, so
|
125 |
+
wrapping stdout is not actually required. This will generally be
|
126 |
+
False on non-Windows platforms, unless optional functionality like
|
127 |
+
autoreset has been requested using kwargs to init()
|
128 |
+
'''
|
129 |
+
return self.convert or self.strip or self.autoreset
|
130 |
+
|
131 |
+
def get_win32_calls(self):
|
132 |
+
if self.convert and winterm:
|
133 |
+
return {
|
134 |
+
AnsiStyle.RESET_ALL: (winterm.reset_all, ),
|
135 |
+
AnsiStyle.BRIGHT: (winterm.style, WinStyle.BRIGHT),
|
136 |
+
AnsiStyle.DIM: (winterm.style, WinStyle.NORMAL),
|
137 |
+
AnsiStyle.NORMAL: (winterm.style, WinStyle.NORMAL),
|
138 |
+
AnsiFore.BLACK: (winterm.fore, WinColor.BLACK),
|
139 |
+
AnsiFore.RED: (winterm.fore, WinColor.RED),
|
140 |
+
AnsiFore.GREEN: (winterm.fore, WinColor.GREEN),
|
141 |
+
AnsiFore.YELLOW: (winterm.fore, WinColor.YELLOW),
|
142 |
+
AnsiFore.BLUE: (winterm.fore, WinColor.BLUE),
|
143 |
+
AnsiFore.MAGENTA: (winterm.fore, WinColor.MAGENTA),
|
144 |
+
AnsiFore.CYAN: (winterm.fore, WinColor.CYAN),
|
145 |
+
AnsiFore.WHITE: (winterm.fore, WinColor.GREY),
|
146 |
+
AnsiFore.RESET: (winterm.fore, ),
|
147 |
+
AnsiFore.LIGHTBLACK_EX: (winterm.fore, WinColor.BLACK, True),
|
148 |
+
AnsiFore.LIGHTRED_EX: (winterm.fore, WinColor.RED, True),
|
149 |
+
AnsiFore.LIGHTGREEN_EX: (winterm.fore, WinColor.GREEN, True),
|
150 |
+
AnsiFore.LIGHTYELLOW_EX: (winterm.fore, WinColor.YELLOW, True),
|
151 |
+
AnsiFore.LIGHTBLUE_EX: (winterm.fore, WinColor.BLUE, True),
|
152 |
+
AnsiFore.LIGHTMAGENTA_EX: (winterm.fore, WinColor.MAGENTA, True),
|
153 |
+
AnsiFore.LIGHTCYAN_EX: (winterm.fore, WinColor.CYAN, True),
|
154 |
+
AnsiFore.LIGHTWHITE_EX: (winterm.fore, WinColor.GREY, True),
|
155 |
+
AnsiBack.BLACK: (winterm.back, WinColor.BLACK),
|
156 |
+
AnsiBack.RED: (winterm.back, WinColor.RED),
|
157 |
+
AnsiBack.GREEN: (winterm.back, WinColor.GREEN),
|
158 |
+
AnsiBack.YELLOW: (winterm.back, WinColor.YELLOW),
|
159 |
+
AnsiBack.BLUE: (winterm.back, WinColor.BLUE),
|
160 |
+
AnsiBack.MAGENTA: (winterm.back, WinColor.MAGENTA),
|
161 |
+
AnsiBack.CYAN: (winterm.back, WinColor.CYAN),
|
162 |
+
AnsiBack.WHITE: (winterm.back, WinColor.GREY),
|
163 |
+
AnsiBack.RESET: (winterm.back, ),
|
164 |
+
AnsiBack.LIGHTBLACK_EX: (winterm.back, WinColor.BLACK, True),
|
165 |
+
AnsiBack.LIGHTRED_EX: (winterm.back, WinColor.RED, True),
|
166 |
+
AnsiBack.LIGHTGREEN_EX: (winterm.back, WinColor.GREEN, True),
|
167 |
+
AnsiBack.LIGHTYELLOW_EX: (winterm.back, WinColor.YELLOW, True),
|
168 |
+
AnsiBack.LIGHTBLUE_EX: (winterm.back, WinColor.BLUE, True),
|
169 |
+
AnsiBack.LIGHTMAGENTA_EX: (winterm.back, WinColor.MAGENTA, True),
|
170 |
+
AnsiBack.LIGHTCYAN_EX: (winterm.back, WinColor.CYAN, True),
|
171 |
+
AnsiBack.LIGHTWHITE_EX: (winterm.back, WinColor.GREY, True),
|
172 |
+
}
|
173 |
+
return dict()
|
174 |
+
|
175 |
+
def write(self, text):
|
176 |
+
if self.strip or self.convert:
|
177 |
+
self.write_and_convert(text)
|
178 |
+
else:
|
179 |
+
self.wrapped.write(text)
|
180 |
+
self.wrapped.flush()
|
181 |
+
if self.autoreset:
|
182 |
+
self.reset_all()
|
183 |
+
|
184 |
+
|
185 |
+
def reset_all(self):
|
186 |
+
if self.convert:
|
187 |
+
self.call_win32('m', (0,))
|
188 |
+
elif not self.strip and not self.stream.closed:
|
189 |
+
self.wrapped.write(Style.RESET_ALL)
|
190 |
+
|
191 |
+
|
192 |
+
def write_and_convert(self, text):
|
193 |
+
'''
|
194 |
+
Write the given text to our wrapped stream, stripping any ANSI
|
195 |
+
sequences from the text, and optionally converting them into win32
|
196 |
+
calls.
|
197 |
+
'''
|
198 |
+
cursor = 0
|
199 |
+
text = self.convert_osc(text)
|
200 |
+
for match in self.ANSI_CSI_RE.finditer(text):
|
201 |
+
start, end = match.span()
|
202 |
+
self.write_plain_text(text, cursor, start)
|
203 |
+
self.convert_ansi(*match.groups())
|
204 |
+
cursor = end
|
205 |
+
self.write_plain_text(text, cursor, len(text))
|
206 |
+
|
207 |
+
|
208 |
+
def write_plain_text(self, text, start, end):
|
209 |
+
if start < end:
|
210 |
+
self.wrapped.write(text[start:end])
|
211 |
+
self.wrapped.flush()
|
212 |
+
|
213 |
+
|
214 |
+
def convert_ansi(self, paramstring, command):
|
215 |
+
if self.convert:
|
216 |
+
params = self.extract_params(command, paramstring)
|
217 |
+
self.call_win32(command, params)
|
218 |
+
|
219 |
+
|
220 |
+
def extract_params(self, command, paramstring):
|
221 |
+
if command in 'Hf':
|
222 |
+
params = tuple(int(p) if len(p) != 0 else 1 for p in paramstring.split(';'))
|
223 |
+
while len(params) < 2:
|
224 |
+
# defaults:
|
225 |
+
params = params + (1,)
|
226 |
+
else:
|
227 |
+
params = tuple(int(p) for p in paramstring.split(';') if len(p) != 0)
|
228 |
+
if len(params) == 0:
|
229 |
+
# defaults:
|
230 |
+
if command in 'JKm':
|
231 |
+
params = (0,)
|
232 |
+
elif command in 'ABCD':
|
233 |
+
params = (1,)
|
234 |
+
|
235 |
+
return params
|
236 |
+
|
237 |
+
|
238 |
+
def call_win32(self, command, params):
|
239 |
+
if command == 'm':
|
240 |
+
for param in params:
|
241 |
+
if param in self.win32_calls:
|
242 |
+
func_args = self.win32_calls[param]
|
243 |
+
func = func_args[0]
|
244 |
+
args = func_args[1:]
|
245 |
+
kwargs = dict(on_stderr=self.on_stderr)
|
246 |
+
func(*args, **kwargs)
|
247 |
+
elif command in 'J':
|
248 |
+
winterm.erase_screen(params[0], on_stderr=self.on_stderr)
|
249 |
+
elif command in 'K':
|
250 |
+
winterm.erase_line(params[0], on_stderr=self.on_stderr)
|
251 |
+
elif command in 'Hf': # cursor position - absolute
|
252 |
+
winterm.set_cursor_position(params, on_stderr=self.on_stderr)
|
253 |
+
elif command in 'ABCD': # cursor position - relative
|
254 |
+
n = params[0]
|
255 |
+
# A - up, B - down, C - forward, D - back
|
256 |
+
x, y = {'A': (0, -n), 'B': (0, n), 'C': (n, 0), 'D': (-n, 0)}[command]
|
257 |
+
winterm.cursor_adjust(x, y, on_stderr=self.on_stderr)
|
258 |
+
|
259 |
+
|
260 |
+
def convert_osc(self, text):
|
261 |
+
for match in self.ANSI_OSC_RE.finditer(text):
|
262 |
+
start, end = match.span()
|
263 |
+
text = text[:start] + text[end:]
|
264 |
+
paramstring, command = match.groups()
|
265 |
+
if command == BEL:
|
266 |
+
if paramstring.count(";") == 1:
|
267 |
+
params = paramstring.split(";")
|
268 |
+
# 0 - change title and icon (we will only change title)
|
269 |
+
# 1 - change icon (we don't support this)
|
270 |
+
# 2 - change title
|
271 |
+
if params[0] in '02':
|
272 |
+
winterm.set_title(params[1])
|
273 |
+
return text
|
274 |
+
|
275 |
+
|
276 |
+
def flush(self):
|
277 |
+
self.wrapped.flush()
|
env-llmeval/lib/python3.10/site-packages/colorama/initialise.py
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
import atexit
|
3 |
+
import contextlib
|
4 |
+
import sys
|
5 |
+
|
6 |
+
from .ansitowin32 import AnsiToWin32
|
7 |
+
|
8 |
+
|
9 |
+
def _wipe_internal_state_for_tests():
|
10 |
+
global orig_stdout, orig_stderr
|
11 |
+
orig_stdout = None
|
12 |
+
orig_stderr = None
|
13 |
+
|
14 |
+
global wrapped_stdout, wrapped_stderr
|
15 |
+
wrapped_stdout = None
|
16 |
+
wrapped_stderr = None
|
17 |
+
|
18 |
+
global atexit_done
|
19 |
+
atexit_done = False
|
20 |
+
|
21 |
+
global fixed_windows_console
|
22 |
+
fixed_windows_console = False
|
23 |
+
|
24 |
+
try:
|
25 |
+
# no-op if it wasn't registered
|
26 |
+
atexit.unregister(reset_all)
|
27 |
+
except AttributeError:
|
28 |
+
# python 2: no atexit.unregister. Oh well, we did our best.
|
29 |
+
pass
|
30 |
+
|
31 |
+
|
32 |
+
def reset_all():
|
33 |
+
if AnsiToWin32 is not None: # Issue #74: objects might become None at exit
|
34 |
+
AnsiToWin32(orig_stdout).reset_all()
|
35 |
+
|
36 |
+
|
37 |
+
def init(autoreset=False, convert=None, strip=None, wrap=True):
|
38 |
+
|
39 |
+
if not wrap and any([autoreset, convert, strip]):
|
40 |
+
raise ValueError('wrap=False conflicts with any other arg=True')
|
41 |
+
|
42 |
+
global wrapped_stdout, wrapped_stderr
|
43 |
+
global orig_stdout, orig_stderr
|
44 |
+
|
45 |
+
orig_stdout = sys.stdout
|
46 |
+
orig_stderr = sys.stderr
|
47 |
+
|
48 |
+
if sys.stdout is None:
|
49 |
+
wrapped_stdout = None
|
50 |
+
else:
|
51 |
+
sys.stdout = wrapped_stdout = \
|
52 |
+
wrap_stream(orig_stdout, convert, strip, autoreset, wrap)
|
53 |
+
if sys.stderr is None:
|
54 |
+
wrapped_stderr = None
|
55 |
+
else:
|
56 |
+
sys.stderr = wrapped_stderr = \
|
57 |
+
wrap_stream(orig_stderr, convert, strip, autoreset, wrap)
|
58 |
+
|
59 |
+
global atexit_done
|
60 |
+
if not atexit_done:
|
61 |
+
atexit.register(reset_all)
|
62 |
+
atexit_done = True
|
63 |
+
|
64 |
+
|
65 |
+
def deinit():
|
66 |
+
if orig_stdout is not None:
|
67 |
+
sys.stdout = orig_stdout
|
68 |
+
if orig_stderr is not None:
|
69 |
+
sys.stderr = orig_stderr
|
70 |
+
|
71 |
+
|
72 |
+
def just_fix_windows_console():
|
73 |
+
global fixed_windows_console
|
74 |
+
|
75 |
+
if sys.platform != "win32":
|
76 |
+
return
|
77 |
+
if fixed_windows_console:
|
78 |
+
return
|
79 |
+
if wrapped_stdout is not None or wrapped_stderr is not None:
|
80 |
+
# Someone already ran init() and it did stuff, so we won't second-guess them
|
81 |
+
return
|
82 |
+
|
83 |
+
# On newer versions of Windows, AnsiToWin32.__init__ will implicitly enable the
|
84 |
+
# native ANSI support in the console as a side-effect. We only need to actually
|
85 |
+
# replace sys.stdout/stderr if we're in the old-style conversion mode.
|
86 |
+
new_stdout = AnsiToWin32(sys.stdout, convert=None, strip=None, autoreset=False)
|
87 |
+
if new_stdout.convert:
|
88 |
+
sys.stdout = new_stdout
|
89 |
+
new_stderr = AnsiToWin32(sys.stderr, convert=None, strip=None, autoreset=False)
|
90 |
+
if new_stderr.convert:
|
91 |
+
sys.stderr = new_stderr
|
92 |
+
|
93 |
+
fixed_windows_console = True
|
94 |
+
|
95 |
+
@contextlib.contextmanager
|
96 |
+
def colorama_text(*args, **kwargs):
|
97 |
+
init(*args, **kwargs)
|
98 |
+
try:
|
99 |
+
yield
|
100 |
+
finally:
|
101 |
+
deinit()
|
102 |
+
|
103 |
+
|
104 |
+
def reinit():
|
105 |
+
if wrapped_stdout is not None:
|
106 |
+
sys.stdout = wrapped_stdout
|
107 |
+
if wrapped_stderr is not None:
|
108 |
+
sys.stderr = wrapped_stderr
|
109 |
+
|
110 |
+
|
111 |
+
def wrap_stream(stream, convert, strip, autoreset, wrap):
|
112 |
+
if wrap:
|
113 |
+
wrapper = AnsiToWin32(stream,
|
114 |
+
convert=convert, strip=strip, autoreset=autoreset)
|
115 |
+
if wrapper.should_wrap():
|
116 |
+
stream = wrapper.stream
|
117 |
+
return stream
|
118 |
+
|
119 |
+
|
120 |
+
# Use this for initial setup as well, to reduce code duplication
|
121 |
+
_wipe_internal_state_for_tests()
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (179 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/ansi_test.cpython-310.pyc
ADDED
Binary file (2.27 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/ansitowin32_test.cpython-310.pyc
ADDED
Binary file (11.6 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/initialise_test.cpython-310.pyc
ADDED
Binary file (6.88 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/isatty_test.cpython-310.pyc
ADDED
Binary file (2.67 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/utils.cpython-310.pyc
ADDED
Binary file (1.58 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/__pycache__/winterm_test.cpython-310.pyc
ADDED
Binary file (3.17 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/ansi_test.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
import sys
|
3 |
+
from unittest import TestCase, main
|
4 |
+
|
5 |
+
from ..ansi import Back, Fore, Style
|
6 |
+
from ..ansitowin32 import AnsiToWin32
|
7 |
+
|
8 |
+
stdout_orig = sys.stdout
|
9 |
+
stderr_orig = sys.stderr
|
10 |
+
|
11 |
+
|
12 |
+
class AnsiTest(TestCase):
|
13 |
+
|
14 |
+
def setUp(self):
|
15 |
+
# sanity check: stdout should be a file or StringIO object.
|
16 |
+
# It will only be AnsiToWin32 if init() has previously wrapped it
|
17 |
+
self.assertNotEqual(type(sys.stdout), AnsiToWin32)
|
18 |
+
self.assertNotEqual(type(sys.stderr), AnsiToWin32)
|
19 |
+
|
20 |
+
def tearDown(self):
|
21 |
+
sys.stdout = stdout_orig
|
22 |
+
sys.stderr = stderr_orig
|
23 |
+
|
24 |
+
|
25 |
+
def testForeAttributes(self):
|
26 |
+
self.assertEqual(Fore.BLACK, '\033[30m')
|
27 |
+
self.assertEqual(Fore.RED, '\033[31m')
|
28 |
+
self.assertEqual(Fore.GREEN, '\033[32m')
|
29 |
+
self.assertEqual(Fore.YELLOW, '\033[33m')
|
30 |
+
self.assertEqual(Fore.BLUE, '\033[34m')
|
31 |
+
self.assertEqual(Fore.MAGENTA, '\033[35m')
|
32 |
+
self.assertEqual(Fore.CYAN, '\033[36m')
|
33 |
+
self.assertEqual(Fore.WHITE, '\033[37m')
|
34 |
+
self.assertEqual(Fore.RESET, '\033[39m')
|
35 |
+
|
36 |
+
# Check the light, extended versions.
|
37 |
+
self.assertEqual(Fore.LIGHTBLACK_EX, '\033[90m')
|
38 |
+
self.assertEqual(Fore.LIGHTRED_EX, '\033[91m')
|
39 |
+
self.assertEqual(Fore.LIGHTGREEN_EX, '\033[92m')
|
40 |
+
self.assertEqual(Fore.LIGHTYELLOW_EX, '\033[93m')
|
41 |
+
self.assertEqual(Fore.LIGHTBLUE_EX, '\033[94m')
|
42 |
+
self.assertEqual(Fore.LIGHTMAGENTA_EX, '\033[95m')
|
43 |
+
self.assertEqual(Fore.LIGHTCYAN_EX, '\033[96m')
|
44 |
+
self.assertEqual(Fore.LIGHTWHITE_EX, '\033[97m')
|
45 |
+
|
46 |
+
|
47 |
+
def testBackAttributes(self):
|
48 |
+
self.assertEqual(Back.BLACK, '\033[40m')
|
49 |
+
self.assertEqual(Back.RED, '\033[41m')
|
50 |
+
self.assertEqual(Back.GREEN, '\033[42m')
|
51 |
+
self.assertEqual(Back.YELLOW, '\033[43m')
|
52 |
+
self.assertEqual(Back.BLUE, '\033[44m')
|
53 |
+
self.assertEqual(Back.MAGENTA, '\033[45m')
|
54 |
+
self.assertEqual(Back.CYAN, '\033[46m')
|
55 |
+
self.assertEqual(Back.WHITE, '\033[47m')
|
56 |
+
self.assertEqual(Back.RESET, '\033[49m')
|
57 |
+
|
58 |
+
# Check the light, extended versions.
|
59 |
+
self.assertEqual(Back.LIGHTBLACK_EX, '\033[100m')
|
60 |
+
self.assertEqual(Back.LIGHTRED_EX, '\033[101m')
|
61 |
+
self.assertEqual(Back.LIGHTGREEN_EX, '\033[102m')
|
62 |
+
self.assertEqual(Back.LIGHTYELLOW_EX, '\033[103m')
|
63 |
+
self.assertEqual(Back.LIGHTBLUE_EX, '\033[104m')
|
64 |
+
self.assertEqual(Back.LIGHTMAGENTA_EX, '\033[105m')
|
65 |
+
self.assertEqual(Back.LIGHTCYAN_EX, '\033[106m')
|
66 |
+
self.assertEqual(Back.LIGHTWHITE_EX, '\033[107m')
|
67 |
+
|
68 |
+
|
69 |
+
def testStyleAttributes(self):
|
70 |
+
self.assertEqual(Style.DIM, '\033[2m')
|
71 |
+
self.assertEqual(Style.NORMAL, '\033[22m')
|
72 |
+
self.assertEqual(Style.BRIGHT, '\033[1m')
|
73 |
+
|
74 |
+
|
75 |
+
if __name__ == '__main__':
|
76 |
+
main()
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/ansitowin32_test.py
ADDED
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
from io import StringIO, TextIOWrapper
|
3 |
+
from unittest import TestCase, main
|
4 |
+
try:
|
5 |
+
from contextlib import ExitStack
|
6 |
+
except ImportError:
|
7 |
+
# python 2
|
8 |
+
from contextlib2 import ExitStack
|
9 |
+
|
10 |
+
try:
|
11 |
+
from unittest.mock import MagicMock, Mock, patch
|
12 |
+
except ImportError:
|
13 |
+
from mock import MagicMock, Mock, patch
|
14 |
+
|
15 |
+
from ..ansitowin32 import AnsiToWin32, StreamWrapper
|
16 |
+
from ..win32 import ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
17 |
+
from .utils import osname
|
18 |
+
|
19 |
+
|
20 |
+
class StreamWrapperTest(TestCase):
|
21 |
+
|
22 |
+
def testIsAProxy(self):
|
23 |
+
mockStream = Mock()
|
24 |
+
wrapper = StreamWrapper(mockStream, None)
|
25 |
+
self.assertTrue( wrapper.random_attr is mockStream.random_attr )
|
26 |
+
|
27 |
+
def testDelegatesWrite(self):
|
28 |
+
mockStream = Mock()
|
29 |
+
mockConverter = Mock()
|
30 |
+
wrapper = StreamWrapper(mockStream, mockConverter)
|
31 |
+
wrapper.write('hello')
|
32 |
+
self.assertTrue(mockConverter.write.call_args, (('hello',), {}))
|
33 |
+
|
34 |
+
def testDelegatesContext(self):
|
35 |
+
mockConverter = Mock()
|
36 |
+
s = StringIO()
|
37 |
+
with StreamWrapper(s, mockConverter) as fp:
|
38 |
+
fp.write(u'hello')
|
39 |
+
self.assertTrue(s.closed)
|
40 |
+
|
41 |
+
def testProxyNoContextManager(self):
|
42 |
+
mockStream = MagicMock()
|
43 |
+
mockStream.__enter__.side_effect = AttributeError()
|
44 |
+
mockConverter = Mock()
|
45 |
+
with self.assertRaises(AttributeError) as excinfo:
|
46 |
+
with StreamWrapper(mockStream, mockConverter) as wrapper:
|
47 |
+
wrapper.write('hello')
|
48 |
+
|
49 |
+
def test_closed_shouldnt_raise_on_closed_stream(self):
|
50 |
+
stream = StringIO()
|
51 |
+
stream.close()
|
52 |
+
wrapper = StreamWrapper(stream, None)
|
53 |
+
self.assertEqual(wrapper.closed, True)
|
54 |
+
|
55 |
+
def test_closed_shouldnt_raise_on_detached_stream(self):
|
56 |
+
stream = TextIOWrapper(StringIO())
|
57 |
+
stream.detach()
|
58 |
+
wrapper = StreamWrapper(stream, None)
|
59 |
+
self.assertEqual(wrapper.closed, True)
|
60 |
+
|
61 |
+
class AnsiToWin32Test(TestCase):
|
62 |
+
|
63 |
+
def testInit(self):
|
64 |
+
mockStdout = Mock()
|
65 |
+
auto = Mock()
|
66 |
+
stream = AnsiToWin32(mockStdout, autoreset=auto)
|
67 |
+
self.assertEqual(stream.wrapped, mockStdout)
|
68 |
+
self.assertEqual(stream.autoreset, auto)
|
69 |
+
|
70 |
+
@patch('colorama.ansitowin32.winterm', None)
|
71 |
+
@patch('colorama.ansitowin32.winapi_test', lambda *_: True)
|
72 |
+
def testStripIsTrueOnWindows(self):
|
73 |
+
with osname('nt'):
|
74 |
+
mockStdout = Mock()
|
75 |
+
stream = AnsiToWin32(mockStdout)
|
76 |
+
self.assertTrue(stream.strip)
|
77 |
+
|
78 |
+
def testStripIsFalseOffWindows(self):
|
79 |
+
with osname('posix'):
|
80 |
+
mockStdout = Mock(closed=False)
|
81 |
+
stream = AnsiToWin32(mockStdout)
|
82 |
+
self.assertFalse(stream.strip)
|
83 |
+
|
84 |
+
def testWriteStripsAnsi(self):
|
85 |
+
mockStdout = Mock()
|
86 |
+
stream = AnsiToWin32(mockStdout)
|
87 |
+
stream.wrapped = Mock()
|
88 |
+
stream.write_and_convert = Mock()
|
89 |
+
stream.strip = True
|
90 |
+
|
91 |
+
stream.write('abc')
|
92 |
+
|
93 |
+
self.assertFalse(stream.wrapped.write.called)
|
94 |
+
self.assertEqual(stream.write_and_convert.call_args, (('abc',), {}))
|
95 |
+
|
96 |
+
def testWriteDoesNotStripAnsi(self):
|
97 |
+
mockStdout = Mock()
|
98 |
+
stream = AnsiToWin32(mockStdout)
|
99 |
+
stream.wrapped = Mock()
|
100 |
+
stream.write_and_convert = Mock()
|
101 |
+
stream.strip = False
|
102 |
+
stream.convert = False
|
103 |
+
|
104 |
+
stream.write('abc')
|
105 |
+
|
106 |
+
self.assertFalse(stream.write_and_convert.called)
|
107 |
+
self.assertEqual(stream.wrapped.write.call_args, (('abc',), {}))
|
108 |
+
|
109 |
+
def assert_autoresets(self, convert, autoreset=True):
|
110 |
+
stream = AnsiToWin32(Mock())
|
111 |
+
stream.convert = convert
|
112 |
+
stream.reset_all = Mock()
|
113 |
+
stream.autoreset = autoreset
|
114 |
+
stream.winterm = Mock()
|
115 |
+
|
116 |
+
stream.write('abc')
|
117 |
+
|
118 |
+
self.assertEqual(stream.reset_all.called, autoreset)
|
119 |
+
|
120 |
+
def testWriteAutoresets(self):
|
121 |
+
self.assert_autoresets(convert=True)
|
122 |
+
self.assert_autoresets(convert=False)
|
123 |
+
self.assert_autoresets(convert=True, autoreset=False)
|
124 |
+
self.assert_autoresets(convert=False, autoreset=False)
|
125 |
+
|
126 |
+
def testWriteAndConvertWritesPlainText(self):
|
127 |
+
stream = AnsiToWin32(Mock())
|
128 |
+
stream.write_and_convert( 'abc' )
|
129 |
+
self.assertEqual( stream.wrapped.write.call_args, (('abc',), {}) )
|
130 |
+
|
131 |
+
def testWriteAndConvertStripsAllValidAnsi(self):
|
132 |
+
stream = AnsiToWin32(Mock())
|
133 |
+
stream.call_win32 = Mock()
|
134 |
+
data = [
|
135 |
+
'abc\033[mdef',
|
136 |
+
'abc\033[0mdef',
|
137 |
+
'abc\033[2mdef',
|
138 |
+
'abc\033[02mdef',
|
139 |
+
'abc\033[002mdef',
|
140 |
+
'abc\033[40mdef',
|
141 |
+
'abc\033[040mdef',
|
142 |
+
'abc\033[0;1mdef',
|
143 |
+
'abc\033[40;50mdef',
|
144 |
+
'abc\033[50;30;40mdef',
|
145 |
+
'abc\033[Adef',
|
146 |
+
'abc\033[0Gdef',
|
147 |
+
'abc\033[1;20;128Hdef',
|
148 |
+
]
|
149 |
+
for datum in data:
|
150 |
+
stream.wrapped.write.reset_mock()
|
151 |
+
stream.write_and_convert( datum )
|
152 |
+
self.assertEqual(
|
153 |
+
[args[0] for args in stream.wrapped.write.call_args_list],
|
154 |
+
[ ('abc',), ('def',) ]
|
155 |
+
)
|
156 |
+
|
157 |
+
def testWriteAndConvertSkipsEmptySnippets(self):
|
158 |
+
stream = AnsiToWin32(Mock())
|
159 |
+
stream.call_win32 = Mock()
|
160 |
+
stream.write_and_convert( '\033[40m\033[41m' )
|
161 |
+
self.assertFalse( stream.wrapped.write.called )
|
162 |
+
|
163 |
+
def testWriteAndConvertCallsWin32WithParamsAndCommand(self):
|
164 |
+
stream = AnsiToWin32(Mock())
|
165 |
+
stream.convert = True
|
166 |
+
stream.call_win32 = Mock()
|
167 |
+
stream.extract_params = Mock(return_value='params')
|
168 |
+
data = {
|
169 |
+
'abc\033[adef': ('a', 'params'),
|
170 |
+
'abc\033[;;bdef': ('b', 'params'),
|
171 |
+
'abc\033[0cdef': ('c', 'params'),
|
172 |
+
'abc\033[;;0;;Gdef': ('G', 'params'),
|
173 |
+
'abc\033[1;20;128Hdef': ('H', 'params'),
|
174 |
+
}
|
175 |
+
for datum, expected in data.items():
|
176 |
+
stream.call_win32.reset_mock()
|
177 |
+
stream.write_and_convert( datum )
|
178 |
+
self.assertEqual( stream.call_win32.call_args[0], expected )
|
179 |
+
|
180 |
+
def test_reset_all_shouldnt_raise_on_closed_orig_stdout(self):
|
181 |
+
stream = StringIO()
|
182 |
+
converter = AnsiToWin32(stream)
|
183 |
+
stream.close()
|
184 |
+
|
185 |
+
converter.reset_all()
|
186 |
+
|
187 |
+
def test_wrap_shouldnt_raise_on_closed_orig_stdout(self):
|
188 |
+
stream = StringIO()
|
189 |
+
stream.close()
|
190 |
+
with \
|
191 |
+
patch("colorama.ansitowin32.os.name", "nt"), \
|
192 |
+
patch("colorama.ansitowin32.winapi_test", lambda: True):
|
193 |
+
converter = AnsiToWin32(stream)
|
194 |
+
self.assertTrue(converter.strip)
|
195 |
+
self.assertFalse(converter.convert)
|
196 |
+
|
197 |
+
def test_wrap_shouldnt_raise_on_missing_closed_attr(self):
|
198 |
+
with \
|
199 |
+
patch("colorama.ansitowin32.os.name", "nt"), \
|
200 |
+
patch("colorama.ansitowin32.winapi_test", lambda: True):
|
201 |
+
converter = AnsiToWin32(object())
|
202 |
+
self.assertTrue(converter.strip)
|
203 |
+
self.assertFalse(converter.convert)
|
204 |
+
|
205 |
+
def testExtractParams(self):
|
206 |
+
stream = AnsiToWin32(Mock())
|
207 |
+
data = {
|
208 |
+
'': (0,),
|
209 |
+
';;': (0,),
|
210 |
+
'2': (2,),
|
211 |
+
';;002;;': (2,),
|
212 |
+
'0;1': (0, 1),
|
213 |
+
';;003;;456;;': (3, 456),
|
214 |
+
'11;22;33;44;55': (11, 22, 33, 44, 55),
|
215 |
+
}
|
216 |
+
for datum, expected in data.items():
|
217 |
+
self.assertEqual(stream.extract_params('m', datum), expected)
|
218 |
+
|
219 |
+
def testCallWin32UsesLookup(self):
|
220 |
+
listener = Mock()
|
221 |
+
stream = AnsiToWin32(listener)
|
222 |
+
stream.win32_calls = {
|
223 |
+
1: (lambda *_, **__: listener(11),),
|
224 |
+
2: (lambda *_, **__: listener(22),),
|
225 |
+
3: (lambda *_, **__: listener(33),),
|
226 |
+
}
|
227 |
+
stream.call_win32('m', (3, 1, 99, 2))
|
228 |
+
self.assertEqual(
|
229 |
+
[a[0][0] for a in listener.call_args_list],
|
230 |
+
[33, 11, 22] )
|
231 |
+
|
232 |
+
def test_osc_codes(self):
|
233 |
+
mockStdout = Mock()
|
234 |
+
stream = AnsiToWin32(mockStdout, convert=True)
|
235 |
+
with patch('colorama.ansitowin32.winterm') as winterm:
|
236 |
+
data = [
|
237 |
+
'\033]0\x07', # missing arguments
|
238 |
+
'\033]0;foo\x08', # wrong OSC command
|
239 |
+
'\033]0;colorama_test_title\x07', # should work
|
240 |
+
'\033]1;colorama_test_title\x07', # wrong set command
|
241 |
+
'\033]2;colorama_test_title\x07', # should work
|
242 |
+
'\033]' + ';' * 64 + '\x08', # see issue #247
|
243 |
+
]
|
244 |
+
for code in data:
|
245 |
+
stream.write(code)
|
246 |
+
self.assertEqual(winterm.set_title.call_count, 2)
|
247 |
+
|
248 |
+
def test_native_windows_ansi(self):
|
249 |
+
with ExitStack() as stack:
|
250 |
+
def p(a, b):
|
251 |
+
stack.enter_context(patch(a, b, create=True))
|
252 |
+
# Pretend to be on Windows
|
253 |
+
p("colorama.ansitowin32.os.name", "nt")
|
254 |
+
p("colorama.ansitowin32.winapi_test", lambda: True)
|
255 |
+
p("colorama.win32.winapi_test", lambda: True)
|
256 |
+
p("colorama.winterm.win32.windll", "non-None")
|
257 |
+
p("colorama.winterm.get_osfhandle", lambda _: 1234)
|
258 |
+
|
259 |
+
# Pretend that our mock stream has native ANSI support
|
260 |
+
p(
|
261 |
+
"colorama.winterm.win32.GetConsoleMode",
|
262 |
+
lambda _: ENABLE_VIRTUAL_TERMINAL_PROCESSING,
|
263 |
+
)
|
264 |
+
SetConsoleMode = Mock()
|
265 |
+
p("colorama.winterm.win32.SetConsoleMode", SetConsoleMode)
|
266 |
+
|
267 |
+
stdout = Mock()
|
268 |
+
stdout.closed = False
|
269 |
+
stdout.isatty.return_value = True
|
270 |
+
stdout.fileno.return_value = 1
|
271 |
+
|
272 |
+
# Our fake console says it has native vt support, so AnsiToWin32 should
|
273 |
+
# enable that support and do nothing else.
|
274 |
+
stream = AnsiToWin32(stdout)
|
275 |
+
SetConsoleMode.assert_called_with(1234, ENABLE_VIRTUAL_TERMINAL_PROCESSING)
|
276 |
+
self.assertFalse(stream.strip)
|
277 |
+
self.assertFalse(stream.convert)
|
278 |
+
self.assertFalse(stream.should_wrap())
|
279 |
+
|
280 |
+
# Now let's pretend we're on an old Windows console, that doesn't have
|
281 |
+
# native ANSI support.
|
282 |
+
p("colorama.winterm.win32.GetConsoleMode", lambda _: 0)
|
283 |
+
SetConsoleMode = Mock()
|
284 |
+
p("colorama.winterm.win32.SetConsoleMode", SetConsoleMode)
|
285 |
+
|
286 |
+
stream = AnsiToWin32(stdout)
|
287 |
+
SetConsoleMode.assert_called_with(1234, ENABLE_VIRTUAL_TERMINAL_PROCESSING)
|
288 |
+
self.assertTrue(stream.strip)
|
289 |
+
self.assertTrue(stream.convert)
|
290 |
+
self.assertTrue(stream.should_wrap())
|
291 |
+
|
292 |
+
|
293 |
+
if __name__ == '__main__':
|
294 |
+
main()
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/initialise_test.py
ADDED
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
import sys
|
3 |
+
from unittest import TestCase, main, skipUnless
|
4 |
+
|
5 |
+
try:
|
6 |
+
from unittest.mock import patch, Mock
|
7 |
+
except ImportError:
|
8 |
+
from mock import patch, Mock
|
9 |
+
|
10 |
+
from ..ansitowin32 import StreamWrapper
|
11 |
+
from ..initialise import init, just_fix_windows_console, _wipe_internal_state_for_tests
|
12 |
+
from .utils import osname, replace_by
|
13 |
+
|
14 |
+
orig_stdout = sys.stdout
|
15 |
+
orig_stderr = sys.stderr
|
16 |
+
|
17 |
+
|
18 |
+
class InitTest(TestCase):
|
19 |
+
|
20 |
+
@skipUnless(sys.stdout.isatty(), "sys.stdout is not a tty")
|
21 |
+
def setUp(self):
|
22 |
+
# sanity check
|
23 |
+
self.assertNotWrapped()
|
24 |
+
|
25 |
+
def tearDown(self):
|
26 |
+
_wipe_internal_state_for_tests()
|
27 |
+
sys.stdout = orig_stdout
|
28 |
+
sys.stderr = orig_stderr
|
29 |
+
|
30 |
+
def assertWrapped(self):
|
31 |
+
self.assertIsNot(sys.stdout, orig_stdout, 'stdout should be wrapped')
|
32 |
+
self.assertIsNot(sys.stderr, orig_stderr, 'stderr should be wrapped')
|
33 |
+
self.assertTrue(isinstance(sys.stdout, StreamWrapper),
|
34 |
+
'bad stdout wrapper')
|
35 |
+
self.assertTrue(isinstance(sys.stderr, StreamWrapper),
|
36 |
+
'bad stderr wrapper')
|
37 |
+
|
38 |
+
def assertNotWrapped(self):
|
39 |
+
self.assertIs(sys.stdout, orig_stdout, 'stdout should not be wrapped')
|
40 |
+
self.assertIs(sys.stderr, orig_stderr, 'stderr should not be wrapped')
|
41 |
+
|
42 |
+
@patch('colorama.initialise.reset_all')
|
43 |
+
@patch('colorama.ansitowin32.winapi_test', lambda *_: True)
|
44 |
+
@patch('colorama.ansitowin32.enable_vt_processing', lambda *_: False)
|
45 |
+
def testInitWrapsOnWindows(self, _):
|
46 |
+
with osname("nt"):
|
47 |
+
init()
|
48 |
+
self.assertWrapped()
|
49 |
+
|
50 |
+
@patch('colorama.initialise.reset_all')
|
51 |
+
@patch('colorama.ansitowin32.winapi_test', lambda *_: False)
|
52 |
+
def testInitDoesntWrapOnEmulatedWindows(self, _):
|
53 |
+
with osname("nt"):
|
54 |
+
init()
|
55 |
+
self.assertNotWrapped()
|
56 |
+
|
57 |
+
def testInitDoesntWrapOnNonWindows(self):
|
58 |
+
with osname("posix"):
|
59 |
+
init()
|
60 |
+
self.assertNotWrapped()
|
61 |
+
|
62 |
+
def testInitDoesntWrapIfNone(self):
|
63 |
+
with replace_by(None):
|
64 |
+
init()
|
65 |
+
# We can't use assertNotWrapped here because replace_by(None)
|
66 |
+
# changes stdout/stderr already.
|
67 |
+
self.assertIsNone(sys.stdout)
|
68 |
+
self.assertIsNone(sys.stderr)
|
69 |
+
|
70 |
+
def testInitAutoresetOnWrapsOnAllPlatforms(self):
|
71 |
+
with osname("posix"):
|
72 |
+
init(autoreset=True)
|
73 |
+
self.assertWrapped()
|
74 |
+
|
75 |
+
def testInitWrapOffDoesntWrapOnWindows(self):
|
76 |
+
with osname("nt"):
|
77 |
+
init(wrap=False)
|
78 |
+
self.assertNotWrapped()
|
79 |
+
|
80 |
+
def testInitWrapOffIncompatibleWithAutoresetOn(self):
|
81 |
+
self.assertRaises(ValueError, lambda: init(autoreset=True, wrap=False))
|
82 |
+
|
83 |
+
@patch('colorama.win32.SetConsoleTextAttribute')
|
84 |
+
@patch('colorama.initialise.AnsiToWin32')
|
85 |
+
def testAutoResetPassedOn(self, mockATW32, _):
|
86 |
+
with osname("nt"):
|
87 |
+
init(autoreset=True)
|
88 |
+
self.assertEqual(len(mockATW32.call_args_list), 2)
|
89 |
+
self.assertEqual(mockATW32.call_args_list[1][1]['autoreset'], True)
|
90 |
+
self.assertEqual(mockATW32.call_args_list[0][1]['autoreset'], True)
|
91 |
+
|
92 |
+
@patch('colorama.initialise.AnsiToWin32')
|
93 |
+
def testAutoResetChangeable(self, mockATW32):
|
94 |
+
with osname("nt"):
|
95 |
+
init()
|
96 |
+
|
97 |
+
init(autoreset=True)
|
98 |
+
self.assertEqual(len(mockATW32.call_args_list), 4)
|
99 |
+
self.assertEqual(mockATW32.call_args_list[2][1]['autoreset'], True)
|
100 |
+
self.assertEqual(mockATW32.call_args_list[3][1]['autoreset'], True)
|
101 |
+
|
102 |
+
init()
|
103 |
+
self.assertEqual(len(mockATW32.call_args_list), 6)
|
104 |
+
self.assertEqual(
|
105 |
+
mockATW32.call_args_list[4][1]['autoreset'], False)
|
106 |
+
self.assertEqual(
|
107 |
+
mockATW32.call_args_list[5][1]['autoreset'], False)
|
108 |
+
|
109 |
+
|
110 |
+
@patch('colorama.initialise.atexit.register')
|
111 |
+
def testAtexitRegisteredOnlyOnce(self, mockRegister):
|
112 |
+
init()
|
113 |
+
self.assertTrue(mockRegister.called)
|
114 |
+
mockRegister.reset_mock()
|
115 |
+
init()
|
116 |
+
self.assertFalse(mockRegister.called)
|
117 |
+
|
118 |
+
|
119 |
+
class JustFixWindowsConsoleTest(TestCase):
|
120 |
+
def _reset(self):
|
121 |
+
_wipe_internal_state_for_tests()
|
122 |
+
sys.stdout = orig_stdout
|
123 |
+
sys.stderr = orig_stderr
|
124 |
+
|
125 |
+
def tearDown(self):
|
126 |
+
self._reset()
|
127 |
+
|
128 |
+
@patch("colorama.ansitowin32.winapi_test", lambda: True)
|
129 |
+
def testJustFixWindowsConsole(self):
|
130 |
+
if sys.platform != "win32":
|
131 |
+
# just_fix_windows_console should be a no-op
|
132 |
+
just_fix_windows_console()
|
133 |
+
self.assertIs(sys.stdout, orig_stdout)
|
134 |
+
self.assertIs(sys.stderr, orig_stderr)
|
135 |
+
else:
|
136 |
+
def fake_std():
|
137 |
+
# Emulate stdout=not a tty, stderr=tty
|
138 |
+
# to check that we handle both cases correctly
|
139 |
+
stdout = Mock()
|
140 |
+
stdout.closed = False
|
141 |
+
stdout.isatty.return_value = False
|
142 |
+
stdout.fileno.return_value = 1
|
143 |
+
sys.stdout = stdout
|
144 |
+
|
145 |
+
stderr = Mock()
|
146 |
+
stderr.closed = False
|
147 |
+
stderr.isatty.return_value = True
|
148 |
+
stderr.fileno.return_value = 2
|
149 |
+
sys.stderr = stderr
|
150 |
+
|
151 |
+
for native_ansi in [False, True]:
|
152 |
+
with patch(
|
153 |
+
'colorama.ansitowin32.enable_vt_processing',
|
154 |
+
lambda *_: native_ansi
|
155 |
+
):
|
156 |
+
self._reset()
|
157 |
+
fake_std()
|
158 |
+
|
159 |
+
# Regular single-call test
|
160 |
+
prev_stdout = sys.stdout
|
161 |
+
prev_stderr = sys.stderr
|
162 |
+
just_fix_windows_console()
|
163 |
+
self.assertIs(sys.stdout, prev_stdout)
|
164 |
+
if native_ansi:
|
165 |
+
self.assertIs(sys.stderr, prev_stderr)
|
166 |
+
else:
|
167 |
+
self.assertIsNot(sys.stderr, prev_stderr)
|
168 |
+
|
169 |
+
# second call without resetting is always a no-op
|
170 |
+
prev_stdout = sys.stdout
|
171 |
+
prev_stderr = sys.stderr
|
172 |
+
just_fix_windows_console()
|
173 |
+
self.assertIs(sys.stdout, prev_stdout)
|
174 |
+
self.assertIs(sys.stderr, prev_stderr)
|
175 |
+
|
176 |
+
self._reset()
|
177 |
+
fake_std()
|
178 |
+
|
179 |
+
# If init() runs first, just_fix_windows_console should be a no-op
|
180 |
+
init()
|
181 |
+
prev_stdout = sys.stdout
|
182 |
+
prev_stderr = sys.stderr
|
183 |
+
just_fix_windows_console()
|
184 |
+
self.assertIs(prev_stdout, sys.stdout)
|
185 |
+
self.assertIs(prev_stderr, sys.stderr)
|
186 |
+
|
187 |
+
|
188 |
+
if __name__ == '__main__':
|
189 |
+
main()
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/isatty_test.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
import sys
|
3 |
+
from unittest import TestCase, main
|
4 |
+
|
5 |
+
from ..ansitowin32 import StreamWrapper, AnsiToWin32
|
6 |
+
from .utils import pycharm, replace_by, replace_original_by, StreamTTY, StreamNonTTY
|
7 |
+
|
8 |
+
|
9 |
+
def is_a_tty(stream):
|
10 |
+
return StreamWrapper(stream, None).isatty()
|
11 |
+
|
12 |
+
class IsattyTest(TestCase):
|
13 |
+
|
14 |
+
def test_TTY(self):
|
15 |
+
tty = StreamTTY()
|
16 |
+
self.assertTrue(is_a_tty(tty))
|
17 |
+
with pycharm():
|
18 |
+
self.assertTrue(is_a_tty(tty))
|
19 |
+
|
20 |
+
def test_nonTTY(self):
|
21 |
+
non_tty = StreamNonTTY()
|
22 |
+
self.assertFalse(is_a_tty(non_tty))
|
23 |
+
with pycharm():
|
24 |
+
self.assertFalse(is_a_tty(non_tty))
|
25 |
+
|
26 |
+
def test_withPycharm(self):
|
27 |
+
with pycharm():
|
28 |
+
self.assertTrue(is_a_tty(sys.stderr))
|
29 |
+
self.assertTrue(is_a_tty(sys.stdout))
|
30 |
+
|
31 |
+
def test_withPycharmTTYOverride(self):
|
32 |
+
tty = StreamTTY()
|
33 |
+
with pycharm(), replace_by(tty):
|
34 |
+
self.assertTrue(is_a_tty(tty))
|
35 |
+
|
36 |
+
def test_withPycharmNonTTYOverride(self):
|
37 |
+
non_tty = StreamNonTTY()
|
38 |
+
with pycharm(), replace_by(non_tty):
|
39 |
+
self.assertFalse(is_a_tty(non_tty))
|
40 |
+
|
41 |
+
def test_withPycharmNoneOverride(self):
|
42 |
+
with pycharm():
|
43 |
+
with replace_by(None), replace_original_by(None):
|
44 |
+
self.assertFalse(is_a_tty(None))
|
45 |
+
self.assertFalse(is_a_tty(StreamNonTTY()))
|
46 |
+
self.assertTrue(is_a_tty(StreamTTY()))
|
47 |
+
|
48 |
+
def test_withPycharmStreamWrapped(self):
|
49 |
+
with pycharm():
|
50 |
+
self.assertTrue(AnsiToWin32(StreamTTY()).stream.isatty())
|
51 |
+
self.assertFalse(AnsiToWin32(StreamNonTTY()).stream.isatty())
|
52 |
+
self.assertTrue(AnsiToWin32(sys.stdout).stream.isatty())
|
53 |
+
self.assertTrue(AnsiToWin32(sys.stderr).stream.isatty())
|
54 |
+
|
55 |
+
|
56 |
+
if __name__ == '__main__':
|
57 |
+
main()
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/utils.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
from contextlib import contextmanager
|
3 |
+
from io import StringIO
|
4 |
+
import sys
|
5 |
+
import os
|
6 |
+
|
7 |
+
|
8 |
+
class StreamTTY(StringIO):
|
9 |
+
def isatty(self):
|
10 |
+
return True
|
11 |
+
|
12 |
+
class StreamNonTTY(StringIO):
|
13 |
+
def isatty(self):
|
14 |
+
return False
|
15 |
+
|
16 |
+
@contextmanager
|
17 |
+
def osname(name):
|
18 |
+
orig = os.name
|
19 |
+
os.name = name
|
20 |
+
yield
|
21 |
+
os.name = orig
|
22 |
+
|
23 |
+
@contextmanager
|
24 |
+
def replace_by(stream):
|
25 |
+
orig_stdout = sys.stdout
|
26 |
+
orig_stderr = sys.stderr
|
27 |
+
sys.stdout = stream
|
28 |
+
sys.stderr = stream
|
29 |
+
yield
|
30 |
+
sys.stdout = orig_stdout
|
31 |
+
sys.stderr = orig_stderr
|
32 |
+
|
33 |
+
@contextmanager
|
34 |
+
def replace_original_by(stream):
|
35 |
+
orig_stdout = sys.__stdout__
|
36 |
+
orig_stderr = sys.__stderr__
|
37 |
+
sys.__stdout__ = stream
|
38 |
+
sys.__stderr__ = stream
|
39 |
+
yield
|
40 |
+
sys.__stdout__ = orig_stdout
|
41 |
+
sys.__stderr__ = orig_stderr
|
42 |
+
|
43 |
+
@contextmanager
|
44 |
+
def pycharm():
|
45 |
+
os.environ["PYCHARM_HOSTED"] = "1"
|
46 |
+
non_tty = StreamNonTTY()
|
47 |
+
with replace_by(non_tty), replace_original_by(non_tty):
|
48 |
+
yield
|
49 |
+
del os.environ["PYCHARM_HOSTED"]
|
env-llmeval/lib/python3.10/site-packages/colorama/tests/winterm_test.py
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
import sys
|
3 |
+
from unittest import TestCase, main, skipUnless
|
4 |
+
|
5 |
+
try:
|
6 |
+
from unittest.mock import Mock, patch
|
7 |
+
except ImportError:
|
8 |
+
from mock import Mock, patch
|
9 |
+
|
10 |
+
from ..winterm import WinColor, WinStyle, WinTerm
|
11 |
+
|
12 |
+
|
13 |
+
class WinTermTest(TestCase):
|
14 |
+
|
15 |
+
@patch('colorama.winterm.win32')
|
16 |
+
def testInit(self, mockWin32):
|
17 |
+
mockAttr = Mock()
|
18 |
+
mockAttr.wAttributes = 7 + 6 * 16 + 8
|
19 |
+
mockWin32.GetConsoleScreenBufferInfo.return_value = mockAttr
|
20 |
+
term = WinTerm()
|
21 |
+
self.assertEqual(term._fore, 7)
|
22 |
+
self.assertEqual(term._back, 6)
|
23 |
+
self.assertEqual(term._style, 8)
|
24 |
+
|
25 |
+
@skipUnless(sys.platform.startswith("win"), "requires Windows")
|
26 |
+
def testGetAttrs(self):
|
27 |
+
term = WinTerm()
|
28 |
+
|
29 |
+
term._fore = 0
|
30 |
+
term._back = 0
|
31 |
+
term._style = 0
|
32 |
+
self.assertEqual(term.get_attrs(), 0)
|
33 |
+
|
34 |
+
term._fore = WinColor.YELLOW
|
35 |
+
self.assertEqual(term.get_attrs(), WinColor.YELLOW)
|
36 |
+
|
37 |
+
term._back = WinColor.MAGENTA
|
38 |
+
self.assertEqual(
|
39 |
+
term.get_attrs(),
|
40 |
+
WinColor.YELLOW + WinColor.MAGENTA * 16)
|
41 |
+
|
42 |
+
term._style = WinStyle.BRIGHT
|
43 |
+
self.assertEqual(
|
44 |
+
term.get_attrs(),
|
45 |
+
WinColor.YELLOW + WinColor.MAGENTA * 16 + WinStyle.BRIGHT)
|
46 |
+
|
47 |
+
@patch('colorama.winterm.win32')
|
48 |
+
def testResetAll(self, mockWin32):
|
49 |
+
mockAttr = Mock()
|
50 |
+
mockAttr.wAttributes = 1 + 2 * 16 + 8
|
51 |
+
mockWin32.GetConsoleScreenBufferInfo.return_value = mockAttr
|
52 |
+
term = WinTerm()
|
53 |
+
|
54 |
+
term.set_console = Mock()
|
55 |
+
term._fore = -1
|
56 |
+
term._back = -1
|
57 |
+
term._style = -1
|
58 |
+
|
59 |
+
term.reset_all()
|
60 |
+
|
61 |
+
self.assertEqual(term._fore, 1)
|
62 |
+
self.assertEqual(term._back, 2)
|
63 |
+
self.assertEqual(term._style, 8)
|
64 |
+
self.assertEqual(term.set_console.called, True)
|
65 |
+
|
66 |
+
@skipUnless(sys.platform.startswith("win"), "requires Windows")
|
67 |
+
def testFore(self):
|
68 |
+
term = WinTerm()
|
69 |
+
term.set_console = Mock()
|
70 |
+
term._fore = 0
|
71 |
+
|
72 |
+
term.fore(5)
|
73 |
+
|
74 |
+
self.assertEqual(term._fore, 5)
|
75 |
+
self.assertEqual(term.set_console.called, True)
|
76 |
+
|
77 |
+
@skipUnless(sys.platform.startswith("win"), "requires Windows")
|
78 |
+
def testBack(self):
|
79 |
+
term = WinTerm()
|
80 |
+
term.set_console = Mock()
|
81 |
+
term._back = 0
|
82 |
+
|
83 |
+
term.back(5)
|
84 |
+
|
85 |
+
self.assertEqual(term._back, 5)
|
86 |
+
self.assertEqual(term.set_console.called, True)
|
87 |
+
|
88 |
+
@skipUnless(sys.platform.startswith("win"), "requires Windows")
|
89 |
+
def testStyle(self):
|
90 |
+
term = WinTerm()
|
91 |
+
term.set_console = Mock()
|
92 |
+
term._style = 0
|
93 |
+
|
94 |
+
term.style(22)
|
95 |
+
|
96 |
+
self.assertEqual(term._style, 22)
|
97 |
+
self.assertEqual(term.set_console.called, True)
|
98 |
+
|
99 |
+
@patch('colorama.winterm.win32')
|
100 |
+
def testSetConsole(self, mockWin32):
|
101 |
+
mockAttr = Mock()
|
102 |
+
mockAttr.wAttributes = 0
|
103 |
+
mockWin32.GetConsoleScreenBufferInfo.return_value = mockAttr
|
104 |
+
term = WinTerm()
|
105 |
+
term.windll = Mock()
|
106 |
+
|
107 |
+
term.set_console()
|
108 |
+
|
109 |
+
self.assertEqual(
|
110 |
+
mockWin32.SetConsoleTextAttribute.call_args,
|
111 |
+
((mockWin32.STDOUT, term.get_attrs()), {})
|
112 |
+
)
|
113 |
+
|
114 |
+
@patch('colorama.winterm.win32')
|
115 |
+
def testSetConsoleOnStderr(self, mockWin32):
|
116 |
+
mockAttr = Mock()
|
117 |
+
mockAttr.wAttributes = 0
|
118 |
+
mockWin32.GetConsoleScreenBufferInfo.return_value = mockAttr
|
119 |
+
term = WinTerm()
|
120 |
+
term.windll = Mock()
|
121 |
+
|
122 |
+
term.set_console(on_stderr=True)
|
123 |
+
|
124 |
+
self.assertEqual(
|
125 |
+
mockWin32.SetConsoleTextAttribute.call_args,
|
126 |
+
((mockWin32.STDERR, term.get_attrs()), {})
|
127 |
+
)
|
128 |
+
|
129 |
+
|
130 |
+
if __name__ == '__main__':
|
131 |
+
main()
|
env-llmeval/lib/python3.10/site-packages/colorama/win32.py
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
|
3 |
+
# from winbase.h
|
4 |
+
STDOUT = -11
|
5 |
+
STDERR = -12
|
6 |
+
|
7 |
+
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
|
8 |
+
|
9 |
+
try:
|
10 |
+
import ctypes
|
11 |
+
from ctypes import LibraryLoader
|
12 |
+
windll = LibraryLoader(ctypes.WinDLL)
|
13 |
+
from ctypes import wintypes
|
14 |
+
except (AttributeError, ImportError):
|
15 |
+
windll = None
|
16 |
+
SetConsoleTextAttribute = lambda *_: None
|
17 |
+
winapi_test = lambda *_: None
|
18 |
+
else:
|
19 |
+
from ctypes import byref, Structure, c_char, POINTER
|
20 |
+
|
21 |
+
COORD = wintypes._COORD
|
22 |
+
|
23 |
+
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
|
24 |
+
"""struct in wincon.h."""
|
25 |
+
_fields_ = [
|
26 |
+
("dwSize", COORD),
|
27 |
+
("dwCursorPosition", COORD),
|
28 |
+
("wAttributes", wintypes.WORD),
|
29 |
+
("srWindow", wintypes.SMALL_RECT),
|
30 |
+
("dwMaximumWindowSize", COORD),
|
31 |
+
]
|
32 |
+
def __str__(self):
|
33 |
+
return '(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)' % (
|
34 |
+
self.dwSize.Y, self.dwSize.X
|
35 |
+
, self.dwCursorPosition.Y, self.dwCursorPosition.X
|
36 |
+
, self.wAttributes
|
37 |
+
, self.srWindow.Top, self.srWindow.Left, self.srWindow.Bottom, self.srWindow.Right
|
38 |
+
, self.dwMaximumWindowSize.Y, self.dwMaximumWindowSize.X
|
39 |
+
)
|
40 |
+
|
41 |
+
_GetStdHandle = windll.kernel32.GetStdHandle
|
42 |
+
_GetStdHandle.argtypes = [
|
43 |
+
wintypes.DWORD,
|
44 |
+
]
|
45 |
+
_GetStdHandle.restype = wintypes.HANDLE
|
46 |
+
|
47 |
+
_GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo
|
48 |
+
_GetConsoleScreenBufferInfo.argtypes = [
|
49 |
+
wintypes.HANDLE,
|
50 |
+
POINTER(CONSOLE_SCREEN_BUFFER_INFO),
|
51 |
+
]
|
52 |
+
_GetConsoleScreenBufferInfo.restype = wintypes.BOOL
|
53 |
+
|
54 |
+
_SetConsoleTextAttribute = windll.kernel32.SetConsoleTextAttribute
|
55 |
+
_SetConsoleTextAttribute.argtypes = [
|
56 |
+
wintypes.HANDLE,
|
57 |
+
wintypes.WORD,
|
58 |
+
]
|
59 |
+
_SetConsoleTextAttribute.restype = wintypes.BOOL
|
60 |
+
|
61 |
+
_SetConsoleCursorPosition = windll.kernel32.SetConsoleCursorPosition
|
62 |
+
_SetConsoleCursorPosition.argtypes = [
|
63 |
+
wintypes.HANDLE,
|
64 |
+
COORD,
|
65 |
+
]
|
66 |
+
_SetConsoleCursorPosition.restype = wintypes.BOOL
|
67 |
+
|
68 |
+
_FillConsoleOutputCharacterA = windll.kernel32.FillConsoleOutputCharacterA
|
69 |
+
_FillConsoleOutputCharacterA.argtypes = [
|
70 |
+
wintypes.HANDLE,
|
71 |
+
c_char,
|
72 |
+
wintypes.DWORD,
|
73 |
+
COORD,
|
74 |
+
POINTER(wintypes.DWORD),
|
75 |
+
]
|
76 |
+
_FillConsoleOutputCharacterA.restype = wintypes.BOOL
|
77 |
+
|
78 |
+
_FillConsoleOutputAttribute = windll.kernel32.FillConsoleOutputAttribute
|
79 |
+
_FillConsoleOutputAttribute.argtypes = [
|
80 |
+
wintypes.HANDLE,
|
81 |
+
wintypes.WORD,
|
82 |
+
wintypes.DWORD,
|
83 |
+
COORD,
|
84 |
+
POINTER(wintypes.DWORD),
|
85 |
+
]
|
86 |
+
_FillConsoleOutputAttribute.restype = wintypes.BOOL
|
87 |
+
|
88 |
+
_SetConsoleTitleW = windll.kernel32.SetConsoleTitleW
|
89 |
+
_SetConsoleTitleW.argtypes = [
|
90 |
+
wintypes.LPCWSTR
|
91 |
+
]
|
92 |
+
_SetConsoleTitleW.restype = wintypes.BOOL
|
93 |
+
|
94 |
+
_GetConsoleMode = windll.kernel32.GetConsoleMode
|
95 |
+
_GetConsoleMode.argtypes = [
|
96 |
+
wintypes.HANDLE,
|
97 |
+
POINTER(wintypes.DWORD)
|
98 |
+
]
|
99 |
+
_GetConsoleMode.restype = wintypes.BOOL
|
100 |
+
|
101 |
+
_SetConsoleMode = windll.kernel32.SetConsoleMode
|
102 |
+
_SetConsoleMode.argtypes = [
|
103 |
+
wintypes.HANDLE,
|
104 |
+
wintypes.DWORD
|
105 |
+
]
|
106 |
+
_SetConsoleMode.restype = wintypes.BOOL
|
107 |
+
|
108 |
+
def _winapi_test(handle):
|
109 |
+
csbi = CONSOLE_SCREEN_BUFFER_INFO()
|
110 |
+
success = _GetConsoleScreenBufferInfo(
|
111 |
+
handle, byref(csbi))
|
112 |
+
return bool(success)
|
113 |
+
|
114 |
+
def winapi_test():
|
115 |
+
return any(_winapi_test(h) for h in
|
116 |
+
(_GetStdHandle(STDOUT), _GetStdHandle(STDERR)))
|
117 |
+
|
118 |
+
def GetConsoleScreenBufferInfo(stream_id=STDOUT):
|
119 |
+
handle = _GetStdHandle(stream_id)
|
120 |
+
csbi = CONSOLE_SCREEN_BUFFER_INFO()
|
121 |
+
success = _GetConsoleScreenBufferInfo(
|
122 |
+
handle, byref(csbi))
|
123 |
+
return csbi
|
124 |
+
|
125 |
+
def SetConsoleTextAttribute(stream_id, attrs):
|
126 |
+
handle = _GetStdHandle(stream_id)
|
127 |
+
return _SetConsoleTextAttribute(handle, attrs)
|
128 |
+
|
129 |
+
def SetConsoleCursorPosition(stream_id, position, adjust=True):
|
130 |
+
position = COORD(*position)
|
131 |
+
# If the position is out of range, do nothing.
|
132 |
+
if position.Y <= 0 or position.X <= 0:
|
133 |
+
return
|
134 |
+
# Adjust for Windows' SetConsoleCursorPosition:
|
135 |
+
# 1. being 0-based, while ANSI is 1-based.
|
136 |
+
# 2. expecting (x,y), while ANSI uses (y,x).
|
137 |
+
adjusted_position = COORD(position.Y - 1, position.X - 1)
|
138 |
+
if adjust:
|
139 |
+
# Adjust for viewport's scroll position
|
140 |
+
sr = GetConsoleScreenBufferInfo(STDOUT).srWindow
|
141 |
+
adjusted_position.Y += sr.Top
|
142 |
+
adjusted_position.X += sr.Left
|
143 |
+
# Resume normal processing
|
144 |
+
handle = _GetStdHandle(stream_id)
|
145 |
+
return _SetConsoleCursorPosition(handle, adjusted_position)
|
146 |
+
|
147 |
+
def FillConsoleOutputCharacter(stream_id, char, length, start):
|
148 |
+
handle = _GetStdHandle(stream_id)
|
149 |
+
char = c_char(char.encode())
|
150 |
+
length = wintypes.DWORD(length)
|
151 |
+
num_written = wintypes.DWORD(0)
|
152 |
+
# Note that this is hard-coded for ANSI (vs wide) bytes.
|
153 |
+
success = _FillConsoleOutputCharacterA(
|
154 |
+
handle, char, length, start, byref(num_written))
|
155 |
+
return num_written.value
|
156 |
+
|
157 |
+
def FillConsoleOutputAttribute(stream_id, attr, length, start):
|
158 |
+
''' FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten )'''
|
159 |
+
handle = _GetStdHandle(stream_id)
|
160 |
+
attribute = wintypes.WORD(attr)
|
161 |
+
length = wintypes.DWORD(length)
|
162 |
+
num_written = wintypes.DWORD(0)
|
163 |
+
# Note that this is hard-coded for ANSI (vs wide) bytes.
|
164 |
+
return _FillConsoleOutputAttribute(
|
165 |
+
handle, attribute, length, start, byref(num_written))
|
166 |
+
|
167 |
+
def SetConsoleTitle(title):
|
168 |
+
return _SetConsoleTitleW(title)
|
169 |
+
|
170 |
+
def GetConsoleMode(handle):
|
171 |
+
mode = wintypes.DWORD()
|
172 |
+
success = _GetConsoleMode(handle, byref(mode))
|
173 |
+
if not success:
|
174 |
+
raise ctypes.WinError()
|
175 |
+
return mode.value
|
176 |
+
|
177 |
+
def SetConsoleMode(handle, mode):
|
178 |
+
success = _SetConsoleMode(handle, mode)
|
179 |
+
if not success:
|
180 |
+
raise ctypes.WinError()
|
env-llmeval/lib/python3.10/site-packages/colorama/winterm.py
ADDED
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
2 |
+
try:
|
3 |
+
from msvcrt import get_osfhandle
|
4 |
+
except ImportError:
|
5 |
+
def get_osfhandle(_):
|
6 |
+
raise OSError("This isn't windows!")
|
7 |
+
|
8 |
+
|
9 |
+
from . import win32
|
10 |
+
|
11 |
+
# from wincon.h
|
12 |
+
class WinColor(object):
|
13 |
+
BLACK = 0
|
14 |
+
BLUE = 1
|
15 |
+
GREEN = 2
|
16 |
+
CYAN = 3
|
17 |
+
RED = 4
|
18 |
+
MAGENTA = 5
|
19 |
+
YELLOW = 6
|
20 |
+
GREY = 7
|
21 |
+
|
22 |
+
# from wincon.h
|
23 |
+
class WinStyle(object):
|
24 |
+
NORMAL = 0x00 # dim text, dim background
|
25 |
+
BRIGHT = 0x08 # bright text, dim background
|
26 |
+
BRIGHT_BACKGROUND = 0x80 # dim text, bright background
|
27 |
+
|
28 |
+
class WinTerm(object):
|
29 |
+
|
30 |
+
def __init__(self):
|
31 |
+
self._default = win32.GetConsoleScreenBufferInfo(win32.STDOUT).wAttributes
|
32 |
+
self.set_attrs(self._default)
|
33 |
+
self._default_fore = self._fore
|
34 |
+
self._default_back = self._back
|
35 |
+
self._default_style = self._style
|
36 |
+
# In order to emulate LIGHT_EX in windows, we borrow the BRIGHT style.
|
37 |
+
# So that LIGHT_EX colors and BRIGHT style do not clobber each other,
|
38 |
+
# we track them separately, since LIGHT_EX is overwritten by Fore/Back
|
39 |
+
# and BRIGHT is overwritten by Style codes.
|
40 |
+
self._light = 0
|
41 |
+
|
42 |
+
def get_attrs(self):
|
43 |
+
return self._fore + self._back * 16 + (self._style | self._light)
|
44 |
+
|
45 |
+
def set_attrs(self, value):
|
46 |
+
self._fore = value & 7
|
47 |
+
self._back = (value >> 4) & 7
|
48 |
+
self._style = value & (WinStyle.BRIGHT | WinStyle.BRIGHT_BACKGROUND)
|
49 |
+
|
50 |
+
def reset_all(self, on_stderr=None):
|
51 |
+
self.set_attrs(self._default)
|
52 |
+
self.set_console(attrs=self._default)
|
53 |
+
self._light = 0
|
54 |
+
|
55 |
+
def fore(self, fore=None, light=False, on_stderr=False):
|
56 |
+
if fore is None:
|
57 |
+
fore = self._default_fore
|
58 |
+
self._fore = fore
|
59 |
+
# Emulate LIGHT_EX with BRIGHT Style
|
60 |
+
if light:
|
61 |
+
self._light |= WinStyle.BRIGHT
|
62 |
+
else:
|
63 |
+
self._light &= ~WinStyle.BRIGHT
|
64 |
+
self.set_console(on_stderr=on_stderr)
|
65 |
+
|
66 |
+
def back(self, back=None, light=False, on_stderr=False):
|
67 |
+
if back is None:
|
68 |
+
back = self._default_back
|
69 |
+
self._back = back
|
70 |
+
# Emulate LIGHT_EX with BRIGHT_BACKGROUND Style
|
71 |
+
if light:
|
72 |
+
self._light |= WinStyle.BRIGHT_BACKGROUND
|
73 |
+
else:
|
74 |
+
self._light &= ~WinStyle.BRIGHT_BACKGROUND
|
75 |
+
self.set_console(on_stderr=on_stderr)
|
76 |
+
|
77 |
+
def style(self, style=None, on_stderr=False):
|
78 |
+
if style is None:
|
79 |
+
style = self._default_style
|
80 |
+
self._style = style
|
81 |
+
self.set_console(on_stderr=on_stderr)
|
82 |
+
|
83 |
+
def set_console(self, attrs=None, on_stderr=False):
|
84 |
+
if attrs is None:
|
85 |
+
attrs = self.get_attrs()
|
86 |
+
handle = win32.STDOUT
|
87 |
+
if on_stderr:
|
88 |
+
handle = win32.STDERR
|
89 |
+
win32.SetConsoleTextAttribute(handle, attrs)
|
90 |
+
|
91 |
+
def get_position(self, handle):
|
92 |
+
position = win32.GetConsoleScreenBufferInfo(handle).dwCursorPosition
|
93 |
+
# Because Windows coordinates are 0-based,
|
94 |
+
# and win32.SetConsoleCursorPosition expects 1-based.
|
95 |
+
position.X += 1
|
96 |
+
position.Y += 1
|
97 |
+
return position
|
98 |
+
|
99 |
+
def set_cursor_position(self, position=None, on_stderr=False):
|
100 |
+
if position is None:
|
101 |
+
# I'm not currently tracking the position, so there is no default.
|
102 |
+
# position = self.get_position()
|
103 |
+
return
|
104 |
+
handle = win32.STDOUT
|
105 |
+
if on_stderr:
|
106 |
+
handle = win32.STDERR
|
107 |
+
win32.SetConsoleCursorPosition(handle, position)
|
108 |
+
|
109 |
+
def cursor_adjust(self, x, y, on_stderr=False):
|
110 |
+
handle = win32.STDOUT
|
111 |
+
if on_stderr:
|
112 |
+
handle = win32.STDERR
|
113 |
+
position = self.get_position(handle)
|
114 |
+
adjusted_position = (position.Y + y, position.X + x)
|
115 |
+
win32.SetConsoleCursorPosition(handle, adjusted_position, adjust=False)
|
116 |
+
|
117 |
+
def erase_screen(self, mode=0, on_stderr=False):
|
118 |
+
# 0 should clear from the cursor to the end of the screen.
|
119 |
+
# 1 should clear from the cursor to the beginning of the screen.
|
120 |
+
# 2 should clear the entire screen, and move cursor to (1,1)
|
121 |
+
handle = win32.STDOUT
|
122 |
+
if on_stderr:
|
123 |
+
handle = win32.STDERR
|
124 |
+
csbi = win32.GetConsoleScreenBufferInfo(handle)
|
125 |
+
# get the number of character cells in the current buffer
|
126 |
+
cells_in_screen = csbi.dwSize.X * csbi.dwSize.Y
|
127 |
+
# get number of character cells before current cursor position
|
128 |
+
cells_before_cursor = csbi.dwSize.X * csbi.dwCursorPosition.Y + csbi.dwCursorPosition.X
|
129 |
+
if mode == 0:
|
130 |
+
from_coord = csbi.dwCursorPosition
|
131 |
+
cells_to_erase = cells_in_screen - cells_before_cursor
|
132 |
+
elif mode == 1:
|
133 |
+
from_coord = win32.COORD(0, 0)
|
134 |
+
cells_to_erase = cells_before_cursor
|
135 |
+
elif mode == 2:
|
136 |
+
from_coord = win32.COORD(0, 0)
|
137 |
+
cells_to_erase = cells_in_screen
|
138 |
+
else:
|
139 |
+
# invalid mode
|
140 |
+
return
|
141 |
+
# fill the entire screen with blanks
|
142 |
+
win32.FillConsoleOutputCharacter(handle, ' ', cells_to_erase, from_coord)
|
143 |
+
# now set the buffer's attributes accordingly
|
144 |
+
win32.FillConsoleOutputAttribute(handle, self.get_attrs(), cells_to_erase, from_coord)
|
145 |
+
if mode == 2:
|
146 |
+
# put the cursor where needed
|
147 |
+
win32.SetConsoleCursorPosition(handle, (1, 1))
|
148 |
+
|
149 |
+
def erase_line(self, mode=0, on_stderr=False):
|
150 |
+
# 0 should clear from the cursor to the end of the line.
|
151 |
+
# 1 should clear from the cursor to the beginning of the line.
|
152 |
+
# 2 should clear the entire line.
|
153 |
+
handle = win32.STDOUT
|
154 |
+
if on_stderr:
|
155 |
+
handle = win32.STDERR
|
156 |
+
csbi = win32.GetConsoleScreenBufferInfo(handle)
|
157 |
+
if mode == 0:
|
158 |
+
from_coord = csbi.dwCursorPosition
|
159 |
+
cells_to_erase = csbi.dwSize.X - csbi.dwCursorPosition.X
|
160 |
+
elif mode == 1:
|
161 |
+
from_coord = win32.COORD(0, csbi.dwCursorPosition.Y)
|
162 |
+
cells_to_erase = csbi.dwCursorPosition.X
|
163 |
+
elif mode == 2:
|
164 |
+
from_coord = win32.COORD(0, csbi.dwCursorPosition.Y)
|
165 |
+
cells_to_erase = csbi.dwSize.X
|
166 |
+
else:
|
167 |
+
# invalid mode
|
168 |
+
return
|
169 |
+
# fill the entire screen with blanks
|
170 |
+
win32.FillConsoleOutputCharacter(handle, ' ', cells_to_erase, from_coord)
|
171 |
+
# now set the buffer's attributes accordingly
|
172 |
+
win32.FillConsoleOutputAttribute(handle, self.get_attrs(), cells_to_erase, from_coord)
|
173 |
+
|
174 |
+
def set_title(self, title):
|
175 |
+
win32.SetConsoleTitle(title)
|
176 |
+
|
177 |
+
|
178 |
+
def enable_vt_processing(fd):
|
179 |
+
if win32.windll is None or not win32.winapi_test():
|
180 |
+
return False
|
181 |
+
|
182 |
+
try:
|
183 |
+
handle = get_osfhandle(fd)
|
184 |
+
mode = win32.GetConsoleMode(handle)
|
185 |
+
win32.SetConsoleMode(
|
186 |
+
handle,
|
187 |
+
mode | win32.ENABLE_VIRTUAL_TERMINAL_PROCESSING,
|
188 |
+
)
|
189 |
+
|
190 |
+
mode = win32.GetConsoleMode(handle)
|
191 |
+
if mode & win32.ENABLE_VIRTUAL_TERMINAL_PROCESSING:
|
192 |
+
return True
|
193 |
+
# Can get TypeError in testsuite where 'fd' is a Mock()
|
194 |
+
except (OSError, TypeError):
|
195 |
+
return False
|
env-llmeval/lib/python3.10/site-packages/packaging/_parser.py
ADDED
@@ -0,0 +1,356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Handwritten parser of dependency specifiers.
|
2 |
+
|
3 |
+
The docstring for each __parse_* function contains ENBF-inspired grammar representing
|
4 |
+
the implementation.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import ast
|
8 |
+
from typing import Any, List, NamedTuple, Optional, Tuple, Union
|
9 |
+
|
10 |
+
from ._tokenizer import DEFAULT_RULES, Tokenizer
|
11 |
+
|
12 |
+
|
13 |
+
class Node:
|
14 |
+
def __init__(self, value: str) -> None:
|
15 |
+
self.value = value
|
16 |
+
|
17 |
+
def __str__(self) -> str:
|
18 |
+
return self.value
|
19 |
+
|
20 |
+
def __repr__(self) -> str:
|
21 |
+
return f"<{self.__class__.__name__}('{self}')>"
|
22 |
+
|
23 |
+
def serialize(self) -> str:
|
24 |
+
raise NotImplementedError
|
25 |
+
|
26 |
+
|
27 |
+
class Variable(Node):
|
28 |
+
def serialize(self) -> str:
|
29 |
+
return str(self)
|
30 |
+
|
31 |
+
|
32 |
+
class Value(Node):
|
33 |
+
def serialize(self) -> str:
|
34 |
+
return f'"{self}"'
|
35 |
+
|
36 |
+
|
37 |
+
class Op(Node):
|
38 |
+
def serialize(self) -> str:
|
39 |
+
return str(self)
|
40 |
+
|
41 |
+
|
42 |
+
MarkerVar = Union[Variable, Value]
|
43 |
+
MarkerItem = Tuple[MarkerVar, Op, MarkerVar]
|
44 |
+
# MarkerAtom = Union[MarkerItem, List["MarkerAtom"]]
|
45 |
+
# MarkerList = List[Union["MarkerList", MarkerAtom, str]]
|
46 |
+
# mypy does not support recursive type definition
|
47 |
+
# https://github.com/python/mypy/issues/731
|
48 |
+
MarkerAtom = Any
|
49 |
+
MarkerList = List[Any]
|
50 |
+
|
51 |
+
|
52 |
+
class ParsedRequirement(NamedTuple):
|
53 |
+
name: str
|
54 |
+
url: str
|
55 |
+
extras: List[str]
|
56 |
+
specifier: str
|
57 |
+
marker: Optional[MarkerList]
|
58 |
+
|
59 |
+
|
60 |
+
# --------------------------------------------------------------------------------------
|
61 |
+
# Recursive descent parser for dependency specifier
|
62 |
+
# --------------------------------------------------------------------------------------
|
63 |
+
def parse_requirement(source: str) -> ParsedRequirement:
|
64 |
+
return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
|
65 |
+
|
66 |
+
|
67 |
+
def _parse_requirement(tokenizer: Tokenizer) -> ParsedRequirement:
|
68 |
+
"""
|
69 |
+
requirement = WS? IDENTIFIER WS? extras WS? requirement_details
|
70 |
+
"""
|
71 |
+
tokenizer.consume("WS")
|
72 |
+
|
73 |
+
name_token = tokenizer.expect(
|
74 |
+
"IDENTIFIER", expected="package name at the start of dependency specifier"
|
75 |
+
)
|
76 |
+
name = name_token.text
|
77 |
+
tokenizer.consume("WS")
|
78 |
+
|
79 |
+
extras = _parse_extras(tokenizer)
|
80 |
+
tokenizer.consume("WS")
|
81 |
+
|
82 |
+
url, specifier, marker = _parse_requirement_details(tokenizer)
|
83 |
+
tokenizer.expect("END", expected="end of dependency specifier")
|
84 |
+
|
85 |
+
return ParsedRequirement(name, url, extras, specifier, marker)
|
86 |
+
|
87 |
+
|
88 |
+
def _parse_requirement_details(
|
89 |
+
tokenizer: Tokenizer,
|
90 |
+
) -> Tuple[str, str, Optional[MarkerList]]:
|
91 |
+
"""
|
92 |
+
requirement_details = AT URL (WS requirement_marker?)?
|
93 |
+
| specifier WS? (requirement_marker)?
|
94 |
+
"""
|
95 |
+
|
96 |
+
specifier = ""
|
97 |
+
url = ""
|
98 |
+
marker = None
|
99 |
+
|
100 |
+
if tokenizer.check("AT"):
|
101 |
+
tokenizer.read()
|
102 |
+
tokenizer.consume("WS")
|
103 |
+
|
104 |
+
url_start = tokenizer.position
|
105 |
+
url = tokenizer.expect("URL", expected="URL after @").text
|
106 |
+
if tokenizer.check("END", peek=True):
|
107 |
+
return (url, specifier, marker)
|
108 |
+
|
109 |
+
tokenizer.expect("WS", expected="whitespace after URL")
|
110 |
+
|
111 |
+
# The input might end after whitespace.
|
112 |
+
if tokenizer.check("END", peek=True):
|
113 |
+
return (url, specifier, marker)
|
114 |
+
|
115 |
+
marker = _parse_requirement_marker(
|
116 |
+
tokenizer, span_start=url_start, after="URL and whitespace"
|
117 |
+
)
|
118 |
+
else:
|
119 |
+
specifier_start = tokenizer.position
|
120 |
+
specifier = _parse_specifier(tokenizer)
|
121 |
+
tokenizer.consume("WS")
|
122 |
+
|
123 |
+
if tokenizer.check("END", peek=True):
|
124 |
+
return (url, specifier, marker)
|
125 |
+
|
126 |
+
marker = _parse_requirement_marker(
|
127 |
+
tokenizer,
|
128 |
+
span_start=specifier_start,
|
129 |
+
after=(
|
130 |
+
"version specifier"
|
131 |
+
if specifier
|
132 |
+
else "name and no valid version specifier"
|
133 |
+
),
|
134 |
+
)
|
135 |
+
|
136 |
+
return (url, specifier, marker)
|
137 |
+
|
138 |
+
|
139 |
+
def _parse_requirement_marker(
|
140 |
+
tokenizer: Tokenizer, *, span_start: int, after: str
|
141 |
+
) -> MarkerList:
|
142 |
+
"""
|
143 |
+
requirement_marker = SEMICOLON marker WS?
|
144 |
+
"""
|
145 |
+
|
146 |
+
if not tokenizer.check("SEMICOLON"):
|
147 |
+
tokenizer.raise_syntax_error(
|
148 |
+
f"Expected end or semicolon (after {after})",
|
149 |
+
span_start=span_start,
|
150 |
+
)
|
151 |
+
tokenizer.read()
|
152 |
+
|
153 |
+
marker = _parse_marker(tokenizer)
|
154 |
+
tokenizer.consume("WS")
|
155 |
+
|
156 |
+
return marker
|
157 |
+
|
158 |
+
|
159 |
+
def _parse_extras(tokenizer: Tokenizer) -> List[str]:
|
160 |
+
"""
|
161 |
+
extras = (LEFT_BRACKET wsp* extras_list? wsp* RIGHT_BRACKET)?
|
162 |
+
"""
|
163 |
+
if not tokenizer.check("LEFT_BRACKET", peek=True):
|
164 |
+
return []
|
165 |
+
|
166 |
+
with tokenizer.enclosing_tokens(
|
167 |
+
"LEFT_BRACKET",
|
168 |
+
"RIGHT_BRACKET",
|
169 |
+
around="extras",
|
170 |
+
):
|
171 |
+
tokenizer.consume("WS")
|
172 |
+
extras = _parse_extras_list(tokenizer)
|
173 |
+
tokenizer.consume("WS")
|
174 |
+
|
175 |
+
return extras
|
176 |
+
|
177 |
+
|
178 |
+
def _parse_extras_list(tokenizer: Tokenizer) -> List[str]:
|
179 |
+
"""
|
180 |
+
extras_list = identifier (wsp* ',' wsp* identifier)*
|
181 |
+
"""
|
182 |
+
extras: List[str] = []
|
183 |
+
|
184 |
+
if not tokenizer.check("IDENTIFIER"):
|
185 |
+
return extras
|
186 |
+
|
187 |
+
extras.append(tokenizer.read().text)
|
188 |
+
|
189 |
+
while True:
|
190 |
+
tokenizer.consume("WS")
|
191 |
+
if tokenizer.check("IDENTIFIER", peek=True):
|
192 |
+
tokenizer.raise_syntax_error("Expected comma between extra names")
|
193 |
+
elif not tokenizer.check("COMMA"):
|
194 |
+
break
|
195 |
+
|
196 |
+
tokenizer.read()
|
197 |
+
tokenizer.consume("WS")
|
198 |
+
|
199 |
+
extra_token = tokenizer.expect("IDENTIFIER", expected="extra name after comma")
|
200 |
+
extras.append(extra_token.text)
|
201 |
+
|
202 |
+
return extras
|
203 |
+
|
204 |
+
|
205 |
+
def _parse_specifier(tokenizer: Tokenizer) -> str:
|
206 |
+
"""
|
207 |
+
specifier = LEFT_PARENTHESIS WS? version_many WS? RIGHT_PARENTHESIS
|
208 |
+
| WS? version_many WS?
|
209 |
+
"""
|
210 |
+
with tokenizer.enclosing_tokens(
|
211 |
+
"LEFT_PARENTHESIS",
|
212 |
+
"RIGHT_PARENTHESIS",
|
213 |
+
around="version specifier",
|
214 |
+
):
|
215 |
+
tokenizer.consume("WS")
|
216 |
+
parsed_specifiers = _parse_version_many(tokenizer)
|
217 |
+
tokenizer.consume("WS")
|
218 |
+
|
219 |
+
return parsed_specifiers
|
220 |
+
|
221 |
+
|
222 |
+
def _parse_version_many(tokenizer: Tokenizer) -> str:
|
223 |
+
"""
|
224 |
+
version_many = (SPECIFIER (WS? COMMA WS? SPECIFIER)*)?
|
225 |
+
"""
|
226 |
+
parsed_specifiers = ""
|
227 |
+
while tokenizer.check("SPECIFIER"):
|
228 |
+
span_start = tokenizer.position
|
229 |
+
parsed_specifiers += tokenizer.read().text
|
230 |
+
if tokenizer.check("VERSION_PREFIX_TRAIL", peek=True):
|
231 |
+
tokenizer.raise_syntax_error(
|
232 |
+
".* suffix can only be used with `==` or `!=` operators",
|
233 |
+
span_start=span_start,
|
234 |
+
span_end=tokenizer.position + 1,
|
235 |
+
)
|
236 |
+
if tokenizer.check("VERSION_LOCAL_LABEL_TRAIL", peek=True):
|
237 |
+
tokenizer.raise_syntax_error(
|
238 |
+
"Local version label can only be used with `==` or `!=` operators",
|
239 |
+
span_start=span_start,
|
240 |
+
span_end=tokenizer.position,
|
241 |
+
)
|
242 |
+
tokenizer.consume("WS")
|
243 |
+
if not tokenizer.check("COMMA"):
|
244 |
+
break
|
245 |
+
parsed_specifiers += tokenizer.read().text
|
246 |
+
tokenizer.consume("WS")
|
247 |
+
|
248 |
+
return parsed_specifiers
|
249 |
+
|
250 |
+
|
251 |
+
# --------------------------------------------------------------------------------------
|
252 |
+
# Recursive descent parser for marker expression
|
253 |
+
# --------------------------------------------------------------------------------------
|
254 |
+
def parse_marker(source: str) -> MarkerList:
|
255 |
+
return _parse_full_marker(Tokenizer(source, rules=DEFAULT_RULES))
|
256 |
+
|
257 |
+
|
258 |
+
def _parse_full_marker(tokenizer: Tokenizer) -> MarkerList:
|
259 |
+
retval = _parse_marker(tokenizer)
|
260 |
+
tokenizer.expect("END", expected="end of marker expression")
|
261 |
+
return retval
|
262 |
+
|
263 |
+
|
264 |
+
def _parse_marker(tokenizer: Tokenizer) -> MarkerList:
|
265 |
+
"""
|
266 |
+
marker = marker_atom (BOOLOP marker_atom)+
|
267 |
+
"""
|
268 |
+
expression = [_parse_marker_atom(tokenizer)]
|
269 |
+
while tokenizer.check("BOOLOP"):
|
270 |
+
token = tokenizer.read()
|
271 |
+
expr_right = _parse_marker_atom(tokenizer)
|
272 |
+
expression.extend((token.text, expr_right))
|
273 |
+
return expression
|
274 |
+
|
275 |
+
|
276 |
+
def _parse_marker_atom(tokenizer: Tokenizer) -> MarkerAtom:
|
277 |
+
"""
|
278 |
+
marker_atom = WS? LEFT_PARENTHESIS WS? marker WS? RIGHT_PARENTHESIS WS?
|
279 |
+
| WS? marker_item WS?
|
280 |
+
"""
|
281 |
+
|
282 |
+
tokenizer.consume("WS")
|
283 |
+
if tokenizer.check("LEFT_PARENTHESIS", peek=True):
|
284 |
+
with tokenizer.enclosing_tokens(
|
285 |
+
"LEFT_PARENTHESIS",
|
286 |
+
"RIGHT_PARENTHESIS",
|
287 |
+
around="marker expression",
|
288 |
+
):
|
289 |
+
tokenizer.consume("WS")
|
290 |
+
marker: MarkerAtom = _parse_marker(tokenizer)
|
291 |
+
tokenizer.consume("WS")
|
292 |
+
else:
|
293 |
+
marker = _parse_marker_item(tokenizer)
|
294 |
+
tokenizer.consume("WS")
|
295 |
+
return marker
|
296 |
+
|
297 |
+
|
298 |
+
def _parse_marker_item(tokenizer: Tokenizer) -> MarkerItem:
|
299 |
+
"""
|
300 |
+
marker_item = WS? marker_var WS? marker_op WS? marker_var WS?
|
301 |
+
"""
|
302 |
+
tokenizer.consume("WS")
|
303 |
+
marker_var_left = _parse_marker_var(tokenizer)
|
304 |
+
tokenizer.consume("WS")
|
305 |
+
marker_op = _parse_marker_op(tokenizer)
|
306 |
+
tokenizer.consume("WS")
|
307 |
+
marker_var_right = _parse_marker_var(tokenizer)
|
308 |
+
tokenizer.consume("WS")
|
309 |
+
return (marker_var_left, marker_op, marker_var_right)
|
310 |
+
|
311 |
+
|
312 |
+
def _parse_marker_var(tokenizer: Tokenizer) -> MarkerVar:
|
313 |
+
"""
|
314 |
+
marker_var = VARIABLE | QUOTED_STRING
|
315 |
+
"""
|
316 |
+
if tokenizer.check("VARIABLE"):
|
317 |
+
return process_env_var(tokenizer.read().text.replace(".", "_"))
|
318 |
+
elif tokenizer.check("QUOTED_STRING"):
|
319 |
+
return process_python_str(tokenizer.read().text)
|
320 |
+
else:
|
321 |
+
tokenizer.raise_syntax_error(
|
322 |
+
message="Expected a marker variable or quoted string"
|
323 |
+
)
|
324 |
+
|
325 |
+
|
326 |
+
def process_env_var(env_var: str) -> Variable:
|
327 |
+
if env_var in ("platform_python_implementation", "python_implementation"):
|
328 |
+
return Variable("platform_python_implementation")
|
329 |
+
else:
|
330 |
+
return Variable(env_var)
|
331 |
+
|
332 |
+
|
333 |
+
def process_python_str(python_str: str) -> Value:
|
334 |
+
value = ast.literal_eval(python_str)
|
335 |
+
return Value(str(value))
|
336 |
+
|
337 |
+
|
338 |
+
def _parse_marker_op(tokenizer: Tokenizer) -> Op:
|
339 |
+
"""
|
340 |
+
marker_op = IN | NOT IN | OP
|
341 |
+
"""
|
342 |
+
if tokenizer.check("IN"):
|
343 |
+
tokenizer.read()
|
344 |
+
return Op("in")
|
345 |
+
elif tokenizer.check("NOT"):
|
346 |
+
tokenizer.read()
|
347 |
+
tokenizer.expect("WS", expected="whitespace after 'not'")
|
348 |
+
tokenizer.expect("IN", expected="'in' after 'not'")
|
349 |
+
return Op("not in")
|
350 |
+
elif tokenizer.check("OP"):
|
351 |
+
return Op(tokenizer.read().text)
|
352 |
+
else:
|
353 |
+
return tokenizer.raise_syntax_error(
|
354 |
+
"Expected marker operator, one of "
|
355 |
+
"<=, <, !=, ==, >=, >, ~=, ===, in, not in"
|
356 |
+
)
|
env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/INSTALLER
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pip
|
env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/LICENSE
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
Apache License
|
3 |
+
Version 2.0, January 2004
|
4 |
+
http://www.apache.org/licenses/
|
5 |
+
|
6 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7 |
+
|
8 |
+
1. Definitions.
|
9 |
+
|
10 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
11 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
12 |
+
|
13 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14 |
+
the copyright owner that is granting the License.
|
15 |
+
|
16 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
17 |
+
other entities that control, are controlled by, or are under common
|
18 |
+
control with that entity. For the purposes of this definition,
|
19 |
+
"control" means (i) the power, direct or indirect, to cause the
|
20 |
+
direction or management of such entity, whether by contract or
|
21 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23 |
+
|
24 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25 |
+
exercising permissions granted by this License.
|
26 |
+
|
27 |
+
"Source" form shall mean the preferred form for making modifications,
|
28 |
+
including but not limited to software source code, documentation
|
29 |
+
source, and configuration files.
|
30 |
+
|
31 |
+
"Object" form shall mean any form resulting from mechanical
|
32 |
+
transformation or translation of a Source form, including but
|
33 |
+
not limited to compiled object code, generated documentation,
|
34 |
+
and conversions to other media types.
|
35 |
+
|
36 |
+
"Work" shall mean the work of authorship, whether in Source or
|
37 |
+
Object form, made available under the License, as indicated by a
|
38 |
+
copyright notice that is included in or attached to the work
|
39 |
+
(an example is provided in the Appendix below).
|
40 |
+
|
41 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42 |
+
form, that is based on (or derived from) the Work and for which the
|
43 |
+
editorial revisions, annotations, elaborations, or other modifications
|
44 |
+
represent, as a whole, an original work of authorship. For the purposes
|
45 |
+
of this License, Derivative Works shall not include works that remain
|
46 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47 |
+
the Work and Derivative Works thereof.
|
48 |
+
|
49 |
+
"Contribution" shall mean any work of authorship, including
|
50 |
+
the original version of the Work and any modifications or additions
|
51 |
+
to that Work or Derivative Works thereof, that is intentionally
|
52 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
55 |
+
means any form of electronic, verbal, or written communication sent
|
56 |
+
to the Licensor or its representatives, including but not limited to
|
57 |
+
communication on electronic mailing lists, source code control systems,
|
58 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
59 |
+
Licensor for the purpose of discussing and improving the Work, but
|
60 |
+
excluding communication that is conspicuously marked or otherwise
|
61 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
62 |
+
|
63 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64 |
+
on behalf of whom a Contribution has been received by Licensor and
|
65 |
+
subsequently incorporated within the Work.
|
66 |
+
|
67 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68 |
+
this License, each Contributor hereby grants to You a perpetual,
|
69 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70 |
+
copyright license to reproduce, prepare Derivative Works of,
|
71 |
+
publicly display, publicly perform, sublicense, and distribute the
|
72 |
+
Work and such Derivative Works in Source or Object form.
|
73 |
+
|
74 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75 |
+
this License, each Contributor hereby grants to You a perpetual,
|
76 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77 |
+
(except as stated in this section) patent license to make, have made,
|
78 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79 |
+
where such license applies only to those patent claims licensable
|
80 |
+
by such Contributor that are necessarily infringed by their
|
81 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
82 |
+
with the Work to which such Contribution(s) was submitted. If You
|
83 |
+
institute patent litigation against any entity (including a
|
84 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85 |
+
or a Contribution incorporated within the Work constitutes direct
|
86 |
+
or contributory patent infringement, then any patent licenses
|
87 |
+
granted to You under this License for that Work shall terminate
|
88 |
+
as of the date such litigation is filed.
|
89 |
+
|
90 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
91 |
+
Work or Derivative Works thereof in any medium, with or without
|
92 |
+
modifications, and in Source or Object form, provided that You
|
93 |
+
meet the following conditions:
|
94 |
+
|
95 |
+
(a) You must give any other recipients of the Work or
|
96 |
+
Derivative Works a copy of this License; and
|
97 |
+
|
98 |
+
(b) You must cause any modified files to carry prominent notices
|
99 |
+
stating that You changed the files; and
|
100 |
+
|
101 |
+
(c) You must retain, in the Source form of any Derivative Works
|
102 |
+
that You distribute, all copyright, patent, trademark, and
|
103 |
+
attribution notices from the Source form of the Work,
|
104 |
+
excluding those notices that do not pertain to any part of
|
105 |
+
the Derivative Works; and
|
106 |
+
|
107 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108 |
+
distribution, then any Derivative Works that You distribute must
|
109 |
+
include a readable copy of the attribution notices contained
|
110 |
+
within such NOTICE file, excluding those notices that do not
|
111 |
+
pertain to any part of the Derivative Works, in at least one
|
112 |
+
of the following places: within a NOTICE text file distributed
|
113 |
+
as part of the Derivative Works; within the Source form or
|
114 |
+
documentation, if provided along with the Derivative Works; or,
|
115 |
+
within a display generated by the Derivative Works, if and
|
116 |
+
wherever such third-party notices normally appear. The contents
|
117 |
+
of the NOTICE file are for informational purposes only and
|
118 |
+
do not modify the License. You may add Your own attribution
|
119 |
+
notices within Derivative Works that You distribute, alongside
|
120 |
+
or as an addendum to the NOTICE text from the Work, provided
|
121 |
+
that such additional attribution notices cannot be construed
|
122 |
+
as modifying the License.
|
123 |
+
|
124 |
+
You may add Your own copyright statement to Your modifications and
|
125 |
+
may provide additional or different license terms and conditions
|
126 |
+
for use, reproduction, or distribution of Your modifications, or
|
127 |
+
for any such Derivative Works as a whole, provided Your use,
|
128 |
+
reproduction, and distribution of the Work otherwise complies with
|
129 |
+
the conditions stated in this License.
|
130 |
+
|
131 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132 |
+
any Contribution intentionally submitted for inclusion in the Work
|
133 |
+
by You to the Licensor shall be under the terms and conditions of
|
134 |
+
this License, without any additional terms or conditions.
|
135 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136 |
+
the terms of any separate license agreement you may have executed
|
137 |
+
with Licensor regarding such Contributions.
|
138 |
+
|
139 |
+
6. Trademarks. This License does not grant permission to use the trade
|
140 |
+
names, trademarks, service marks, or product names of the Licensor,
|
141 |
+
except as required for reasonable and customary use in describing the
|
142 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
143 |
+
|
144 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145 |
+
agreed to in writing, Licensor provides the Work (and each
|
146 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148 |
+
implied, including, without limitation, any warranties or conditions
|
149 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151 |
+
appropriateness of using or redistributing the Work and assume any
|
152 |
+
risks associated with Your exercise of permissions under this License.
|
153 |
+
|
154 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
155 |
+
whether in tort (including negligence), contract, or otherwise,
|
156 |
+
unless required by applicable law (such as deliberate and grossly
|
157 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158 |
+
liable to You for damages, including any direct, indirect, special,
|
159 |
+
incidental, or consequential damages of any character arising as a
|
160 |
+
result of this License or out of the use or inability to use the
|
161 |
+
Work (including but not limited to damages for loss of goodwill,
|
162 |
+
work stoppage, computer failure or malfunction, or any and all
|
163 |
+
other commercial damages or losses), even if such Contributor
|
164 |
+
has been advised of the possibility of such damages.
|
165 |
+
|
166 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
168 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169 |
+
or other liability obligations and/or rights consistent with this
|
170 |
+
License. However, in accepting such obligations, You may act only
|
171 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172 |
+
of any other Contributor, and only if You agree to indemnify,
|
173 |
+
defend, and hold each Contributor harmless for any liability
|
174 |
+
incurred by, or claims asserted against, such Contributor by reason
|
175 |
+
of your accepting any such warranty or additional liability.
|
env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/METADATA
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: requests
|
3 |
+
Version: 2.31.0
|
4 |
+
Summary: Python HTTP for Humans.
|
5 |
+
Home-page: https://requests.readthedocs.io
|
6 |
+
Author: Kenneth Reitz
|
7 |
+
Author-email: [email protected]
|
8 |
+
License: Apache 2.0
|
9 |
+
Project-URL: Documentation, https://requests.readthedocs.io
|
10 |
+
Project-URL: Source, https://github.com/psf/requests
|
11 |
+
Platform: UNKNOWN
|
12 |
+
Classifier: Development Status :: 5 - Production/Stable
|
13 |
+
Classifier: Environment :: Web Environment
|
14 |
+
Classifier: Intended Audience :: Developers
|
15 |
+
Classifier: License :: OSI Approved :: Apache Software License
|
16 |
+
Classifier: Natural Language :: English
|
17 |
+
Classifier: Operating System :: OS Independent
|
18 |
+
Classifier: Programming Language :: Python
|
19 |
+
Classifier: Programming Language :: Python :: 3
|
20 |
+
Classifier: Programming Language :: Python :: 3.7
|
21 |
+
Classifier: Programming Language :: Python :: 3.8
|
22 |
+
Classifier: Programming Language :: Python :: 3.9
|
23 |
+
Classifier: Programming Language :: Python :: 3.10
|
24 |
+
Classifier: Programming Language :: Python :: 3.11
|
25 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
26 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
27 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
28 |
+
Classifier: Topic :: Internet :: WWW/HTTP
|
29 |
+
Classifier: Topic :: Software Development :: Libraries
|
30 |
+
Requires-Python: >=3.7
|
31 |
+
Description-Content-Type: text/markdown
|
32 |
+
License-File: LICENSE
|
33 |
+
Requires-Dist: charset-normalizer (<4,>=2)
|
34 |
+
Requires-Dist: idna (<4,>=2.5)
|
35 |
+
Requires-Dist: urllib3 (<3,>=1.21.1)
|
36 |
+
Requires-Dist: certifi (>=2017.4.17)
|
37 |
+
Provides-Extra: security
|
38 |
+
Provides-Extra: socks
|
39 |
+
Requires-Dist: PySocks (!=1.5.7,>=1.5.6) ; extra == 'socks'
|
40 |
+
Provides-Extra: use_chardet_on_py3
|
41 |
+
Requires-Dist: chardet (<6,>=3.0.2) ; extra == 'use_chardet_on_py3'
|
42 |
+
|
43 |
+
# Requests
|
44 |
+
|
45 |
+
**Requests** is a simple, yet elegant, HTTP library.
|
46 |
+
|
47 |
+
```python
|
48 |
+
>>> import requests
|
49 |
+
>>> r = requests.get('https://httpbin.org/basic-auth/user/pass', auth=('user', 'pass'))
|
50 |
+
>>> r.status_code
|
51 |
+
200
|
52 |
+
>>> r.headers['content-type']
|
53 |
+
'application/json; charset=utf8'
|
54 |
+
>>> r.encoding
|
55 |
+
'utf-8'
|
56 |
+
>>> r.text
|
57 |
+
'{"authenticated": true, ...'
|
58 |
+
>>> r.json()
|
59 |
+
{'authenticated': True, ...}
|
60 |
+
```
|
61 |
+
|
62 |
+
Requests allows you to send HTTP/1.1 requests extremely easily. There’s no need to manually add query strings to your URLs, or to form-encode your `PUT` & `POST` data — but nowadays, just use the `json` method!
|
63 |
+
|
64 |
+
Requests is one of the most downloaded Python packages today, pulling in around `30M downloads / week`— according to GitHub, Requests is currently [depended upon](https://github.com/psf/requests/network/dependents?package_id=UGFja2FnZS01NzA4OTExNg%3D%3D) by `1,000,000+` repositories. You may certainly put your trust in this code.
|
65 |
+
|
66 |
+
[](https://pepy.tech/project/requests)
|
67 |
+
[](https://pypi.org/project/requests)
|
68 |
+
[](https://github.com/psf/requests/graphs/contributors)
|
69 |
+
|
70 |
+
## Installing Requests and Supported Versions
|
71 |
+
|
72 |
+
Requests is available on PyPI:
|
73 |
+
|
74 |
+
```console
|
75 |
+
$ python -m pip install requests
|
76 |
+
```
|
77 |
+
|
78 |
+
Requests officially supports Python 3.7+.
|
79 |
+
|
80 |
+
## Supported Features & Best–Practices
|
81 |
+
|
82 |
+
Requests is ready for the demands of building robust and reliable HTTP–speaking applications, for the needs of today.
|
83 |
+
|
84 |
+
- Keep-Alive & Connection Pooling
|
85 |
+
- International Domains and URLs
|
86 |
+
- Sessions with Cookie Persistence
|
87 |
+
- Browser-style TLS/SSL Verification
|
88 |
+
- Basic & Digest Authentication
|
89 |
+
- Familiar `dict`–like Cookies
|
90 |
+
- Automatic Content Decompression and Decoding
|
91 |
+
- Multi-part File Uploads
|
92 |
+
- SOCKS Proxy Support
|
93 |
+
- Connection Timeouts
|
94 |
+
- Streaming Downloads
|
95 |
+
- Automatic honoring of `.netrc`
|
96 |
+
- Chunked HTTP Requests
|
97 |
+
|
98 |
+
## API Reference and User Guide available on [Read the Docs](https://requests.readthedocs.io)
|
99 |
+
|
100 |
+
[](https://requests.readthedocs.io)
|
101 |
+
|
102 |
+
## Cloning the repository
|
103 |
+
|
104 |
+
When cloning the Requests repository, you may need to add the `-c
|
105 |
+
fetch.fsck.badTimezone=ignore` flag to avoid an error about a bad commit (see
|
106 |
+
[this issue](https://github.com/psf/requests/issues/2690) for more background):
|
107 |
+
|
108 |
+
```shell
|
109 |
+
git clone -c fetch.fsck.badTimezone=ignore https://github.com/psf/requests.git
|
110 |
+
```
|
111 |
+
|
112 |
+
You can also apply this setting to your global Git config:
|
113 |
+
|
114 |
+
```shell
|
115 |
+
git config --global fetch.fsck.badTimezone ignore
|
116 |
+
```
|
117 |
+
|
118 |
+
---
|
119 |
+
|
120 |
+
[](https://kennethreitz.org) [](https://www.python.org/psf)
|
121 |
+
|
122 |
+
|
env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/RECORD
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
requests-2.31.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
2 |
+
requests-2.31.0.dist-info/LICENSE,sha256=CeipvOyAZxBGUsFoaFqwkx54aPnIKEtm9a5u2uXxEws,10142
|
3 |
+
requests-2.31.0.dist-info/METADATA,sha256=eCPokOnbb0FROLrfl0R5EpDvdufsb9CaN4noJH__54I,4634
|
4 |
+
requests-2.31.0.dist-info/RECORD,,
|
5 |
+
requests-2.31.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
6 |
+
requests-2.31.0.dist-info/top_level.txt,sha256=fMSVmHfb5rbGOo6xv-O_tUX6j-WyixssE-SnwcDRxNQ,9
|
7 |
+
requests/__init__.py,sha256=LvmKhjIz8mHaKXthC2Mv5ykZ1d92voyf3oJpd-VuAig,4963
|
8 |
+
requests/__pycache__/__init__.cpython-310.pyc,,
|
9 |
+
requests/__pycache__/__version__.cpython-310.pyc,,
|
10 |
+
requests/__pycache__/_internal_utils.cpython-310.pyc,,
|
11 |
+
requests/__pycache__/adapters.cpython-310.pyc,,
|
12 |
+
requests/__pycache__/api.cpython-310.pyc,,
|
13 |
+
requests/__pycache__/auth.cpython-310.pyc,,
|
14 |
+
requests/__pycache__/certs.cpython-310.pyc,,
|
15 |
+
requests/__pycache__/compat.cpython-310.pyc,,
|
16 |
+
requests/__pycache__/cookies.cpython-310.pyc,,
|
17 |
+
requests/__pycache__/exceptions.cpython-310.pyc,,
|
18 |
+
requests/__pycache__/help.cpython-310.pyc,,
|
19 |
+
requests/__pycache__/hooks.cpython-310.pyc,,
|
20 |
+
requests/__pycache__/models.cpython-310.pyc,,
|
21 |
+
requests/__pycache__/packages.cpython-310.pyc,,
|
22 |
+
requests/__pycache__/sessions.cpython-310.pyc,,
|
23 |
+
requests/__pycache__/status_codes.cpython-310.pyc,,
|
24 |
+
requests/__pycache__/structures.cpython-310.pyc,,
|
25 |
+
requests/__pycache__/utils.cpython-310.pyc,,
|
26 |
+
requests/__version__.py,sha256=ssI3Ezt7PaxgkOW45GhtwPUclo_SO_ygtIm4A74IOfw,435
|
27 |
+
requests/_internal_utils.py,sha256=nMQymr4hs32TqVo5AbCrmcJEhvPUh7xXlluyqwslLiQ,1495
|
28 |
+
requests/adapters.py,sha256=v_FmjU5KZ76k-YttShZYB5RprIzhhL8Y3zgW9p4eBQ8,19553
|
29 |
+
requests/api.py,sha256=q61xcXq4tmiImrvcSVLTbFyCiD2F-L_-hWKGbz4y8vg,6449
|
30 |
+
requests/auth.py,sha256=h-HLlVx9j8rKV5hfSAycP2ApOSglTz77R0tz7qCbbEE,10187
|
31 |
+
requests/certs.py,sha256=Z9Sb410Anv6jUFTyss0jFFhU6xst8ctELqfy8Ev23gw,429
|
32 |
+
requests/compat.py,sha256=yxntVOSEHGMrn7FNr_32EEam1ZNAdPRdSE13_yaHzTk,1451
|
33 |
+
requests/cookies.py,sha256=kD3kNEcCj-mxbtf5fJsSaT86eGoEYpD3X0CSgpzl7BM,18560
|
34 |
+
requests/exceptions.py,sha256=DhveFBclVjTRxhRduVpO-GbMYMID2gmjdLfNEqNpI_U,3811
|
35 |
+
requests/help.py,sha256=gPX5d_H7Xd88aDABejhqGgl9B1VFRTt5BmiYvL3PzIQ,3875
|
36 |
+
requests/hooks.py,sha256=CiuysiHA39V5UfcCBXFIx83IrDpuwfN9RcTUgv28ftQ,733
|
37 |
+
requests/models.py,sha256=-DlKi0or8gFAM6VzutobXvvBW_2wrJuOF5NfndTIddA,35223
|
38 |
+
requests/packages.py,sha256=DXgv-FJIczZITmv0vEBAhWj4W-5CGCIN_ksvgR17Dvs,957
|
39 |
+
requests/sessions.py,sha256=-LvTzrPtetSTrR3buxu4XhdgMrJFLB1q5D7P--L2Xhw,30373
|
40 |
+
requests/status_codes.py,sha256=FvHmT5uH-_uimtRz5hH9VCbt7VV-Nei2J9upbej6j8g,4235
|
41 |
+
requests/structures.py,sha256=-IbmhVz06S-5aPSZuUthZ6-6D9XOjRuTXHOabY041XM,2912
|
42 |
+
requests/utils.py,sha256=6sx2X3cIVA8BgWOg8odxFy-_lbWDFETU8HI4fU4Rmqw,33448
|
env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/WHEEL
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Wheel-Version: 1.0
|
2 |
+
Generator: bdist_wheel (0.40.0)
|
3 |
+
Root-Is-Purelib: true
|
4 |
+
Tag: py3-none-any
|
5 |
+
|
env-llmeval/lib/python3.10/site-packages/requests-2.31.0.dist-info/top_level.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
requests
|
env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/PKG-INFO
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: rouge-score
|
3 |
+
Version: 0.1.2
|
4 |
+
Summary: Pure python implementation of ROUGE-1.5.5.
|
5 |
+
Home-page: https://github.com/google-research/google-research/tree/master/rouge
|
6 |
+
Author: Google LLC
|
7 |
+
Author-email: [email protected]
|
8 |
+
License: UNKNOWN
|
9 |
+
Platform: UNKNOWN
|
10 |
+
Classifier: Programming Language :: Python :: 3
|
11 |
+
Classifier: License :: OSI Approved :: Apache Software License
|
12 |
+
Classifier: Operating System :: OS Independent
|
13 |
+
Requires-Python: >=3.7
|
14 |
+
Description-Content-Type: text/markdown
|
15 |
+
|
16 |
+
# Python ROUGE Implementation
|
17 |
+
|
18 |
+
## Overview
|
19 |
+
|
20 |
+
This is a native python implementation of ROUGE, designed to replicate results
|
21 |
+
from the original perl package.
|
22 |
+
|
23 |
+
Maintainers may be contacted at [email protected].
|
24 |
+
|
25 |
+
ROUGE was originally introduced in the paper:
|
26 |
+
|
27 |
+
Lin, Chin-Yew. ROUGE: a Package for Automatic Evaluation of Summaries. In
|
28 |
+
Proceedings of the Workshop on Text Summarization Branches Out (WAS 2004),
|
29 |
+
Barcelona, Spain, July 25 - 26, 2004.
|
30 |
+
|
31 |
+
## ROUGE for Python
|
32 |
+
|
33 |
+
There are ROUGE implementations available for Python, however some are not
|
34 |
+
native python due to their dependency on the perl script, and others provide
|
35 |
+
differing results when compared with the original implementation. This makes it
|
36 |
+
difficult to directly compare with known results.
|
37 |
+
|
38 |
+
This package is designed to replicate perl results. It implements:
|
39 |
+
|
40 |
+
* ROUGE-N (N-gram) scoring
|
41 |
+
* ROUGE-L (Longest Common Subsequence) scoring
|
42 |
+
* Text normalization
|
43 |
+
* Bootstrap resampling for confidence interval calculation
|
44 |
+
* Optional Porter stemming to remove plurals and word suffixes such as (ing,
|
45 |
+
ion, ment).
|
46 |
+
|
47 |
+
Note that not all options provided by the original perl ROUGE script are
|
48 |
+
supported, but the subset of options that are implemented should replicate the
|
49 |
+
original functionality.
|
50 |
+
|
51 |
+
## Stopword removal
|
52 |
+
|
53 |
+
The original ROUGE perl script implemented optional stopword removal (using the
|
54 |
+
-s parameter). However, there were ~600 stopwords used by ROUGE, borrowed from
|
55 |
+
another now defunct package. This word list contained many words that may not be
|
56 |
+
suited to some tasks, such as day and month names and numbers. It also has no
|
57 |
+
clear license for redistribution. Since we are unable to replicate this
|
58 |
+
functionality precisely we do not include stopword removal.
|
59 |
+
|
60 |
+
## Two flavors of ROUGE-L
|
61 |
+
In the ROUGE paper, two flavors of ROUGE are described:
|
62 |
+
|
63 |
+
1. sentence-level: Compute longest common subsequence (LCS) between two pieces of
|
64 |
+
text. Newlines are ignored. This is called `rougeL` in this package.
|
65 |
+
2. summary-level: Newlines in the text are interpreted as sentence boundaries,
|
66 |
+
and the LCS is computed between each pair of reference and candidate sentences,
|
67 |
+
and something called union-LCS is computed. This is called `rougeLsum` in this
|
68 |
+
package. This is the ROUGE-L reported in *[Get To The Point: Summarization with
|
69 |
+
Pointer-Generator Networks](https://arxiv.org/abs/1704.04368)*, for example.
|
70 |
+
If your references/candidates do not have newline delimiters, you can use the
|
71 |
+
--split_summaries flag (or optional argument in RougeScorer).
|
72 |
+
|
73 |
+
## How to run
|
74 |
+
|
75 |
+
This package compares target files (containing one example per line) with
|
76 |
+
prediction files in the same format. It can be launched as follows (from
|
77 |
+
google-research/):
|
78 |
+
|
79 |
+
```shell
|
80 |
+
python -m rouge.rouge \
|
81 |
+
--target_filepattern=*.targets \
|
82 |
+
--prediction_filepattern=*.decodes \
|
83 |
+
--output_filename=scores.csv \
|
84 |
+
--use_stemmer=true \
|
85 |
+
--split_summaries=true
|
86 |
+
```
|
87 |
+
|
88 |
+
## Using pip
|
89 |
+
```
|
90 |
+
pip install -r rouge/requirements.txt
|
91 |
+
pip install rouge-score
|
92 |
+
```
|
93 |
+
|
94 |
+
Then in python:
|
95 |
+
|
96 |
+
```python
|
97 |
+
from rouge_score import rouge_scorer
|
98 |
+
|
99 |
+
scorer = rouge_scorer.RougeScorer(['rouge1', 'rougeL'], use_stemmer=True)
|
100 |
+
scores = scorer.score('The quick brown fox jumps over the lazy dog',
|
101 |
+
'The quick brown dog jumps on the log.')
|
102 |
+
```
|
103 |
+
|
104 |
+
## License
|
105 |
+
|
106 |
+
Licensed under the
|
107 |
+
[Apache 2.0](https://github.com/google-research/google-research/blob/master/LICENSE)
|
108 |
+
License.
|
109 |
+
|
110 |
+
## Disclaimer
|
111 |
+
|
112 |
+
This is not an official Google product.
|
113 |
+
|
114 |
+
|
env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/SOURCES.txt
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
README.md
|
2 |
+
setup.cfg
|
3 |
+
setup.py
|
4 |
+
rouge_score/__init__.py
|
5 |
+
rouge_score/create_pyrouge_files.py
|
6 |
+
rouge_score/io.py
|
7 |
+
rouge_score/io_test.py
|
8 |
+
rouge_score/rouge.py
|
9 |
+
rouge_score/rouge_scorer.py
|
10 |
+
rouge_score/rouge_scorer_test.py
|
11 |
+
rouge_score/scoring.py
|
12 |
+
rouge_score/scoring_test.py
|
13 |
+
rouge_score/test_util.py
|
14 |
+
rouge_score/tokenize.py
|
15 |
+
rouge_score/tokenize_test.py
|
16 |
+
rouge_score/tokenizers.py
|
17 |
+
rouge_score/tokenizers_test.py
|
18 |
+
rouge_score.egg-info/PKG-INFO
|
19 |
+
rouge_score.egg-info/SOURCES.txt
|
20 |
+
rouge_score.egg-info/dependency_links.txt
|
21 |
+
rouge_score.egg-info/requires.txt
|
22 |
+
rouge_score.egg-info/top_level.txt
|
env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/dependency_links.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/installed-files.txt
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
../rouge_score/__init__.py
|
2 |
+
../rouge_score/__pycache__/__init__.cpython-310.pyc
|
3 |
+
../rouge_score/__pycache__/create_pyrouge_files.cpython-310.pyc
|
4 |
+
../rouge_score/__pycache__/io.cpython-310.pyc
|
5 |
+
../rouge_score/__pycache__/io_test.cpython-310.pyc
|
6 |
+
../rouge_score/__pycache__/rouge.cpython-310.pyc
|
7 |
+
../rouge_score/__pycache__/rouge_scorer.cpython-310.pyc
|
8 |
+
../rouge_score/__pycache__/rouge_scorer_test.cpython-310.pyc
|
9 |
+
../rouge_score/__pycache__/scoring.cpython-310.pyc
|
10 |
+
../rouge_score/__pycache__/scoring_test.cpython-310.pyc
|
11 |
+
../rouge_score/__pycache__/test_util.cpython-310.pyc
|
12 |
+
../rouge_score/__pycache__/tokenize.cpython-310.pyc
|
13 |
+
../rouge_score/__pycache__/tokenize_test.cpython-310.pyc
|
14 |
+
../rouge_score/__pycache__/tokenizers.cpython-310.pyc
|
15 |
+
../rouge_score/__pycache__/tokenizers_test.cpython-310.pyc
|
16 |
+
../rouge_score/create_pyrouge_files.py
|
17 |
+
../rouge_score/io.py
|
18 |
+
../rouge_score/io_test.py
|
19 |
+
../rouge_score/rouge.py
|
20 |
+
../rouge_score/rouge_scorer.py
|
21 |
+
../rouge_score/rouge_scorer_test.py
|
22 |
+
../rouge_score/scoring.py
|
23 |
+
../rouge_score/scoring_test.py
|
24 |
+
../rouge_score/test_util.py
|
25 |
+
../rouge_score/tokenize.py
|
26 |
+
../rouge_score/tokenize_test.py
|
27 |
+
../rouge_score/tokenizers.py
|
28 |
+
../rouge_score/tokenizers_test.py
|
29 |
+
PKG-INFO
|
30 |
+
SOURCES.txt
|
31 |
+
dependency_links.txt
|
32 |
+
requires.txt
|
33 |
+
top_level.txt
|
env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/requires.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
absl-py
|
2 |
+
nltk
|
3 |
+
numpy
|
4 |
+
six>=1.14.0
|
env-llmeval/lib/python3.10/site-packages/rouge_score-0.1.2.egg-info/top_level.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
rouge_score
|
env-llmeval/lib/python3.10/site-packages/tcolorpy/__init__.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import platform
|
2 |
+
|
3 |
+
from .__version__ import __author__, __copyright__, __email__, __license__, __version__
|
4 |
+
from ._const import AnsiBGColor, AnsiFGColor, AnsiStyle
|
5 |
+
from ._truecolor import Color, RGBTuple, tcolor
|
6 |
+
|
7 |
+
|
8 |
+
if platform.system() == "Windows":
|
9 |
+
from ctypes import windll # type: ignore
|
10 |
+
|
11 |
+
# https://docs.microsoft.com/en-us/windows/console/getstdhandle
|
12 |
+
STD_OUTPUT_HANDLE = -11
|
13 |
+
|
14 |
+
# https://docs.microsoft.com/en-us/windows/console/setconsolemode
|
15 |
+
ENABLE_PROCESSED_OUTPUT = 1
|
16 |
+
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
|
17 |
+
|
18 |
+
windll.kernel32.SetConsoleMode(
|
19 |
+
windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE),
|
20 |
+
ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING,
|
21 |
+
)
|
env-llmeval/lib/python3.10/site-packages/tcolorpy/__main__.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import sys
|
3 |
+
|
4 |
+
from ._const import AnsiBGColor, AnsiFGColor, AnsiStyle
|
5 |
+
from ._truecolor import tcolor
|
6 |
+
|
7 |
+
|
8 |
+
def parse_option() -> argparse.Namespace:
|
9 |
+
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
|
10 |
+
|
11 |
+
parser.add_argument("string", help="string to apply styles.")
|
12 |
+
parser.add_argument(
|
13 |
+
"-c",
|
14 |
+
"--color",
|
15 |
+
help="specify a color code (#XXXXXX) or a name. valid names are: {}".format(
|
16 |
+
", ".join([style.name.lower() for style in list(AnsiFGColor)])
|
17 |
+
),
|
18 |
+
)
|
19 |
+
parser.add_argument(
|
20 |
+
"-b",
|
21 |
+
"--bg-color",
|
22 |
+
help="specify a background color code (#XXXXXX) or a name. valid names are: {}".format(
|
23 |
+
", ".join([style.name.lower() for style in list(AnsiBGColor)])
|
24 |
+
),
|
25 |
+
)
|
26 |
+
parser.add_argument(
|
27 |
+
"-s",
|
28 |
+
"--styles",
|
29 |
+
help="specify a comma-separated style. valid values are: {}".format(
|
30 |
+
", ".join([style.name.lower() for style in list(AnsiStyle)])
|
31 |
+
),
|
32 |
+
)
|
33 |
+
parser.add_argument(
|
34 |
+
"--encode",
|
35 |
+
help="output a text encoded with the specified encoding",
|
36 |
+
)
|
37 |
+
|
38 |
+
return parser.parse_args()
|
39 |
+
|
40 |
+
|
41 |
+
def main() -> int:
|
42 |
+
ns = parse_option()
|
43 |
+
|
44 |
+
styles = []
|
45 |
+
if ns.styles:
|
46 |
+
styles = [style for style in ns.styles.split(",")]
|
47 |
+
|
48 |
+
try:
|
49 |
+
ansi_string = tcolor(ns.string, color=ns.color, bg_color=ns.bg_color, styles=styles)
|
50 |
+
except ValueError as e:
|
51 |
+
print(f"{e.__class__.__name__}: {e}", file=sys.stderr)
|
52 |
+
return 1
|
53 |
+
|
54 |
+
if ns.encode:
|
55 |
+
ansi_string = ansi_string.encode(ns.encode) # type: ignore
|
56 |
+
|
57 |
+
print(ansi_string)
|
58 |
+
|
59 |
+
return 0
|
60 |
+
|
61 |
+
|
62 |
+
if __name__ == "__main__":
|
63 |
+
sys.exit(main())
|
env-llmeval/lib/python3.10/site-packages/tcolorpy/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (735 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/tcolorpy/__pycache__/__main__.cpython-310.pyc
ADDED
Binary file (2.11 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/tcolorpy/__pycache__/__version__.cpython-310.pyc
ADDED
Binary file (379 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/tcolorpy/__pycache__/_const.cpython-310.pyc
ADDED
Binary file (1.32 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/tcolorpy/__pycache__/_truecolor.cpython-310.pyc
ADDED
Binary file (7.62 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/tcolorpy/__version__.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__author__ = "Tsuyoshi Hombashi"
|
2 |
+
__copyright__ = f"Copyright 2020, {__author__}"
|
3 |
+
__license__ = "MIT License"
|
4 |
+
__version__ = "0.1.4"
|
5 |
+
__maintainer__ = __author__
|
6 |
+
__email__ = "[email protected]"
|
env-llmeval/lib/python3.10/site-packages/tcolorpy/_const.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from enum import Enum, unique
|
2 |
+
|
3 |
+
|
4 |
+
CSI = "\033["
|
5 |
+
RESET = CSI + "0m"
|
6 |
+
|
7 |
+
|
8 |
+
@unique
|
9 |
+
class AnsiStyle(Enum):
|
10 |
+
BOLD = 1
|
11 |
+
DIM = 2
|
12 |
+
ITALIC = 3
|
13 |
+
UNDERLINE = 4
|
14 |
+
BLINK = 5
|
15 |
+
INVERT = 7
|
16 |
+
STRIKE = 9
|
17 |
+
|
18 |
+
|
19 |
+
class AnsiFGColor(Enum):
|
20 |
+
BLACK = 30
|
21 |
+
RED = 31
|
22 |
+
GREEN = 32
|
23 |
+
YELLOW = 33
|
24 |
+
BLUE = 34
|
25 |
+
MAGENTA = 35
|
26 |
+
CYAN = 36
|
27 |
+
WHITE = 37
|
28 |
+
LIGHTBLACK = 90
|
29 |
+
LIGHTRED = 91
|
30 |
+
LIGHTGREEN = 92
|
31 |
+
LIGHTYELLOW = 93
|
32 |
+
LIGHTBLUE = 94
|
33 |
+
LIGHTMAGENTA = 95
|
34 |
+
LIGHTCYAN = 96
|
35 |
+
LIGHTWHITE = 97
|
36 |
+
LBLACK = 90
|
37 |
+
LRED = 91
|
38 |
+
LGREEN = 92
|
39 |
+
LYELLOW = 93
|
40 |
+
LBLUE = 94
|
41 |
+
LMAGENTA = 95
|
42 |
+
LCYAN = 96
|
43 |
+
LWHITE = 97
|
44 |
+
|
45 |
+
|
46 |
+
class AnsiBGColor(Enum):
|
47 |
+
BLACK = 40
|
48 |
+
RED = 41
|
49 |
+
GREEN = 42
|
50 |
+
YELLOW = 43
|
51 |
+
BLUE = 44
|
52 |
+
MAGENTA = 45
|
53 |
+
CYAN = 46
|
54 |
+
WHITE = 47
|
55 |
+
LIGHTBLACK = 100
|
56 |
+
LIGHTRED = 101
|
57 |
+
LIGHTGREEN = 102
|
58 |
+
LIGHTYELLOW = 103
|
59 |
+
LIGHTBLUE = 104
|
60 |
+
LIGHTMAGENTA = 105
|
61 |
+
LIGHTCYAN = 106
|
62 |
+
LIGHTWHITE = 107
|
63 |
+
LBLACK = 100
|
64 |
+
LRED = 101
|
65 |
+
LGREEN = 102
|
66 |
+
LYELLOW = 103
|
67 |
+
LBLUE = 104
|
68 |
+
LMAGENTA = 105
|
69 |
+
LCYAN = 106
|
70 |
+
LWHITE = 107
|
env-llmeval/lib/python3.10/site-packages/tcolorpy/_truecolor.py
ADDED
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
from collections import namedtuple
|
3 |
+
from colorsys import rgb_to_hsv
|
4 |
+
from enum import Enum
|
5 |
+
from typing import Any, List, Optional, Sequence, Tuple, Type, Union, cast # noqa
|
6 |
+
|
7 |
+
from ._const import CSI, RESET, AnsiBGColor, AnsiFGColor, AnsiStyle
|
8 |
+
|
9 |
+
|
10 |
+
RGBTuple = Tuple[int, int, int]
|
11 |
+
|
12 |
+
HSV = namedtuple("HSV", "hue saturation value")
|
13 |
+
|
14 |
+
_regexp_color_code = re.compile(
|
15 |
+
"^#?(?P<red>[0-9a-f]{2})(?P<green>[0-9a-f]{2})(?P<blue>[0-9a-f]{2})$", re.IGNORECASE
|
16 |
+
)
|
17 |
+
_regexp_normalize = re.compile(r"[\s_-]")
|
18 |
+
name_to_rgb = {
|
19 |
+
"BLACK": (0, 0, 0),
|
20 |
+
"RED": (205, 49, 49),
|
21 |
+
"GREEN": (13, 188, 121),
|
22 |
+
"YELLOW": (229, 229, 16),
|
23 |
+
"BLUE": (36, 114, 200),
|
24 |
+
"MAGENTA": (188, 63, 188),
|
25 |
+
"CYAN": (17, 168, 205),
|
26 |
+
"WHITE": (229, 229, 229),
|
27 |
+
"LIGHTBLACK": (102, 102, 102),
|
28 |
+
"LIGHTRED": (241, 76, 76),
|
29 |
+
"LIGHTGREEN": (35, 209, 139),
|
30 |
+
"LIGHTYELLOW": (245, 245, 67),
|
31 |
+
"LIGHTBLUE": (59, 142, 234),
|
32 |
+
"LIGHTMAGENTA": (214, 112, 214),
|
33 |
+
"LIGHTCYAN": (41, 184, 219),
|
34 |
+
"LIGHTWHITE": (255, 255, 255),
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
def _normalize_name(name: str) -> str:
|
39 |
+
return _regexp_normalize.sub("", name).upper()
|
40 |
+
|
41 |
+
|
42 |
+
class Color:
|
43 |
+
def __init__(self, color: Union["Color", str, RGBTuple]) -> None:
|
44 |
+
self.__name = ""
|
45 |
+
self.__is_color_code_src = False
|
46 |
+
self.__hsv: Optional[HSV] = None
|
47 |
+
|
48 |
+
if color is None:
|
49 |
+
raise TypeError("color must be one of Color/str/RGBTuple")
|
50 |
+
|
51 |
+
if isinstance(color, str):
|
52 |
+
color = _normalize_name(color)
|
53 |
+
try:
|
54 |
+
self.__from_color_name(color)
|
55 |
+
except KeyError:
|
56 |
+
self.__from_color_code(color)
|
57 |
+
|
58 |
+
return
|
59 |
+
|
60 |
+
try:
|
61 |
+
# from a RGBTuple instance
|
62 |
+
self.red, self.green, self.blue = color # type: ignore
|
63 |
+
self.__validate_rgb_value(self.red)
|
64 |
+
self.__validate_rgb_value(self.green)
|
65 |
+
self.__validate_rgb_value(self.blue)
|
66 |
+
except TypeError:
|
67 |
+
# from a Color instance
|
68 |
+
self.__name = color.name # type: ignore
|
69 |
+
self.red, self.green, self.blue = color.red, color.green, color.blue # type: ignore
|
70 |
+
|
71 |
+
def __eq__(self, other: Any) -> bool:
|
72 |
+
if not isinstance(other, Color):
|
73 |
+
return False
|
74 |
+
|
75 |
+
if self.name and other.name:
|
76 |
+
return self.name == other.name
|
77 |
+
elif self.name or other.name:
|
78 |
+
return False
|
79 |
+
|
80 |
+
if all([self.red == other.red, self.green == other.green, self.blue == other.blue]):
|
81 |
+
return True
|
82 |
+
|
83 |
+
return False
|
84 |
+
|
85 |
+
def __ne__(self, other: Any) -> bool:
|
86 |
+
if not isinstance(other, Color):
|
87 |
+
return True
|
88 |
+
|
89 |
+
return not self.__eq__(other)
|
90 |
+
|
91 |
+
def __repr__(self) -> str:
|
92 |
+
items = [f"code={self.color_code}, rgb=({self.red}, {self.green}, {self.blue})"]
|
93 |
+
|
94 |
+
if self.__name:
|
95 |
+
items.append(f"name={self.__name}")
|
96 |
+
|
97 |
+
return "Color({})".format(", ".join(items))
|
98 |
+
|
99 |
+
def __from_color_code(self, color_code: str) -> None:
|
100 |
+
match = _regexp_color_code.search(color_code)
|
101 |
+
if match is None:
|
102 |
+
raise ValueError(f"invalid color code found: {color_code}")
|
103 |
+
|
104 |
+
self.__is_color_code_src = True
|
105 |
+
red, green, blue = match.group(1, 2, 3)
|
106 |
+
self.red = int(red, 16)
|
107 |
+
self.green = int(green, 16)
|
108 |
+
self.blue = int(blue, 16)
|
109 |
+
|
110 |
+
def __from_color_name(self, name: str) -> None:
|
111 |
+
self.red, self.green, self.blue = name_to_rgb[name]
|
112 |
+
self.__name = name
|
113 |
+
|
114 |
+
def __validate_rgb_value(self, n: int) -> None:
|
115 |
+
if not (0 <= n <= 255):
|
116 |
+
raise ValueError("value must be within 0-255")
|
117 |
+
|
118 |
+
@property
|
119 |
+
def name(self) -> str:
|
120 |
+
return self.__name
|
121 |
+
|
122 |
+
@property
|
123 |
+
def is_color_code_src(self) -> bool:
|
124 |
+
return self.__is_color_code_src
|
125 |
+
|
126 |
+
@property
|
127 |
+
def color_code(self) -> str:
|
128 |
+
return f"#{self.red:02x}{self.green:02x}{self.blue:02x}"
|
129 |
+
|
130 |
+
@property
|
131 |
+
def hsv(self) -> HSV:
|
132 |
+
if self.__hsv is None:
|
133 |
+
self.__hsv = HSV(*rgb_to_hsv(self.red / 255, self.green / 255, self.blue / 255))
|
134 |
+
|
135 |
+
return self.__hsv
|
136 |
+
|
137 |
+
def calc_scaler(self) -> int:
|
138 |
+
return self.red + self.green + self.blue
|
139 |
+
|
140 |
+
def calc_complementary(self) -> "Color":
|
141 |
+
rgb = (self.red, self.green, self.blue)
|
142 |
+
n = max(rgb) + min(rgb)
|
143 |
+
return Color((n - self.red, n - self.green, n - self.blue))
|
144 |
+
|
145 |
+
|
146 |
+
def _normalize_enum(value: Any, enum_class: Type[Enum]) -> Any:
|
147 |
+
if isinstance(value, enum_class):
|
148 |
+
return value
|
149 |
+
|
150 |
+
try:
|
151 |
+
return enum_class[_normalize_name(value)]
|
152 |
+
except AttributeError:
|
153 |
+
raise TypeError(f"value must be a {enum_class} or a str: actual={type(value)}")
|
154 |
+
except KeyError:
|
155 |
+
raise ValueError(
|
156 |
+
"invalid value found: expected={}, actual={}".format(
|
157 |
+
"/".join([item.name for item in enum_class]), value
|
158 |
+
)
|
159 |
+
)
|
160 |
+
|
161 |
+
|
162 |
+
def _ansi_escape(value: str) -> str:
|
163 |
+
return f"{CSI}{value}m"
|
164 |
+
|
165 |
+
|
166 |
+
def _to_ansi_style(style: Union[str, AnsiStyle]) -> str:
|
167 |
+
return _ansi_escape(f"{_normalize_enum(style, AnsiStyle).value}")
|
168 |
+
|
169 |
+
|
170 |
+
def _to_ansi_fg_truecolor(color: Color) -> str:
|
171 |
+
return _ansi_escape(f"38;2;{color.red};{color.green};{color.blue}")
|
172 |
+
|
173 |
+
|
174 |
+
def _to_ansi_bg_truecolor(color: Color) -> str:
|
175 |
+
return _ansi_escape(f"48;2;{color.red};{color.green};{color.blue}")
|
176 |
+
|
177 |
+
|
178 |
+
def _to_ansi_fg_color(color: AnsiFGColor) -> str:
|
179 |
+
return _ansi_escape(f"{color.value}")
|
180 |
+
|
181 |
+
|
182 |
+
def _to_ansi_bg_color(color: AnsiBGColor) -> str:
|
183 |
+
return _ansi_escape(f"{color.value}")
|
184 |
+
|
185 |
+
|
186 |
+
def _make_ansi_fg_truecolor(color: Union[Color, str, RGBTuple, AnsiFGColor, None]) -> str:
|
187 |
+
if isinstance(color, AnsiFGColor):
|
188 |
+
return _to_ansi_fg_color(color)
|
189 |
+
|
190 |
+
if isinstance(color, Color):
|
191 |
+
if color.name:
|
192 |
+
return _to_ansi_fg_color(_normalize_enum(color.name, AnsiFGColor))
|
193 |
+
|
194 |
+
return _to_ansi_fg_truecolor(color)
|
195 |
+
|
196 |
+
if isinstance(color, str):
|
197 |
+
try:
|
198 |
+
return _to_ansi_fg_color(_normalize_enum(color, AnsiFGColor))
|
199 |
+
except ValueError:
|
200 |
+
c = Color(color)
|
201 |
+
elif isinstance(color, (tuple, list)):
|
202 |
+
c = Color(color)
|
203 |
+
else:
|
204 |
+
c = color # type: ignore
|
205 |
+
|
206 |
+
return _to_ansi_fg_truecolor(c) if c else ""
|
207 |
+
|
208 |
+
|
209 |
+
def _make_ansi_bg_truecolor(color: Union[Color, str, RGBTuple, AnsiBGColor, None]) -> str:
|
210 |
+
if isinstance(color, AnsiBGColor):
|
211 |
+
return _to_ansi_bg_color(color)
|
212 |
+
|
213 |
+
if isinstance(color, Color):
|
214 |
+
if color.name:
|
215 |
+
return _to_ansi_bg_color(_normalize_enum(color.name, AnsiBGColor))
|
216 |
+
|
217 |
+
return _to_ansi_bg_truecolor(color)
|
218 |
+
|
219 |
+
if isinstance(color, str):
|
220 |
+
try:
|
221 |
+
return _to_ansi_bg_color(_normalize_enum(color, AnsiBGColor))
|
222 |
+
except ValueError:
|
223 |
+
c = Color(color)
|
224 |
+
elif isinstance(color, (tuple, list)):
|
225 |
+
c = Color(color)
|
226 |
+
else:
|
227 |
+
c = color # type: ignore
|
228 |
+
|
229 |
+
return _to_ansi_bg_truecolor(c) if c else ""
|
230 |
+
|
231 |
+
|
232 |
+
def tcolor(
|
233 |
+
string: str,
|
234 |
+
color: Union[Color, str, RGBTuple, AnsiFGColor, None] = None,
|
235 |
+
bg_color: Union[Color, str, RGBTuple, AnsiBGColor, None] = None,
|
236 |
+
styles: Optional[Sequence[Union[str, AnsiStyle]]] = None,
|
237 |
+
) -> str:
|
238 |
+
ansi_fg_color = _make_ansi_fg_truecolor(color)
|
239 |
+
ansi_bg_color = _make_ansi_bg_truecolor(bg_color)
|
240 |
+
|
241 |
+
ansi_styles: List[str] = []
|
242 |
+
if styles:
|
243 |
+
ansi_styles = [_to_ansi_style(style) for style in styles]
|
244 |
+
|
245 |
+
reset = RESET
|
246 |
+
if not ansi_fg_color and not ansi_bg_color and not ansi_styles:
|
247 |
+
reset = ""
|
248 |
+
|
249 |
+
return "".join(ansi_styles + [ansi_bg_color, ansi_fg_color, string, reset])
|
env-llmeval/lib/python3.10/site-packages/tcolorpy/py.typed
ADDED
File without changes
|