Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ genrst/
.DS_Store

*.egg-info
.venv
.venv

# VSCode
settings.json

.coverage
21 changes: 21 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[MESSAGES CONTROL]
disable=
invalid-name, # C0103
missing-module-docstring, # C0114
missing-class-docstring, # C0115
missing-function-docstring, # C0116
consider-using-f-string, # C0209
line-too-long, # C0301
; trailing-whitespace, # C0303
import-outside-toplevel, # C0415
; unsubscriptable-object, # E1136
too-many-instance-attributes, # R0902
too-few-public-methods, # R0903
too-many-return-statements, # R0911
; too-many-branches, # R0912
; too-many-arguments, # R0913
too-many-locals, # R0914
; too-many-positional-arguments, # R0917
unused-argument # W0613
; bare-except, # W0702
; broad-exception-raised, # W0719
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,22 @@
# urtypes

Python implementation of the [Blockchain Commons UR Types specification](https://github.com/BlockchainCommons/Research/blob/master/papers/bcr-2020-006-urtypes.md).

## Development

Execute **tests**:
```
poetry run pytest tests
```

See **coverage**:
```
poetry run pytest --cov=urtypes --cov-report=term-missing --cov-report=html
```

**Before commit, check pylint, vulture and format with black**:
```
poetry run pylint src
poetry run vulture src
poetry run black src
```
434 changes: 298 additions & 136 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ python = "^3.10"
pytest = "^6.2.5"
pytest-mock = "^3.6.1"
pytest-cov = "^3.0.0"
black = "^22.1.0"
black = "^22.1.0"
vulture = "^2.14"
pylint = "^4.0.2"
4 changes: 0 additions & 4 deletions src/urtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,3 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from .registry import *
from .bytes import *
from .crypto import *
6 changes: 1 addition & 5 deletions src/urtypes/bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from urtypes import RegistryType, RegistryItem
from .registry import RegistryType, RegistryItem

BYTES = RegistryType("bytes", None)


class Bytes(RegistryItem):
def __init__(self, data):
super().__init__()
self.data = data

def __eq__(self, o):
return self.data == o.data

@classmethod
def registry_type(cls):
return BYTES
Expand Down
4 changes: 0 additions & 4 deletions src/urtypes/cbor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from .data import *
from .decoder import *
from .encoder import *
48 changes: 21 additions & 27 deletions src/urtypes/cbor/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,53 +24,47 @@
# coding: utf-8


class Tagging(object):
class Tagging:
__slots__ = ("tag", "obj")

def __init__(self, tag, obj):
self.tag = tag
self.obj = obj

def __eq__(self, other):
return (
isinstance(other, Tagging)
and self.tag == other.tag
and self.obj == other.obj
)

class Mapping:
__slots__ = ("map",)

class Mapping(object):
__slots__ = "map"

def __init__(self, map):
self.map = map
def __init__(self, _map):
self.map = _map

@staticmethod
def mapping(obj):
return Mapping(obj)


class DataItem(Tagging):
def __init__(self, tag, map):
super().__init__(tag, Mapping(map))
def __init__(self, tag, _map):
super().__init__(tag, Mapping(_map))
self.tag = tag
self.map = map
self.map = _map


class _Undefined(object):
_instance = None
# class _Undefined:
# _instance = None

def __new__(cls, *args, **kwargs):
if not isinstance(cls._instance, cls):
cls._instance = object.__new__(cls, *args, **kwargs)
return cls._instance
# def __new__(cls, *args, **kwargs):
# if not isinstance(cls._instance, cls):
# cls._instance = object.__new__(cls, *args, **kwargs)
# return cls._instance

def __str__(self):
return "Undefined"
# def __str__(self):
# return "Undefined"

def __repr__(self):
return "Undefined"
# def __repr__(self):
# return "Undefined"


Undefined = _Undefined()
# Undefined = _Undefined()

__all__ = ["Tagging", "Mapping", "DataItem"]
__all__ = ("Tagging", "Mapping", "DataItem")
Loading
Loading