Skip to content

Commit

Permalink
version 0.2.0: GUID() now simply returns a string
Browse files Browse the repository at this point in the history
  • Loading branch information
logileifs committed Dec 20, 2020
1 parent c8f99eb commit 95b72b4
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 29 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ Human friendly GUID/UUID library
```python
>>> from guid import GUID
>>> guid = GUID()
>>> guid.uuid
'd95b880b-fcec-47fb-bcc4-d49f71415cf8'
>>> guid.slug
'2VuIC_zsR_u8xNSfcUFc-A'
>>> guid
'Kj2hvuO5Ra-VU5ghIJVnlQ'
>>> from guid import guid_to_uuid
>>> guid_to_uuid(guid)
UUID('2a3da1be-e3b9-45af-9553-982120956795')
>>> from guid import uuid_to_guid
>>> from uuid import uuid4
>>> u = uuid4()
>>> u
UUID('929f9121-8264-472a-a4ee-ff7557457f12')
>>> uuid_to_guid(u)
'kp-RIYJkRyqk7v91V0V_Eg'
>>> guid_to_uuid('kp-RIYJkRyqk7v91V0V_Eg')
UUID('929f9121-8264-472a-a4ee-ff7557457f12')
```
Binary file added dist/guid-0.2.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/guid-0.2.0.tar.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions guid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from guid.guid import GUID
from guid.guid import slug_to_uuid
from guid.guid import uuid_to_slug
from guid.guid import uuid_to_guid
from guid.guid import guid_to_uuid
24 changes: 4 additions & 20 deletions guid/guid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,14 @@
from base64 import urlsafe_b64encode


def uuid_to_slug(uuid):
def uuid_to_guid(uuid):
return urlsafe_b64encode(uuid.bytes).rstrip(b'=').decode()


def slug_to_uuid(slug):
def guid_to_uuid(slug):
return UUID(bytes=urlsafe_b64decode(slug + '=='))


def guid_to_uuid(guid):
return slug_to_uuid(guid.slug)


class GUID():
def __init__(self):
self.slug = uuid_to_slug(uuid4())

def to_uuid(self):
return guid_to_uuid(self)

def __repr__(self):
return self.slug

def __str__(self):
return self.slug

def __json__(self):
return self.slug
def __new__(self):
return uuid_to_guid(uuid4())
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.poetry]
name = "guid"
version = "0.2.0"
description = "Human friendly GUID/UUID library"
authors = ["Logi Leifsson <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.7"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
15 changes: 15 additions & 0 deletions recipes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
recipes:
test:
vars: {}
steps:
- python -m unittest discover -v -s tests -p "*test*.py"

build:
vars: {}
steps:
- poetry build

publish:
vars: {}
steps:
- poetry publish
16 changes: 13 additions & 3 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
from unittest import TestCase

from guid import GUID
from uuid import uuid4
from guid import uuid_to_guid
from guid import guid_to_uuid


class TestGUID(TestCase):
def test_0(self):
u1 = uuid4()
g = uuid_to_guid(u1)
u2 = guid_to_uuid(g)
self.assertEqual(u1, u2)

def test_1(self):
guid = GUID()
self.assertIsNotNone(guid.uuid)
self.assertIsNotNone(guid.slug)
g1 = GUID()
u = guid_to_uuid(g1)
g2 = uuid_to_guid(u)
self.assertEqual(g1, g2)

0 comments on commit 95b72b4

Please sign in to comment.