Bug 1393725 - Update slugid python library to 1.0.7. r=gps

This commit is contained in:
John Ford 2017-08-25 11:27:59 +02:00
parent 5289232843
commit a29b277953
6 changed files with 43 additions and 13 deletions

14
third_party/python/slugid/PKG-INFO vendored Normal file
View File

@ -0,0 +1,14 @@
Metadata-Version: 1.1
Name: slugid
Version: 1.0.7
Summary: Base64 encoded uuid v4 slugs
Home-page: http://taskcluster.github.io/slugid.py
Author: Pete Moore
Author-email: pmoore@mozilla.com
License: MPL 2.0
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.5

View File

@ -5,8 +5,9 @@ slugid.py - Compressed UUIDs for python
|Build Status| |Coverage Status| |License| |pypi Version| |Downloads|
A python module for generating v4 UUIDs and encoding them into 22 character
URL-safe base64 slug representation (see `RFC 4648 sec. 5`_).
A python 2.7 and python 3.5 compatible module for generating v4 UUIDs and
encoding them into 22 character URL-safe base64 slug representation (see `RFC
4648 sec. 5`_).
Slugs are url-safe base64 encoded v4 uuids, stripped of base64 ``=`` padding.

5
third_party/python/slugid/setup.cfg vendored Normal file
View File

@ -0,0 +1,5 @@
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0

2
third_party/python/slugid/setup.py vendored Normal file → Executable file
View File

@ -1,7 +1,6 @@
#!/usr/bin/env python
import re
from codecs import open
try:
@ -35,5 +34,6 @@ setup(
'Intended Audience :: Developers',
'Natural Language :: English',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
),
)

View File

@ -34,10 +34,15 @@ Usage:
>>> slugid.v4()
-9OpXaCORAaFh4sJRk7PUA
"""
from .slugid import decode, encode, nice, v4
__title__ = 'slugid'
__version__ = '1.0.6'
__version__ = '1.0.7'
__author__ = 'Peter Moore'
__license__ = 'MPL 2.0'
from .slugid import decode, encode, nice, v4
__all__ = [
'decode',
'encode',
'nice',
'v4',
]

View File

@ -1,29 +1,34 @@
# Licensed under the Mozilla Public Licence 2.0.
# https://www.mozilla.org/en-US/MPL/2.0
import sys
import uuid
import base64
def encode(uuid_):
"""
Returns the given uuid.UUID object as a 22 character slug. This can be a
regular v4 slug or a "nice" slug.
Returns the given uuid.UUID object as a 22 character slug. This can be a
regular v4 slug or a "nice" slug.
"""
return base64.urlsafe_b64encode(uuid_.bytes)[:-2] # Drop '==' padding
return base64.urlsafe_b64encode(uuid_.bytes)[:-2] # Drop '==' padding
def decode(slug):
"""
Returns the uuid.UUID object represented by the given v4 or "nice" slug
"""
return uuid.UUID(bytes=base64.urlsafe_b64decode(slug + '==')) # b64 padding
if sys.version_info.major != 2 and isinstance(slug, bytes):
slug = slug.decode('ascii')
slug = slug + '==' # base64 padding
return uuid.UUID(bytes=base64.urlsafe_b64decode(slug))
def v4():
"""
Returns a randomly generated uuid v4 compliant slug
"""
return base64.urlsafe_b64encode(uuid.uuid4().bytes)[:-2] # Drop '==' padding
return base64.urlsafe_b64encode(uuid.uuid4().bytes)[:-2] # Drop '==' padding
def nice():
@ -38,6 +43,6 @@ def nice():
Potentially other "nice" properties may be added in future to further
restrict the range of potential uuids that may be generated.
"""
rawBytes = uuid.uuid4().bytes
rawBytes = chr(ord(rawBytes[0]) & 0x7f) + rawBytes[1:] # Ensure slug starts with [A-Za-f]
rawBytes = bytearray(uuid.uuid4().bytes)
rawBytes[0] = rawBytes[0] & 0x7f # Ensure slug starts with [A-Za-f]
return base64.urlsafe_b64encode(rawBytes)[:-2] # Drop '==' padding