Giter Site home page Giter Site logo

python_xid's Issues

Missing typing requirement

  • Python version: 2.7.13
  • xid==1.0.4
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)

The generated xid string is not always reversible via `Xid.from_string`

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 ===============================================

TypeError: 'map' object is not subscriptable

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.

Update PyPi Package

Please make an update to PyPi package for Python3 support. The released package still throws errors for map(ord, val).

Add Python 3 suppport

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.

python_xid is not thread-safe

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.