Skip to content
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 #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions smartagent/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
agents = pickle.load(open(AGENT_DATASET_LOCATION, 'rb'))
except TypeError:
raise Warning("User-Agent dataset cannot be found! Make sure that AGENT_DATASET_LOCATION is set.")
agents = []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 25-25 refactored with the following changes:


def load_agents():
agents = pickle.load(open(SMART_AGENT_SETTINGS['AGENT_DATASET_LOCATION'], 'rb'))
Expand All @@ -49,24 +48,21 @@ def detect_user_agent(user_agent_string):
"""

start = time.time()
candidates = []
for agent in agents:
if agent['regex'].match(user_agent_string):
candidates.append(agent)
candidates = [
agent for agent in agents if agent['regex'].match(user_agent_string)
]

start = time.time()
candidates.sort(key=lambda x: len(x['name']))

start = time.time()
result = get_user_agent_characteristics(candidates[-1])
return result
return get_user_agent_characteristics(candidates[-1])
Comment on lines -52 to +59
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function detect_user_agent refactored with the following changes:


def all_possible_matches(user_agent_string):
candidates = []
for agent in agents:
if agent['regex'].match(user_agent_string):
candidates.append(agent)

candidates = [
agent for agent in agents if agent['regex'].match(user_agent_string)
]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function all_possible_matches refactored with the following changes:

candidates.sort(key=lambda x: len(x['name']))
return [(item['name'], item['depth']) for item in candidates]

Expand Down