Files
roytam1 0224c91df2 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1170325 - Convert js::Vector into a template alias to mozilla::Vector with a single customized default argument. Also get rid of the CRTP support in mozilla::Vector (through mozilla::VectorBase) now that template aliasing is good enough, and make mozilla::Vector final so that people will use composition and not inheritance with it. (Inheritance plays poorly with movability and a few other things, in addition to messing up template argument deduction matching.) r=Waldo, patch sort of a tag-team between him and me (1f663fc5c1)
- Bug 1225682 - Don't use nsAuto{,C}String as class member variables in toolkit/. r=froydnj (7d47cd8c5f)
- Bug 1209184: Part 1b - [webext] Create a stream converter for localization placeholders. r=billm (1f5f88eccf)
- Bug 1167412 - Always register testing JS modules. r=ted (61246d3c38)
- Bug 1219442 - Re-write specialpowers as a restartless addon, r=jmaher (04b6494438)
- Bug 1217276 - Fix the handling of relativesrcdir for localized chrome data in FasterMake backend. r=mshal (9332ffaa1a)
- Bug 1210703 - fix toolkit theme overlap, r=dao (2b9dcead29)
- Bug 1169714 - Add requests to mach bootstrap SEARCH_PATH, r=jgriffin (35c7732f2e)
- Bug 917999 - Part 3.1 - Prepare taskcluster for a split test package. ;r=jlal (5f13e2c8eb)
- Bug 1168979 part 2 - Add symbol uploading as a build dependency; r=mrrrgn (d845c41588)
- Bug 1168979 part 3 - Clean up upload_symbol template. r=mrrrgn (517f318f5f)
- Bug 1168979 part 4 - Factor out building dependent tasks as a function; Create a task/post-builds for upload_symbols to live in; r=mrrrgn (a088748e8f)
- Bug 1176642 - Use deferred imports for taskcluster mach commands; r=glandium (a40d778717)
- Bug 1133074 - Use routes.json for Taskcluster routes; r=garndt (7a2d1ea735)
- Bug 1133074 - Use routes.json for mozharness TC uploads; r=jlund (20ea9b663d)
- Bug 1133074 - Make the gecko.v2 routes public; r=jlund,garndt (52d26f51cf)
- Bug 1200688: Support --interactive command line option r=jonasfj (ed5235c9e0)
- Bug 1194767 - use slugid 1.0.6 in ./mach taskcluster-graph command. r=wcosta (4b09e42cf4)
- Bug 1168979 part 5 - Add allowed_build_tasks to distinguish builds that require symbol uploading; r=mrrrgn (51af538d8c)
- Bug 1151124 - Add a simplified version of pymake's clinetoargv to mozbuild and use it. r=gps (ce8751951b)
- Bug 1201372: Remove workspace caches for try builds. r=garndt (33543ca777)
- Bug 1133074 - Add routes.json for taskcluster indexing; r=jonasfj (a979711f13)
- Bug 1195865 - Upload android l10n repacks to Taskcluster; r=jlund (e9201b24ab)
- Bug 1194709 - Add pushid support for mozharness routes; r=jlund (6b7a4d0e26)
- Bug 1195870 - Refactor mozharness TC uploading; r=jlund (48e4ef256f)
- Bug 1212942 - Add pushdate routes; r=garndt,jlund (6eaa6629c9)
- Bug 1214760 - prevent multiple tasks from using the same route in the gecko.v2 namespace; r=jonasfj (362c6fcaef)
- Bug 1171033 - Add taskcluster linux64 test configs (but not scheduled anywhere yet), r=dustin (a60327a9a7)
- Bug 1178388: Fix deferred imports for taskcluster-build command. r=gps (0d9688041e)
- Bug 1213283 - Add option to only print task names in |mach taskcluster-graph|, r=dustin (bef3b77463)
- Bug 1204346 - Add a white-list of caches for try server jobs; r=garndt (fdaa632636)
- Bug 1205574: Fix cache name typo in try white list. r=garndt (bcbe4c0e5e)
- Bug 1213011 - Allow post-build tasks to use build_{name,type,product} variables. r=garndt (69beb15547)
- Bug 1210687 - Remove PushbackIter now it's not used anymore. r=gps (7fbf140db2)
- Bug 1224452 - Move shell_quote to the shellutil module. r=gps (e4925f07c7)
- Bug 1227892 - Add a NO_COMPONENTS_MANIFEST moz.build variable. r=gps (6439a3be7c)
- Bug 1227892 - Emit a specialized object for chrome.manifest entries. r=gps (e0f16cdc58)
- Bug 1224452 - Quote passthru variables. r=gps (c21ff3bc27)
- Bug 1218042 - part 1 - pass an objdir into _build_db_line; r=mshal (385c352caa)
- Bug 1218042 - part 2 - make the CompileDB backend follow the backend protocol; r=mshal (6d5ccff583)
- Bug 1224452 - Use mozbuild.shellutil.split instead of shlex.shlex in mozbuild.compilation.util. r=gps (605ca5df51)
- Bug 1224452 - Add an expand_variables helper function to do simple make-like variable expansion. r=gps (3ea3651452)
- Bug 1224460 - Expand make variable references we get out of gyp. r=gps (df92f4b63c)
- Bug 1224452 - Better handle make variable references from gyp files. r=gps (0106b02b5d)
- Bug 1224452 - Straighten up a couple things in some moz.builds. r=gps (670222ac48)
- Bug 1228463 - Set MOZ_PIXMAN_{CFLAGS,LIBS} directly from PKG_CHECK_MODULES. r=mshal (3c70c986c0)
- Bug 1178266 - Link against libatomic when necessary. r=froydnj (951abf132f)
- Bug 1229293 - Enforce order when setting a HierarchicalStringList, and forbid reassignment. r=gps (c751dbf61d)
- Bug 1229279 - Add a specialized HierarchicalStringList class for ContextDerivedValue types. r=gps (a71776670a)
- Bug 1228444 - Don't silence "no preprocessor directives found" warnings for DIST_FILES. r=gps (aaf47470ab)
- Bug 1228444 - Validate that FINAL_TARGET_FILES source files exist. r=gps (afe3c9e054)
- Bug 1219228 - Generate correct source path of cpu-features.c. r=glandium (842f5ac893)
- Bug 1228444 - Make DIST_FILES a HierarchicalStringList, like FINAL_TARGET_FILES. r=gps (6d7a05be9b)
- Bug 1228444 - Make DIST_FILES a HierarchicalStringList, like FINAL_TARGET_FILES. r=gps (f3131b61ec)
- Bug 1229226 - Remove preprocessing support for RESOURCE_FILES. r=gps (e867dadad0)
- Bug 1229233 - Properly skip the top-level directory in the RecursiveMake backend. r=gps (188856f8d7)
- Bug 1229241 - Reject FINAL_TARGET{,_PP}_FILES along DIST_INSTALL = False. r=gps (9031cbb9b8)
- Bug 1229233 - Skip building XPIDL when there aren't any in the FasterMake backend. r=gps (4b657fcf99)
- Bug 1229241 - Redirect EXTRA{_PP}_COMPONENTS to FINAL_TARGET{,_PP}_FILES.components. r=gps (388754db86)
- Bug 1229241 - Differentiate preprocessed and non-preprocessed JS preffiles. r=gps (c130ef8f59)
- Bug 1229226 - Reject RESOURCE_FILES along DIST_SUBDIR or XPI_NAME. r=gps (ab798a04b1)
- Bug 1229241 - Use FINAL_TARGET{,_PP}_FILES for JS_PREFERENCE{,_PP}_FILES. r=gps (e6bbfed921)
- Bug 1227892 - Add basic tests for IS_COMPONENT/NO_COMPONENTS_MANIFEST. r=gps (5c2f0bf3cb)
- Bug 1229241 - Use FINAL_TARGET{,_PP}_FILES for EXTRA{,_PP}_JS_MODULES. r=gps (8f8267f8ad)
- Bug 1229245 - Don't store the target in FinalTarget{,Preprocessed}Files instances. r=gps (394b7d92c8)
- Bug 1229245 - Use a FinalTargetFiles-like object for TESTING_JS_MODULES. r=gps (101489d644)
- Bug 1229279 - Use mozbuild.context.Path for FINAL_TARGET{_PP}_FILES. r=gps (5aa7034ce6)
- Bug 1229341 - Remove HierarchicalStringListWithFlagsFactory. r=gps (5da80b69bf)
- Bug 1229341 - Remove .source flag on BRANDING_FILES. r=gps (bf23c694b2)
- Bug 1229233 - Use SourcePaths for CONFIGURE_SUBST_FILES and CONFIGURE_DEFINE_FILES. r=gps (1695a94e90)
- bug 1160185 - support GENERATED_FILES in EXPORTS. r=glandium (24b469652f)
- Bug 1229241 - Support merging HierarchicalStringLists. r=gps (bc0ed26557)
- Bug 1220000 - Unconditionally include EXTRA_MDDEPEND_FILES so callers get what they expect. r=glandium (a039177317)
- Bug 1230355 - Remove include_deps. r=mshal (8c3205e672)
- Bug 1222591 - "nsMsgUtils.cpp:52:10: fatal error: 'nsProtocolProxyService.h' file not found". r=gps f=aleth (a1b6ef742c)
- Bug 1230067 - Normalize install target when processing JarManifestParser data in FasterMake backend. r=gps (c875719c52)
- Bug 1191209 - Rebuild XPT files when the list of corresponding IDL files changed. r=gps (7018d28e85)
- Bug 1223593 - Make depsdir optional in xpidl-process.py; r=glandium (9439dd4f6e)
- Bug 1229241 - Allow moz.build special variables to be set, as long as the value is not modified. r=gps (1553c6a9b5)
- sort of quick fix for arcticfox/palemoon (562745788a)
- Bug 1219521 - Add imported python modules in the tree to dependencie of GENERATED_FILES scripts. r=glandium (6a73afa6f4)
- non-android of Bug 1108782 - Part 1: straighten out Java classpaths. r=glandium (c374670020)
- part of Bug 1108782 - Part 2: Explode AAR files at configure time. r=glandium (ba69c238ef)
- Bug 1224460 - Avoid make variable references in TK_CFLAGS, TK_LIBS, MOZ_CAIRO_CFLAGS, MOZ_ICU_CFLAGS and CAIRO_FT_CFLAGS. r=gps (bdbeed2237)
- Typo fix for bug 1224460 breaking Gtk+2 builds. r=me (3a79e9d993)
- Bug 1216901 - Always update backend output list files mtime from the base backend class. r=mshal (33c581c475)
- No bug - Message which upstream pushhead is used in |mach artifact|. r=me (e3cfbd2f50)
- Bug 1230409: Implement dummy HeapOffset members for non-ion builds; r=luke (74158a1271)
- some webapprt and mozcrash stuff (2c303646f7)
- Bug 1228369: Rename CodeOffset::use/used into bind/bound; r=luke (90d1b88697)
- fix duplicated entries also for mac and windows (475bdf9a15)
- Bug 1228340: Remove the js_ prefix in front of IonOptimizationsLevel; r=h4writer (44b79061b3)
- Bug 1229196 - Fix MSVC C4334 "was 64-bit shift intended" warning in js/src/asmjs. r=sunfish (debed181c9)
- Bug 1210642 - s/APP_BUILDID/MOZ_APP_BUILDID/ to use the same variable name across products. r=gps (da9fc7a443)
- Bug 1230060 - Use process_install_manifest's --track option in the FasterMake backend. r=gps (a0ffbc880e)
- Bug 1229233 - Ensure the target directory for copies exists in the FasterMake backend. r=gps (80c92303e6)
- Bug 1214464 - Don't detect leaks during ICU build; r=glandium (c0277a56e5)
- Bug 864843 - Part 3. Add build config of ICU for Android r=glandium (8fb16f3450)
- Bug 1164921 - part 2 - remove now-obsolete --enable-android-libstdcxx; r=glandium (5582d619c0)
- Bug 1229541 - Turn NSPR_CFLAGS, NSS_CFLAGS, MOZ_JPEG_CFLAGS, MOZ_PNG_CFLAGS and MOZ_ZLIB_CFLAGS into AC_SUBST_LISTs. r=mshal (333f8c851d)
- Bug 1142352 - Add a configure test for the gcc version of the host compiler when cross compiling. r=glandium (e5baa698f5)
- Bug 1142420 - Require that the same compiler version be used for C and C++ (at the very least, so that our version checks are valid for both). r=glandium (442ff81898)
- Bug 1228068 - Always set MOZ_USING_COMPILER_WRAPPER when a compiler wrapper is involved. r=gps on a CLOSED TREE (5a7c5aa53e)
- fix more dupes (b67b95d705)
2023-04-20 11:43:27 +08:00
..

slugid.py - Compressed UUIDs for python
=======================================

.. image:: https://tools.taskcluster.net/lib/assets/taskcluster-120.png

|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`_).

Slugs are url-safe base64 encoded v4 uuids, stripped of base64 ``=`` padding.

There are two methods for generating slugs - ``slugid.v4()`` and
``slugid.nice()``.

- The ``slugid.v4()`` method returns a slug from a randomly generated v4 uuid.
- The ``slugid.nice()`` method returns a v4 slug which conforms to a set of
  "nice" properties. At the moment the only "nice" property is that the slug
  starts with ``[A-Za-f]``, which in turn implies that the first (most
  significant) bit of its associated uuid is set to 0.

The purpose of the ``slugid.nice()`` method is to support having slugids which
can be used in more contexts safely. Regular slugids can safely be used in
urls, and for example in AMQP routing keys. However, slugs beginning with ``-``
may cause problems when used as command line parameters.

In contrast, slugids generated by the ``slugid.nice()`` method can safely be
used as command line parameters. This comes at a cost to entropy (121 bits vs
122 bits for regular v4 slugs).

Slug consumers should consider carefully which of these two slug generation
methods to call. Is it more important to have maximum entropy, or to have
slugids that do not need special treatment when used as command line
parameters? This is especially important if you are providing a service which
supplies slugs to unexpecting tool developers downstream, who may not realise
the risks of using your regular v4 slugs as command line parameters, especially
since this would arise only as an intermittent issue (one time in 64).

Generated slugs take the form ``[A-Za-z0-9_-]{22}``, or more precisely:

- ``slugid.v4()`` slugs conform to
  ``[A-Za-z0-9_-]{8}[Q-T][A-Za-z0-9_-][CGKOSWaeimquy26-][A-Za-z0-9_-]{10}[AQgw]``

- ``slugid.nice()`` slugs conform to
  ``[A-Za-f][A-Za-z0-9_-]{7}[Q-T][A-Za-z0-9_-][CGKOSWaeimquy26-][A-Za-z0-9_-]{10}[AQgw]``

RFC 4122 defines the setting of 6 bits of the v4 UUID which implies v4 slugs
provide 128 - 6 = 122 bits entropy. Due to the (un)setting of the first bit
of "nice" slugs, nice slugs provide therefore 121 bits entropy.


Usage
-----

.. code-block:: python

    import slugid

    # Generate "nice" URL-safe base64 encoded UUID version 4 (random)
    slug = slugid.nice()  # a8_YezW8T7e1jLxG7evy-A

    # Alternative, if slugs will not be used as command line parameters
    slug = slugid.v4()    # -9OpXaCORAaFh4sJRk7PUA

    # Get python uuid.UUID object
    uuid = slugid.decode(slug)

    # Compress to slug again
    assert(slug == slugid.encode(uuid))


RNG Characteristics
-------------------
UUID generation is performed by the built-in python `uuid library`_ which does
not document its randomness, but falls back to system uuid-generation libraries
where available, then urandom, then random. Therefore generated slugids match
these rng characteristics.

License
-------
The ``slugid`` library is released on the MPL 2.0 license, see the ``LICENSE``
for complete license.

Testing
-------

.. code-block:: bash

    pip install -r requirements.txt
    tox

Publishing
----------
To republish this library to pypi.python.org, update the version number in
``slugid/__init__.py``, commit it, push to github, and then run:

.. code-block:: bash

    # delete stale versions
    rm -rf dist

    # build source package
    python setup.py sdist

    # publish it
    twine upload -s dist/*


.. _RFC 4648 sec. 5: http://tools.ietf.org/html/rfc4648#section-5
.. _uuid library: https://docs.python.org/2/library/uuid.html

.. |Build Status| image:: https://travis-ci.org/taskcluster/slugid.py.svg?branch=master
   :target: http://travis-ci.org/taskcluster/slugid.py
.. |Coverage Status| image:: https://coveralls.io/repos/taskcluster/slugid.py/badge.svg?branch=master&service=github
   :target: https://coveralls.io/github/taskcluster/slugid.py?branch=master
.. |License| image:: https://img.shields.io/badge/license-MPL%202.0-orange.svg
   :target: https://github.com/taskcluster/slugid.py/blob/master/LICENSE
.. |pypi Version| image:: https://img.shields.io/pypi/v/slugid.svg
   :target: https://pypi.python.org/pypi/slugid
.. |Downloads| image:: https://img.shields.io/pypi/dm/slugid.svg
   :target: https://pypi.python.org/pypi/slugid