Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apachedex
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
apachedex
Commits
3cc66082
Commit
3cc66082
authored
Dec 27, 2023
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a context manager for logfile resource management
parent
466146fb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
81 deletions
+90
-81
apachedex/__init__.py
apachedex/__init__.py
+90
-81
No files found.
apachedex/__init__.py
View file @
3cc66082
...
@@ -42,6 +42,7 @@
...
@@ -42,6 +42,7 @@
from
html
import
escape
from
html
import
escape
from
collections
import
defaultdict
,
Counter
from
collections
import
defaultdict
,
Counter
from
contextlib
import
nullcontext
from
datetime
import
datetime
,
timedelta
,
date
,
tzinfo
from
datetime
import
datetime
,
timedelta
,
date
,
tzinfo
from
functools
import
partial
from
functools
import
partial
from
operator
import
itemgetter
from
operator
import
itemgetter
...
@@ -1520,6 +1521,7 @@ def main():
...
@@ -1520,6 +1521,7 @@ def main():
file=sys.stderr)
file=sys.stderr)
if filename == '
-
':
if filename == '
-
':
logfile = sys.stdin
logfile = sys.stdin
logfile_context = nullcontext()
else:
else:
for opener, exc in FILE_OPENER_LIST:
for opener, exc in FILE_OPENER_LIST:
logfile = opener(filename, '
rt
', encoding=INPUT_ENCODING, errors=INPUT_ENCODING_ERROR_HANDLER)
logfile = opener(filename, '
rt
', encoding=INPUT_ENCODING, errors=INPUT_ENCODING_ERROR_HANDLER)
...
@@ -1531,7 +1533,14 @@ def main():
...
@@ -1531,7 +1533,14 @@ def main():
logfile.seek(0)
logfile.seek(0)
break
break
else:
else:
logfile = open(filename, 'r', encoding=INPUT_ENCODING, errors=INPUT_ENCODING_ERROR_HANDLER)
logfile = open( # pylint: disable=consider-using-with
filename,
'r',
encoding=INPUT_ENCODING,
errors=INPUT_ENCODING_ERROR_HANDLER,
)
logfile_context = logfile
with logfile_context:
lineno = 0
lineno = 0
for lineno, line in enumerate(logfile, 1):
for lineno, line in enumerate(logfile, 1):
if show_progress and lineno % 5000 == 0:
if show_progress and lineno % 5000 == 0:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment