golden hour
/opt/alt/python311/lib64/python3.11
⬆️ Go Up
Upload
File/Folder
Size
Actions
LICENSE.txt
13.61 KB
Del
OK
__future__.py
5.1 KB
Del
OK
__hello__.py
227 B
Del
OK
__pycache__
-
Del
OK
_aix_support.py
3.31 KB
Del
OK
_bootsubprocess.py
2.61 KB
Del
OK
_collections_abc.py
29.49 KB
Del
OK
_compat_pickle.py
8.56 KB
Del
OK
_compression.py
5.55 KB
Del
OK
_markupbase.py
14.31 KB
Del
OK
_osx_support.py
21.51 KB
Del
OK
_py_abc.py
6.04 KB
Del
OK
_pydecimal.py
223.83 KB
Del
OK
_pyio.py
91.99 KB
Del
OK
_sitebuiltins.py
3.05 KB
Del
OK
_strptime.py
24.58 KB
Del
OK
_sysconfigdata__linux_x86_64-linux-gnu.py
57.93 KB
Del
OK
_sysconfigdata_d_linux_x86_64-linux-gnu.py
57.16 KB
Del
OK
_threading_local.py
7.05 KB
Del
OK
_weakrefset.py
5.75 KB
Del
OK
abc.py
6.38 KB
Del
OK
aifc.py
33.41 KB
Del
OK
antigravity.py
500 B
Del
OK
argparse.py
97.93 KB
Del
OK
ast.py
60 KB
Del
OK
asynchat.py
11.3 KB
Del
OK
asyncio
-
Del
OK
asyncore.py
19.83 KB
Del
OK
base64.py
20.55 KB
Del
OK
bdb.py
31.7 KB
Del
OK
bisect.py
3.06 KB
Del
OK
bz2.py
11.57 KB
Del
OK
cProfile.py
6.21 KB
Del
OK
calendar.py
24.15 KB
Del
OK
cgi.py
33.63 KB
Del
OK
cgitb.py
12.13 KB
Del
OK
chunk.py
5.37 KB
Del
OK
cmd.py
14.52 KB
Del
OK
code.py
10.37 KB
Del
OK
codecs.py
36.28 KB
Del
OK
codeop.py
5.77 KB
Del
OK
collections
-
Del
OK
colorsys.py
3.97 KB
Del
OK
compileall.py
19.78 KB
Del
OK
concurrent
-
Del
OK
config-3.11-x86_64-linux-gnu
-
Del
OK
configparser.py
54.36 KB
Del
OK
contextlib.py
26.77 KB
Del
OK
contextvars.py
129 B
Del
OK
copy.py
8.48 KB
Del
OK
copyreg.py
7.5 KB
Del
OK
crypt.py
3.82 KB
Del
OK
csv.py
15.65 KB
Del
OK
ctypes
-
Del
OK
curses
-
Del
OK
dataclasses.py
57.1 KB
Del
OK
datetime.py
89.68 KB
Del
OK
dbm
-
Del
OK
decimal.py
320 B
Del
OK
difflib.py
81.36 KB
Del
OK
dis.py
28.23 KB
Del
OK
distutils
-
Del
OK
doctest.py
103.81 KB
Del
OK
email
-
Del
OK
encodings
-
Del
OK
ensurepip
-
Del
OK
enum.py
77.72 KB
Del
OK
filecmp.py
9.94 KB
Del
OK
fileinput.py
15.35 KB
Del
OK
fnmatch.py
5.86 KB
Del
OK
fractions.py
28 KB
Del
OK
ftplib.py
34.98 KB
Del
OK
functools.py
37.51 KB
Del
OK
genericpath.py
5.12 KB
Del
OK
getopt.py
7.31 KB
Del
OK
getpass.py
5.85 KB
Del
OK
gettext.py
20.82 KB
Del
OK
glob.py
8.53 KB
Del
OK
graphlib.py
9.43 KB
Del
OK
gzip.py
23.51 KB
Del
OK
hashlib.py
11.49 KB
Del
OK
heapq.py
22.48 KB
Del
OK
hmac.py
7.54 KB
Del
OK
html
-
Del
OK
http
-
Del
OK
imaplib.py
53.92 KB
Del
OK
imghdr.py
3.86 KB
Del
OK
imp.py
10.36 KB
Del
OK
importlib
-
Del
OK
inspect.py
120.53 KB
Del
OK
io.py
4.22 KB
Del
OK
ipaddress.py
79.51 KB
Del
OK
json
-
Del
OK
keyword.py
1.04 KB
Del
OK
lib-dynload
-
Del
OK
lib2to3
-
Del
OK
linecache.py
5.52 KB
Del
OK
locale.py
77.24 KB
Del
OK
logging
-
Del
OK
lzma.py
12.97 KB
Del
OK
mailbox.py
76.98 KB
Del
OK
mailcap.py
9.15 KB
Del
OK
mimetypes.py
22.42 KB
Del
OK
modulefinder.py
23.14 KB
Del
OK
multiprocessing
-
Del
OK
netrc.py
6.77 KB
Del
OK
nntplib.py
40.12 KB
Del
OK
ntpath.py
28.09 KB
Del
OK
nturl2path.py
2.82 KB
Del
OK
numbers.py
10.11 KB
Del
OK
opcode.py
10.2 KB
Del
OK
operator.py
10.71 KB
Del
OK
optparse.py
58.95 KB
Del
OK
os.py
38.6 KB
Del
OK
pathlib.py
47.43 KB
Del
OK
pdb.py
62.68 KB
Del
OK
pickle.py
63.61 KB
Del
OK
pickletools.py
91.66 KB
Del
OK
pipes.py
8.77 KB
Del
OK
pkgutil.py
24.06 KB
Del
OK
platform.py
41.3 KB
Del
OK
plistlib.py
27.92 KB
Del
OK
poplib.py
14.84 KB
Del
OK
posixpath.py
16.67 KB
Del
OK
pprint.py
24.01 KB
Del
OK
profile.py
22.36 KB
Del
OK
pstats.py
28.67 KB
Del
OK
pty.py
6.17 KB
Del
OK
py_compile.py
7.65 KB
Del
OK
pyclbr.py
11.13 KB
Del
OK
pydoc.py
110.02 KB
Del
OK
pydoc_data
-
Del
OK
queue.py
11.23 KB
Del
OK
quopri.py
7.11 KB
Del
OK
random.py
31.41 KB
Del
OK
re
-
Del
OK
reprlib.py
5.31 KB
Del
OK
rlcompleter.py
7.64 KB
Del
OK
runpy.py
12.85 KB
Del
OK
sched.py
6.2 KB
Del
OK
secrets.py
1.98 KB
Del
OK
selectors.py
19.21 KB
Del
OK
shelve.py
8.36 KB
Del
OK
shlex.py
13.18 KB
Del
OK
shutil.py
55.19 KB
Del
OK
signal.py
2.44 KB
Del
OK
site-packages
-
Del
OK
site.py
22.45 KB
Del
OK
smtpd.py
30.44 KB
Del
OK
smtplib.py
44.37 KB
Del
OK
sndhdr.py
7.27 KB
Del
OK
socket.py
36.68 KB
Del
OK
socketserver.py
26.94 KB
Del
OK
sqlite3
-
Del
OK
sre_compile.py
231 B
Del
OK
sre_constants.py
232 B
Del
OK
sre_parse.py
229 B
Del
OK
ssl.py
53.03 KB
Del
OK
stat.py
5.36 KB
Del
OK
statistics.py
46.59 KB
Del
OK
string.py
11.51 KB
Del
OK
stringprep.py
12.61 KB
Del
OK
struct.py
257 B
Del
OK
subprocess.py
86.65 KB
Del
OK
sunau.py
18.05 KB
Del
OK
symtable.py
10.13 KB
Del
OK
sysconfig.py
29.6 KB
Del
OK
tabnanny.py
11.05 KB
Del
OK
tarfile.py
109.33 KB
Del
OK
telnetlib.py
22.75 KB
Del
OK
tempfile.py
31.13 KB
Del
OK
textwrap.py
19.26 KB
Del
OK
this.py
1003 B
Del
OK
threading.py
56.87 KB
Del
OK
timeit.py
13.21 KB
Del
OK
token.py
2.33 KB
Del
OK
tokenize.py
25.72 KB
Del
OK
tomllib
-
Del
OK
trace.py
28.51 KB
Del
OK
traceback.py
39.6 KB
Del
OK
tracemalloc.py
17.62 KB
Del
OK
tty.py
879 B
Del
OK
types.py
9.83 KB
Del
OK
typing.py
118.12 KB
Del
OK
unittest
-
Del
OK
urllib
-
Del
OK
uu.py
7.17 KB
Del
OK
uuid.py
26.95 KB
Del
OK
venv
-
Del
OK
warnings.py
20.62 KB
Del
OK
wave.py
21.31 KB
Del
OK
weakref.py
21.01 KB
Del
OK
webbrowser.py
24.56 KB
Del
OK
wsgiref
-
Del
OK
xdrlib.py
5.84 KB
Del
OK
xml
-
Del
OK
xmlrpc
-
Del
OK
zipapp.py
7.36 KB
Del
OK
zipfile.py
92.23 KB
Del
OK
zipimport.py
30.17 KB
Del
OK
zoneinfo
-
Del
OK
Edit: fileinput.py
"""Helper class to quickly write a loop over all standard input files. Typical use is: import fileinput for line in fileinput.input(encoding="utf-8"): process(line) This iterates over the lines of all files listed in sys.argv[1:], defaulting to sys.stdin if the list is empty. If a filename is '-' it is also replaced by sys.stdin and the optional arguments mode and openhook are ignored. To specify an alternative list of filenames, pass it as the argument to input(). A single file name is also allowed. Functions filename(), lineno() return the filename and cumulative line number of the line that has just been read; filelineno() returns its line number in the current file; isfirstline() returns true iff the line just read is the first line of its file; isstdin() returns true iff the line was read from sys.stdin. Function nextfile() closes the current file so that the next iteration will read the first line from the next file (if any); lines not read from the file will not count towards the cumulative line count; the filename is not changed until after the first line of the next file has been read. Function close() closes the sequence. Before any lines have been read, filename() returns None and both line numbers are zero; nextfile() has no effect. After all lines have been read, filename() and the line number functions return the values pertaining to the last line read; nextfile() has no effect. All files are opened in text mode by default, you can override this by setting the mode parameter to input() or FileInput.__init__(). If an I/O error occurs during opening or reading a file, the OSError exception is raised. If sys.stdin is used more than once, the second and further use will return no lines, except perhaps for interactive use, or if it has been explicitly reset (e.g. using sys.stdin.seek(0)). Empty files are opened and immediately closed; the only time their presence in the list of filenames is noticeable at all is when the last file opened is empty. It is possible that the last line of a file doesn't end in a newline character; otherwise lines are returned including the trailing newline. Class FileInput is the implementation; its methods filename(), lineno(), fileline(), isfirstline(), isstdin(), nextfile() and close() correspond to the functions in the module. In addition it has a readline() method which returns the next input line, and a __getitem__() method which implements the sequence behavior. The sequence must be accessed in strictly sequential order; sequence access and readline() cannot be mixed. Optional in-place filtering: if the keyword argument inplace=1 is passed to input() or to the FileInput constructor, the file is moved to a backup file and standard output is directed to the input file. This makes it possible to write a filter that rewrites its input file in place. If the keyword argument backup=".<some extension>" is also given, it specifies the extension for the backup file, and the backup file remains around; by default, the extension is ".bak" and it is deleted when the output file is closed. In-place filtering is disabled when standard input is read. XXX The current implementation does not work for MS-DOS 8+3 filesystems. """ import io import sys, os from types import GenericAlias __all__ = ["input", "close", "nextfile", "filename", "lineno", "filelineno", "fileno", "isfirstline", "isstdin", "FileInput", "hook_compressed", "hook_encoded"] _state = None def input(files=None, inplace=False, backup="", *, mode="r", openhook=None, encoding=None, errors=None): """Return an instance of the FileInput class, which can be iterated. The parameters are passed to the constructor of the FileInput class. The returned instance, in addition to being an iterator, keeps global state for the functions of this module,. """ global _state if _state and _state._file: raise RuntimeError("input() already active") _state = FileInput(files, inplace, backup, mode=mode, openhook=openhook, encoding=encoding, errors=errors) return _state def close(): """Close the sequence.""" global _state state = _state _state = None if state: state.close() def nextfile(): """ Close the current file so that the next iteration will read the first line from the next file (if any); lines not read from the file will not count towards the cumulative line count. The filename is not changed until after the first line of the next file has been read. Before the first line has been read, this function has no effect; it cannot be used to skip the first file. After the last line of the last file has been read, this function has no effect. """ if not _state: raise RuntimeError("no active input()") return _state.nextfile() def filename(): """ Return the name of the file currently being read. Before the first line has been read, returns None. """ if not _state: raise RuntimeError("no active input()") return _state.filename() def lineno(): """ Return the cumulative line number of the line that has just been read. Before the first line has been read, returns 0. After the last line of the last file has been read, returns the line number of that line. """ if not _state: raise RuntimeError("no active input()") return _state.lineno() def filelineno(): """ Return the line number in the current file. Before the first line has been read, returns 0. After the last line of the last file has been read, returns the line number of that line within the file. """ if not _state: raise RuntimeError("no active input()") return _state.filelineno() def fileno(): """ Return the file number of the current file. When no file is currently opened, returns -1. """ if not _state: raise RuntimeError("no active input()") return _state.fileno() def isfirstline(): """ Returns true the line just read is the first line of its file, otherwise returns false. """ if not _state: raise RuntimeError("no active input()") return _state.isfirstline() def isstdin(): """ Returns true if the last line was read from sys.stdin, otherwise returns false. """ if not _state: raise RuntimeError("no active input()") return _state.isstdin() class FileInput: """FileInput([files[, inplace[, backup]]], *, mode=None, openhook=None) Class FileInput is the implementation of the module; its methods filename(), lineno(), fileline(), isfirstline(), isstdin(), fileno(), nextfile() and close() correspond to the functions of the same name in the module. In addition it has a readline() method which returns the next input line, and a __getitem__() method which implements the sequence behavior. The sequence must be accessed in strictly sequential order; random access and readline() cannot be mixed. """ def __init__(self, files=None, inplace=False, backup="", *, mode="r", openhook=None, encoding=None, errors=None): if isinstance(files, str): files = (files,) elif isinstance(files, os.PathLike): files = (os.fspath(files), ) else: if files is None: files = sys.argv[1:] if not files: files = ('-',) else: files = tuple(files) self._files = files self._inplace = inplace self._backup = backup self._savestdout = None self._output = None self._filename = None self._startlineno = 0 self._filelineno = 0 self._file = None self._isstdin = False self._backupfilename = None self._encoding = encoding self._errors = errors # We can not use io.text_encoding() here because old openhook doesn't # take encoding parameter. if (sys.flags.warn_default_encoding and "b" not in mode and encoding is None and openhook is None): import warnings warnings.warn("'encoding' argument not specified.", EncodingWarning, 2) # restrict mode argument to reading modes if mode not in ('r', 'rb'): raise ValueError("FileInput opening mode must be 'r' or 'rb'") self._mode = mode self._write_mode = mode.replace('r', 'w') if openhook: if inplace: raise ValueError("FileInput cannot use an opening hook in inplace mode") if not callable(openhook): raise ValueError("FileInput openhook must be callable") self._openhook = openhook def __del__(self): self.close() def close(self): try: self.nextfile() finally: self._files = () def __enter__(self): return self def __exit__(self, type, value, traceback): self.close() def __iter__(self): return self def __next__(self): while True: line = self._readline() if line: self._filelineno += 1 return line if not self._file: raise StopIteration self.nextfile() # repeat with next file def nextfile(self): savestdout = self._savestdout self._savestdout = None if savestdout: sys.stdout = savestdout output = self._output self._output = None try: if output: output.close() finally: file = self._file self._file = None try: del self._readline # restore FileInput._readline except AttributeError: pass try: if file and not self._isstdin: file.close() finally: backupfilename = self._backupfilename self._backupfilename = None if backupfilename and not self._backup: try: os.unlink(backupfilename) except OSError: pass self._isstdin = False def readline(self): while True: line = self._readline() if line: self._filelineno += 1 return line if not self._file: return line self.nextfile() # repeat with next file def _readline(self): if not self._files: if 'b' in self._mode: return b'' else: return '' self._filename = self._files[0] self._files = self._files[1:] self._startlineno = self.lineno() self._filelineno = 0 self._file = None self._isstdin = False self._backupfilename = 0 # EncodingWarning is emitted in __init__() already if "b" not in self._mode: encoding = self._encoding or "locale" else: encoding = None if self._filename == '-': self._filename = '<stdin>' if 'b' in self._mode: self._file = getattr(sys.stdin, 'buffer', sys.stdin) else: self._file = sys.stdin self._isstdin = True else: if self._inplace: self._backupfilename = ( os.fspath(self._filename) + (self._backup or ".bak")) try: os.unlink(self._backupfilename) except OSError: pass # The next few lines may raise OSError os.rename(self._filename, self._backupfilename) self._file = open(self._backupfilename, self._mode, encoding=encoding, errors=self._errors) try: perm = os.fstat(self._file.fileno()).st_mode except OSError: self._output = open(self._filename, self._write_mode, encoding=encoding, errors=self._errors) else: mode = os.O_CREAT | os.O_WRONLY | os.O_TRUNC if hasattr(os, 'O_BINARY'): mode |= os.O_BINARY fd = os.open(self._filename, mode, perm) self._output = os.fdopen(fd, self._write_mode, encoding=encoding, errors=self._errors) try: os.chmod(self._filename, perm) except OSError: pass self._savestdout = sys.stdout sys.stdout = self._output else: # This may raise OSError if self._openhook: # Custom hooks made previous to Python 3.10 didn't have # encoding argument if self._encoding is None: self._file = self._openhook(self._filename, self._mode) else: self._file = self._openhook( self._filename, self._mode, encoding=self._encoding, errors=self._errors) else: self._file = open(self._filename, self._mode, encoding=encoding, errors=self._errors) self._readline = self._file.readline # hide FileInput._readline return self._readline() def filename(self): return self._filename def lineno(self): return self._startlineno + self._filelineno def filelineno(self): return self._filelineno def fileno(self): if self._file: try: return self._file.fileno() except ValueError: return -1 else: return -1 def isfirstline(self): return self._filelineno == 1 def isstdin(self): return self._isstdin __class_getitem__ = classmethod(GenericAlias) def hook_compressed(filename, mode, *, encoding=None, errors=None): if encoding is None and "b" not in mode: # EncodingWarning is emitted in FileInput() already. encoding = "locale" ext = os.path.splitext(filename)[1] if ext == '.gz': import gzip stream = gzip.open(filename, mode) elif ext == '.bz2': import bz2 stream = bz2.BZ2File(filename, mode) else: return open(filename, mode, encoding=encoding, errors=errors) # gzip and bz2 are binary mode by default. if "b" not in mode: stream = io.TextIOWrapper(stream, encoding=encoding, errors=errors) return stream def hook_encoded(encoding, errors=None): def openhook(filename, mode): return open(filename, mode, encoding=encoding, errors=errors) return openhook def _test(): import getopt inplace = False backup = False opts, args = getopt.getopt(sys.argv[1:], "ib:") for o, a in opts: if o == '-i': inplace = True if o == '-b': backup = a for line in input(args, inplace=inplace, backup=backup): if line[-1:] == '\n': line = line[:-1] if line[-1:] == '\r': line = line[:-1] print("%d: %s[%d]%s %s" % (lineno(), filename(), filelineno(), isfirstline() and "*" or "", line)) print("%d: %s[%d]" % (lineno(), filename(), filelineno())) if __name__ == '__main__': _test()
Save