mirror of https://gitlab.com/bashrc2/epicyon
Snake case
parent
d2cc61446f
commit
49d6219e78
|
@ -259,7 +259,7 @@ from utils import acct_dir
|
|||
from utils import getImageExtensionFromMimeType
|
||||
from utils import get_image_mime_type
|
||||
from utils import has_object_dict
|
||||
from utils import userAgentDomain
|
||||
from utils import user_agent_domain
|
||||
from utils import isLocalNetworkAddress
|
||||
from utils import permittedDir
|
||||
from utils import isAccountDir
|
||||
|
@ -592,7 +592,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
print('Blocked Crawler: ' + agentStr)
|
||||
return True
|
||||
# get domain name from User-Agent
|
||||
agentDomain = userAgentDomain(agentStr, self.server.debug)
|
||||
agentDomain = user_agent_domain(agentStr, self.server.debug)
|
||||
else:
|
||||
# no User-Agent header is present
|
||||
return True
|
||||
|
|
6
tests.py
6
tests.py
|
@ -66,7 +66,7 @@ from utils import is_group_actor
|
|||
from utils import date_string_to_seconds
|
||||
from utils import date_seconds_to_string
|
||||
from utils import valid_password
|
||||
from utils import userAgentDomain
|
||||
from utils import user_agent_domain
|
||||
from utils import camelCaseSplit
|
||||
from utils import decoded_host
|
||||
from utils import get_full_domain
|
||||
|
@ -5507,10 +5507,10 @@ def _testUserAgentDomain() -> None:
|
|||
print('testUserAgentDomain')
|
||||
userAgent = \
|
||||
'http.rb/4.4.1 (Mastodon/9.10.11; +https://mastodon.something/)'
|
||||
assert userAgentDomain(userAgent, False) == 'mastodon.something'
|
||||
assert user_agent_domain(userAgent, False) == 'mastodon.something'
|
||||
userAgent = \
|
||||
'Mozilla/70.0 (X11; Linux x86_64; rv:1.0) Gecko/20450101 Firefox/1.0'
|
||||
assert userAgentDomain(userAgent, False) is None
|
||||
assert user_agent_domain(userAgent, False) is None
|
||||
|
||||
|
||||
def _testSwitchWords(base_dir: str) -> None:
|
||||
|
|
32
utils.py
32
utils.py
|
@ -2826,28 +2826,28 @@ def permittedDir(path: str) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
def userAgentDomain(userAgent: str, debug: bool) -> str:
|
||||
def user_agent_domain(user_agent: str, debug: bool) -> str:
|
||||
"""If the User-Agent string contains a domain
|
||||
then return it
|
||||
"""
|
||||
if '+http' not in userAgent:
|
||||
if '+http' not in user_agent:
|
||||
return None
|
||||
agentDomain = userAgent.split('+http')[1].strip()
|
||||
if '://' in agentDomain:
|
||||
agentDomain = agentDomain.split('://')[1]
|
||||
if '/' in agentDomain:
|
||||
agentDomain = agentDomain.split('/')[0]
|
||||
if ')' in agentDomain:
|
||||
agentDomain = agentDomain.split(')')[0].strip()
|
||||
if ' ' in agentDomain:
|
||||
agentDomain = agentDomain.replace(' ', '')
|
||||
if ';' in agentDomain:
|
||||
agentDomain = agentDomain.replace(';', '')
|
||||
if '.' not in agentDomain:
|
||||
agent_domain = user_agent.split('+http')[1].strip()
|
||||
if '://' in agent_domain:
|
||||
agent_domain = agent_domain.split('://')[1]
|
||||
if '/' in agent_domain:
|
||||
agent_domain = agent_domain.split('/')[0]
|
||||
if ')' in agent_domain:
|
||||
agent_domain = agent_domain.split(')')[0].strip()
|
||||
if ' ' in agent_domain:
|
||||
agent_domain = agent_domain.replace(' ', '')
|
||||
if ';' in agent_domain:
|
||||
agent_domain = agent_domain.replace(';', '')
|
||||
if '.' not in agent_domain:
|
||||
return None
|
||||
if debug:
|
||||
print('User-Agent Domain: ' + agentDomain)
|
||||
return agentDomain
|
||||
print('User-Agent Domain: ' + agent_domain)
|
||||
return agent_domain
|
||||
|
||||
|
||||
def has_object_dict(post_json_object: {}) -> bool:
|
||||
|
|
Loading…
Reference in New Issue