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