From 2af8c9c1a47014803d7e1eafc1bdeb21c487be6f Mon Sep 17 00:00:00 2001 From: rr- Date: Sat, 9 Apr 2016 22:44:50 +0200 Subject: [PATCH] server/general: cosmetic changes --- server/szurubooru/api/user_api.py | 9 --------- server/szurubooru/db/base.py | 2 -- server/szurubooru/middleware/json_translator.py | 4 ++-- server/szurubooru/util/auth.py | 6 +----- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/server/szurubooru/api/user_api.py b/server/szurubooru/api/user_api.py index 227c6b1f..2558eed7 100644 --- a/server/szurubooru/api/user_api.py +++ b/server/szurubooru/api/user_api.py @@ -30,14 +30,11 @@ def _serialize_user(authenticated_user, user): return ret class UserListApi(BaseApi): - ''' API for lists of users. ''' - def __init__(self): super().__init__() self._search_executor = search.SearchExecutor(search.UserSearchConfig()) def get(self, context): - ''' Retrieve a list of users. ''' auth.verify_privilege(context.user, 'users:list') query = context.get_param_as_string('query') page = context.get_param_as_int('page', 1) @@ -51,7 +48,6 @@ class UserListApi(BaseApi): } def post(self, context): - ''' Create a new user. ''' auth.verify_privilege(context.user, 'users:create') try: @@ -69,10 +65,7 @@ class UserListApi(BaseApi): return {'user': _serialize_user(context.user, user)} class UserDetailApi(BaseApi): - ''' API for individual users. ''' - def get(self, context, user_name): - ''' Retrieve an user. ''' auth.verify_privilege(context.user, 'users:view') user = users.get_by_name(context.session, user_name) if not user: @@ -80,7 +73,6 @@ class UserDetailApi(BaseApi): return {'user': _serialize_user(context.user, user)} def put(self, context, user_name): - ''' Update an existing user. ''' user = users.get_by_name(context.session, user_name) if not user: raise errors.NotFoundError('User %r not found.' % user_name) @@ -120,7 +112,6 @@ class UserDetailApi(BaseApi): return {'user': _serialize_user(context.user, user)} def delete(self, context, user_name): - ''' Delete an existing user. ''' user = users.get_by_name(context.session, user_name) if not user: raise errors.NotFoundError('User %r not found.' % user_name) diff --git a/server/szurubooru/db/base.py b/server/szurubooru/db/base.py index d622ddf2..f7e43148 100644 --- a/server/szurubooru/db/base.py +++ b/server/szurubooru/db/base.py @@ -1,4 +1,2 @@ -''' Base model for every database resource. ''' - from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() # pylint: disable=invalid-name diff --git a/server/szurubooru/middleware/json_translator.py b/server/szurubooru/middleware/json_translator.py index a852ee4e..bb15c356 100644 --- a/server/szurubooru/middleware/json_translator.py +++ b/server/szurubooru/middleware/json_translator.py @@ -3,7 +3,7 @@ import datetime import json import falcon -def json_serial(obj): +def json_serializer(obj): ''' JSON serializer for objects not serializable by default JSON code ''' if isinstance(obj, datetime.datetime): serial = obj.isoformat() @@ -52,4 +52,4 @@ class JsonTranslator(object): if 'result' not in request.context: return response.body = json.dumps( - request.context.result, default=json_serial, indent=2) + request.context.result, default=json_serializer, indent=2) diff --git a/server/szurubooru/util/auth.py b/server/szurubooru/util/auth.py index bb7223f3..efdd0d6e 100644 --- a/server/szurubooru/util/auth.py +++ b/server/szurubooru/util/auth.py @@ -20,7 +20,6 @@ def get_legacy_password_hash(salt, password): return digest.hexdigest() def create_password(): - ''' Create an easy-to-remember password. ''' alphabet = { 'c': list('bcdfghijklmnpqrstvwxyz'), 'v': list('aeiou'), @@ -30,7 +29,6 @@ def create_password(): return ''.join(random.choice(alphabet[l]) for l in list(pattern)) def is_valid_password(user, password): - ''' Return whether the given password for a given user is valid. ''' salt, valid_hash = user.password_salt, user.password_hash possible_hashes = [ get_password_hash(salt, password), @@ -39,9 +37,7 @@ def is_valid_password(user, password): return valid_hash in possible_hashes def verify_privilege(user, privilege_name): - ''' - Throw an AuthError if the given user doesn't have given privilege. - ''' + ''' Throw an AuthError if the given user doesn't have given privilege. ''' all_ranks = config.config['ranks'] assert privilege_name in config.config['privileges']