Skip to content

Commit

Permalink
improve pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
federatedsecurecomputing committed Mar 5, 2024
1 parent de20965 commit 15dc7a8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
23 changes: 15 additions & 8 deletions src/federatedsecure/server/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@


class Bus:
"""the bus stores representations of microservices and other server-side objects"""
"""the bus stores representations of
microservices and other server-side objects"""

def __init__(self):
"""initialize the bus"""
Expand All @@ -18,7 +19,8 @@ def get_argument(self, arg):
if isinstance(arg, dict):
if 'representation_uuid' in arg:
if arg['representation_uuid'] in self.lut_uuid_to_repr:
return self.get_argument(self.lut_uuid_to_repr[arg['representation_uuid']])
return self.get_argument(
self.lut_uuid_to_repr[arg['representation_uuid']])
return arg

def get_arguments(self, body):
Expand Down Expand Up @@ -72,22 +74,27 @@ def release_representation(self, representation_uuid):
"""release a representation"""
del self.lut_uuid_to_repr[representation_uuid]

def create_attribute(self, representation_uuid, attribute_name, public=False):
def create_attribute(self, representation_uuid,
attribute_name, public=False):
"""create a representation of an attribute of a representation"""

if public and attribute_name[0] == '_': # public access to private/hidden member
raise federatedsecure.server.exceptions.AttributeNotPublic(attribute_name)
# public access to private/hidden member
if public and attribute_name[0] == '_':
raise federatedsecure.server.exceptions.\
AttributeNotPublic(attribute_name)

try:
obj = self.lut_uuid_to_repr[representation_uuid]
except KeyError as key_error:
raise federatedsecure.server.exceptions.InvalidIdentifier("representation_uuid",
representation_uuid) from key_error
raise federatedsecure.server.exceptions.\
InvalidIdentifier("representation_uuid",
representation_uuid) from key_error

try:
pointer = getattr(obj, attribute_name)
except KeyError as key_error:
raise federatedsecure.server.exceptions.AttributeNotFound(attribute_name) from key_error
raise federatedsecure.server.exceptions.\
AttributeNotFound(attribute_name) from key_error

uuid = str(_uuid.uuid4())
self.lut_uuid_to_repr[uuid] = pointer
Expand Down
8 changes: 5 additions & 3 deletions src/federatedsecure/server/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@


def discover_builtins_and_plugins(registry):
"""discover microservices and classes in federatedsecure.server.services and federatedsecure.server.services"""
"""discover microservices and classes in federatedsecure.server.services
and federatedsecure.server.services"""

for namespace_package in [federatedsecure.services]:
for _, name, _ in pkgutil.iter_modules(namespace_package.__path__,
namespace_package.__name__ + "."):
for _, name, _ in pkgutil.iter_modules(
namespace_package.__path__,
namespace_package.__name__ + "."):
module = importlib.import_module(name)
try:
getattr(module, "federatedsecure_register")(registry)
Expand Down
6 changes: 4 additions & 2 deletions src/federatedsecure/server/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ def __init__(self, missing):


class AttributeNotFound(ApiError):
"""this exception is thrown when a member attribute of an object does not exist"""
"""this exception is thrown when a member
attribute of an object does not exist"""

def __init__(self, missing):
super().__init__(404, f'attribute not available: {missing}')


class AttributeNotPublic(ApiError):
"""this exception is thrown when a hidden/private member attribute of an object is accessed"""
"""this exception is thrown when a hidden/private
member attribute of an object is accessed"""

def __init__(self, missing):
super().__init__(403, f'attribute not public: {missing}')
9 changes: 6 additions & 3 deletions src/federatedsecure/server/registry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""the registry contains items that may be used as root items for representations"""
"""the registry contains items that may
be used as root items for representations"""

import uuid as _uuid

Expand Down Expand Up @@ -28,7 +29,8 @@ def list_representations(self):
return result

def get_representation(self, requirements):
"""check requirements against descriptions and return a matching item if possible"""
"""check requirements against descriptions
and return a matching item if possible"""

for uuid, (description, item) in self.root_objects.items():
for requirement in requirements:
Expand All @@ -39,4 +41,5 @@ def get_representation(self, requirements):
else:
return uuid, item

raise federatedsecure.server.exceptions.RootObjectNotFound(requirements)
raise federatedsecure.server.exceptions.\
RootObjectNotFound(requirements)

0 comments on commit 15dc7a8

Please sign in to comment.