Skip to content

Commit

Permalink
Merge pull request psf#66 from pR0Ps/master
Browse files Browse the repository at this point in the history
Don't initialize the UserAgent object until one is requested
  • Loading branch information
kennethreitz committed Mar 1, 2018
2 parents b9a7fc3 + b0bd978 commit 2aad96c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion requests_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
DEFAULT_ENCODING = 'utf-8'
DEFAULT_URL = 'https://example.org/'

useragent = UserAgent()
useragent = None

# Typing.
_Find = Union[List['Element'], 'Element']
Expand Down Expand Up @@ -431,6 +431,9 @@ def user_agent(style='chrome') -> _UserAgent:
"""Returns a random user-agent, if not requested one of a specific
style. Defaults to a Chrome-style User-Agent.
"""
global useragent
if not useragent:
useragent = UserAgent()

return useragent[style] if style else useragent.random

Expand Down

0 comments on commit 2aad96c

Please sign in to comment.