Skip to content

Commit

Permalink
Merge pull request #44 from Juanlu001/attrs
Browse files Browse the repository at this point in the history
Use attrs everywhere
  • Loading branch information
astrojuanlu committed Nov 6, 2019
2 parents 587e4eb + 0ba9ca3 commit 2e83b28
Show file tree
Hide file tree
Showing 12 changed files with 471 additions and 2,177 deletions.
8 changes: 4 additions & 4 deletions src/czml3/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import warnings
from enum import Enum
from json import JSONEncoder
from typing import List

import attr

from .constants import ISO8601_FORMAT_Z

Expand All @@ -24,9 +25,8 @@ def default(self, o):
return super().default(o)


@attr.s(repr=False, frozen=True)
class BaseCZMLObject:
KNOWN_PROPERTIES = [] # type: List[str]

def __repr__(self):
return self.dumps(indent=4)

Expand All @@ -45,7 +45,7 @@ def to_json(self):
if getattr(self, "delete", False):
properties_list = NON_DELETE_PROPERTIES
else:
properties_list = self.KNOWN_PROPERTIES
properties_list = list(attr.asdict(self).keys())

obj_dict = {}
for property_name in properties_list:
Expand Down
61 changes: 6 additions & 55 deletions src/czml3/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,7 @@
class Deletable:
"""A property whose value may be deleted."""

_delete: bool

@property
def delete(self):
"""
Whether the client should delete existing samples or interval data for this property.
Data will be deleted for the containing interval,
or if there is no containing interval,
then all data.
If true,
all other properties in this property
will be ignored.
"""
return self._delete
delete: bool


# noinspection PyPep8Naming
Expand All @@ -31,49 +17,14 @@ class Interpolatable:
The interpolation happens over provided time-tagged samples.
"""

_epoch: dt.datetime
_interpolation_algorithm: InterpolationAlgorithms
_interpolation_degree: int

@property
def epoch(self):
"""The epoch to use for times specified as seconds since an epoch."""
return self._epoch

@property
def interpolationAlgorithm(self):
"""The interpolation algorithm to use when interpolating."""
return self._interpolation_algorithm

@property
def interpolationDegree(self):
"""The degree of interpolation to use when interpolating."""
return self._interpolation_degree
epoch: dt.datetime
interpolation_algorithm: InterpolationAlgorithms
interpolation_degree: int


# noinspection PyPep8Naming
class HasAlignment:
"""A property that can be horizontally or vertically aligned."""

_horizontal_origin: HorizontalOrigins
_vertical_origin: VerticalOrigins

@property
def horizontalOrigin(self):
"""The horizontal origin of the object.
It controls whether the object is
left-, center-, or right-aligned with the position.
"""
return self._horizontal_origin

@property
def verticalOrigin(self):
"""The vertical origin of the object.
Determines whether the object is
bottom-, center-, or top-aligned with the position.
"""
return self._vertical_origin
horizontal_origin: HorizontalOrigins
vertical_origin: VerticalOrigins

0 comments on commit 2e83b28

Please sign in to comment.