Blacked the code

This commit is contained in:
Eliot Berriot 2018-06-09 15:36:16 +02:00
parent b6fc0051fa
commit 62ca3bd736
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
279 changed files with 8861 additions and 9527 deletions

View file

@ -8,36 +8,35 @@ from . import actors
from . import utils
from . import serializers
VALID_RESOURCE_TYPES = ['acct']
VALID_RESOURCE_TYPES = ["acct"]
def clean_resource(resource_string):
if not resource_string:
raise forms.ValidationError('Invalid resource string')
raise forms.ValidationError("Invalid resource string")
try:
resource_type, resource = resource_string.split(':', 1)
resource_type, resource = resource_string.split(":", 1)
except ValueError:
raise forms.ValidationError('Missing webfinger resource type')
raise forms.ValidationError("Missing webfinger resource type")
if resource_type not in VALID_RESOURCE_TYPES:
raise forms.ValidationError('Invalid webfinger resource type')
raise forms.ValidationError("Invalid webfinger resource type")
return resource_type, resource
def clean_acct(acct_string, ensure_local=True):
try:
username, hostname = acct_string.split('@')
username, hostname = acct_string.split("@")
except ValueError:
raise forms.ValidationError('Invalid format')
raise forms.ValidationError("Invalid format")
if ensure_local and hostname.lower() != settings.FEDERATION_HOSTNAME:
raise forms.ValidationError(
'Invalid hostname {}'.format(hostname))
raise forms.ValidationError("Invalid hostname {}".format(hostname))
if ensure_local and username not in actors.SYSTEM_ACTORS:
raise forms.ValidationError('Invalid username')
raise forms.ValidationError("Invalid username")
return username, hostname
@ -45,12 +44,12 @@ def clean_acct(acct_string, ensure_local=True):
def get_resource(resource_string):
resource_type, resource = clean_resource(resource_string)
username, hostname = clean_acct(resource, ensure_local=False)
url = 'https://{}/.well-known/webfinger?resource={}'.format(
hostname, resource_string)
url = "https://{}/.well-known/webfinger?resource={}".format(
hostname, resource_string
)
response = session.get_session().get(
url,
verify=settings.EXTERNAL_REQUESTS_VERIFY_SSL,
timeout=5)
url, verify=settings.EXTERNAL_REQUESTS_VERIFY_SSL, timeout=5
)
response.raise_for_status()
serializer = serializers.ActorWebfingerSerializer(data=response.json())
serializer.is_valid(raise_exception=True)