graham / python_xid Goto Github PK
View Code? Open in Web Editor NEWPython Xid Implementation
License: MIT License
Python Xid Implementation
License: MIT License
Please make an update to PyPi package for Python3 support. The released package still throws errors for map(ord, val).
I've simply install xid using command pip install xid
then created a simple file to check if it's working fine or not.
first.py
from xid import Xid
guid = Xid()
print(guid.string())
and then run it as below, but could not run and getting the exception as below.
root@f0b2d7f8a449:/demo# python first.py
Traceback (most recent call last):
File "first.py", line 2, in <module>
guid = Xid()
File "/usr/local/lib/python3.8/site-packages/xid.py", line 92, in __init__
id = generate_new_xid()
File "/usr/local/lib/python3.8/site-packages/xid.py", line 71, in generate_new_xid
id[4] = machineID[0]
TypeError: 'map' object is not subscriptable
root@f0b2d7f8a449:/demo#
If any one can check and help me to fix this issue would be great. tx.
web_1 | from lib.flask_request_id import RequestID
web_1 | File "/usr/share/Amidala/lib/flask_request_id.py", line 2, in <module>
web_1 | from xid import Xid
web_1 | File "/usr/local/lib/python2.7/site-packages/xid.py", line 15, in <module>
web_1 | from typing import List
web_1 | ImportError: No module named typing
web_1 | [2017-10-16 03:01:43 +0000] [9] [INFO] Worker exiting (pid: 9)
I have made a commit to reveal this issue.
This commit added a test case that may failed occasionally.
If you run the below test command multiple times, errors may occure:
$ py.test -sx
Exception in thread Thread-10:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/wonder/workspace/python_xid/xid_test.py", line 79, in worker
threading.current_thread().ident, Xid().string()
File "/home/wonder/workspace/python_xid/xid.py", line 95, in __init__
id = generate_new_xid()
File "/home/wonder/workspace/python_xid/xid.py", line 81, in generate_new_xid
i = next(objectIDGenerator)
ValueError: generator already executing
We can make another commit to fix the issue...
PS: I don't know why
py.test
without-s
option cannot reveal this issue.
I've written a test case to reveal this issue.
Execute py.test
to reproduce error like below:
$ py.test
====================================================== test session starts =======================================================
platform linux2 -- Python 2.7.12, pytest-3.2.5, py-1.5.2, pluggy-0.4.0
rootdir: /home/wonder/workspace/python_xid, inifile:
collected 10 items
xid_test.py .........F
============================================================ FAILURES ============================================================
_______________________________________________ TestXid.test_xid_always_reversible _______________________________________________
self = <xid_test.TestXid testMethod=test_xid_always_reversible>
def test_xid_always_reversible(self):
for i in range(1000):
s = Xid().string()
> self.assertEqual(Xid.from_string(s).string(), s)
xid_test.py:50:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'xid.Xid'>, s = 'b8edi0qo1j65kvnoejvg'
@classmethod
def from_string(cls, s):
# type: (str) -> Xid
val = base32hex.b32decode(s.upper())
value_check = [0 < x < 255 for x in val]
if not all(value_check):
> raise InvalidXid(s)
E InvalidXid: b8edi0qo1j65kvnoejvg
xid.py:152: InvalidXid
=============================================== 1 failed, 9 passed in 0.06 seconds ===============================================
Isn't it, like, 2017 already? A few workarounds will be needed needed to support both py2 nd py3 but, actually, pure py3 code would've been simpler because bytes essentially is a byte array, no map(ord, ...)
needed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.