-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,7 +209,7 @@ def check_format(self, file): | |
file.seek(0) | ||
return | ||
# Skip the next 2 lines. | ||
for i in xrange(2): | ||
for _ in xrange(2): | ||
file.readline() | ||
# Parse the 4th line (regex) | ||
full_regex = [] | ||
|
@@ -668,7 +668,7 @@ def increment(self): | |
self.value = self.counter.next() | ||
|
||
def advance(self, n): | ||
for i in range(n): | ||
for _ in range(n): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
self.increment() | ||
|
||
def __str__(self): | ||
|
@@ -718,10 +718,7 @@ def _compute_speed(self, value, start, end): | |
delta_time = end - start | ||
if value == 0: | ||
return 0 | ||
if delta_time == 0: | ||
return 'very high!' | ||
else: | ||
return value / delta_time | ||
return 'very high!' if delta_time == 0 else value / delta_time | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def _round_value(self, value, base=100): | ||
return round(value * base) / base | ||
|
@@ -1034,9 +1031,7 @@ def _add_site(self, hit): | |
DynamicResolver._add_site_lock.acquire() | ||
|
||
try: | ||
# After we obtain the lock, make sure the site hasn't already been created. | ||
res = self._get_site_id_from_hit_host(hit) | ||
if res: | ||
if res := self._get_site_id_from_hit_host(hit): | ||
Comment on lines
-1037
to
+1034
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
return res[0]['idsite'] | ||
|
||
# The site doesn't exist. | ||
|
@@ -1071,8 +1066,7 @@ def _add_site(self, hit): | |
DynamicResolver._add_site_lock.release() | ||
|
||
def _resolve(self, hit): | ||
res = self._get_site_id_from_hit_host(hit) | ||
if res: | ||
if res := self._get_site_id_from_hit_host(hit): | ||
Comment on lines
-1074
to
+1069
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
# The site already exists. | ||
site_id = res[0]['idsite'] | ||
else: | ||
|
@@ -1152,7 +1146,7 @@ def launch(cls, recorder_count): | |
""" | ||
Launch a bunch of Recorder objects in a separate thread. | ||
""" | ||
for i in xrange(recorder_count): | ||
for _ in xrange(recorder_count): | ||
Comment on lines
-1155
to
+1149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
recorder = Recorder() | ||
cls.recorders.append(recorder) | ||
|
||
|
@@ -1170,7 +1164,7 @@ def add_hits(cls, all_hits): | |
""" | ||
# Organize hits so that one client IP will always use the same queue. | ||
# We have to do this so visits from the same IP will be added in the right order. | ||
hits_by_client = [[] for r in cls.recorders] | ||
hits_by_client = [[] for _ in cls.recorders] | ||
Comment on lines
-1173
to
+1167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
for hit in all_hits: | ||
hits_by_client[abs(hash(hit.ip)) % len(cls.recorders)].append(hit) | ||
|
||
|
@@ -1446,10 +1440,11 @@ def check_path(self, hit): | |
return False | ||
# By default, all paths are included. | ||
if config.options.included_paths: | ||
for included_path in config.options.included_paths: | ||
if fnmatch.fnmatch(hit.path, included_path): | ||
return True | ||
return False | ||
return any( | ||
fnmatch.fnmatch(hit.path, included_path) | ||
for included_path in config.options.included_paths | ||
) | ||
|
||
Comment on lines
-1449
to
+1447
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return True | ||
|
||
@staticmethod | ||
|
@@ -1503,7 +1498,7 @@ def detect_format(file): | |
limit = 100000 | ||
while not format and lineno < limit: | ||
line = file.readline() | ||
lineno = lineno + 1 | ||
lineno += 1 | ||
Comment on lines
-1506
to
+1501
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
logging.debug("Detecting format against line %i" % lineno) | ||
format = Parser.check_format(line) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,10 @@ | |
|
||
# utility functions | ||
def add_junk_to_file(path): | ||
file = open(path) | ||
contents = file.read() | ||
file.close() | ||
|
||
file = open('tmp.log', 'w') | ||
file.write(contents + ' junk') | ||
file.close() | ||
|
||
with open(path) as file: | ||
contents = file.read() | ||
with open('tmp.log', 'w') as file: | ||
file.write(contents + ' junk') | ||
Comment on lines
-9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return 'tmp.log' | ||
|
||
def tearDownModule(): | ||
|
@@ -185,11 +181,9 @@ def test_replay_tracking_arguments(): | |
|
||
def parse_log_file_line(format_name, file_): | ||
format = import_logs.FORMATS[format_name] | ||
|
||
file = open(file_) | ||
match = format.check_format(file) | ||
file.close() | ||
|
||
|
||
with open(file_) as file: | ||
match = format.check_format(file) | ||
Comment on lines
-188
to
+186
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return format.get_all() | ||
|
||
# check parsing groups | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
IisFormat.check_format
refactored with the following changes:for-index-underscore
)