From 49d6219e78436e026269615679b56ef6625ef0a8 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 26 Dec 2021 18:37:07 +0000 Subject: [PATCH] Snake case --- daemon.py | 4 ++-- tests.py | 6 +++--- utils.py | 32 ++++++++++++++++---------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/daemon.py b/daemon.py index 261c7945c..b3879613d 100644 --- a/daemon.py +++ b/daemon.py @@ -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 diff --git a/tests.py b/tests.py index c385688b9..850a527a6 100644 --- a/tests.py +++ b/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: diff --git a/utils.py b/utils.py index c720cf976..2872866f0 100644 --- a/utils.py +++ b/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: