oslo.serialization-2.24.0/0000775000175100017510000000000013236475264015467 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/releasenotes/0000775000175100017510000000000013236475264020160 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/releasenotes/source/0000775000175100017510000000000013236475264021460 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/releasenotes/source/pike.rst0000666000175100017510000000021713236474736023147 0ustar zuulzuul00000000000000=================================== Pike Series Release Notes =================================== .. release-notes:: :branch: stable/pike oslo.serialization-2.24.0/releasenotes/source/_templates/0000775000175100017510000000000013236475264023615 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/releasenotes/source/_templates/.placeholder0000666000175100017510000000000013236474736026073 0ustar zuulzuul00000000000000oslo.serialization-2.24.0/releasenotes/source/unreleased.rst0000666000175100017510000000016013236474736024343 0ustar zuulzuul00000000000000============================== Current Series Release Notes ============================== .. release-notes:: oslo.serialization-2.24.0/releasenotes/source/index.rst0000666000175100017510000000024613236474765023332 0ustar zuulzuul00000000000000================================== oslo.serialization Release Notes ================================== .. toctree:: :maxdepth: 1 unreleased pike ocata oslo.serialization-2.24.0/releasenotes/source/conf.py0000666000175100017510000002163013236474736022766 0ustar zuulzuul00000000000000# -*- coding: utf-8 -*- # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. # See the License for the specific language governing permissions and # limitations under the License. # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'openstackdocstheme', 'reno.sphinxext', ] # openstackdocstheme options repository_name = 'openstack/oslo.serialization' bug_project = 'oslo.serialization' bug_tag = '' # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. # source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'oslo.serialization Release Notes' copyright = u'2016, oslo.serialization Developers' # Release notes do not need a version in the title, they span # multiple versions. # The full version, including alpha/beta/rc tags. release = '' # The short X.Y version. version = '' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: # today = '' # Else, today_fmt is used as the format for a strftime call. # today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = [] # The reST default role (used for this markup: `text`) to use for all # documents. # default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. # add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). # add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. # show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. # modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. # keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'openstackdocs' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. # html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". # html_title = None # A shorter title for the navigation bar. Default is the same as html_title. # html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. # html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. # html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. html_last_updated_fmt = '%Y-%m-%d %H:%M' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. # html_use_smartypants = True # Custom sidebar templates, maps document names to template names. # html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. # html_additional_pages = {} # If false, no module index is generated. # html_domain_indices = True # If false, no index is generated. # html_use_index = True # If true, the index is split into individual pages for each letter. # html_split_index = False # If true, links to the reST sources are added to the pages. # html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. # html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. # html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. # html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). # html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'oslo.serializationReleaseNotesDoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. # 'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ ('index', 'oslo.serializationReleaseNotes.tex', u'oslo.serialization Release Notes Documentation', u'oslo.serialization Developers', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. # latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. # latex_use_parts = False # If true, show page references after internal links. # latex_show_pagerefs = False # If true, show URL addresses after external links. # latex_show_urls = False # Documents to append as an appendix to all manuals. # latex_appendices = [] # If false, no module index is generated. # latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'oslo.serializationReleaseNotes', u'oslo.serialization Release Notes Documentation', [u'oslo.serialization Developers'], 1) ] # If true, show URL addresses after external links. # man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'oslo.serializationReleaseNotes', u'oslo.serialization Release Notes Documentation', u'oslo.serialization Developers', 'oslo.serializationReleaseNotes', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. # texinfo_appendices = [] # If false, no module index is generated. # texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. # texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. # texinfo_no_detailmenu = False # -- Options for Internationalization output ------------------------------ locale_dirs = ['locale/'] oslo.serialization-2.24.0/releasenotes/source/ocata.rst0000666000175100017510000000023013236474736023301 0ustar zuulzuul00000000000000=================================== Ocata Series Release Notes =================================== .. release-notes:: :branch: origin/stable/ocata oslo.serialization-2.24.0/releasenotes/source/_static/0000775000175100017510000000000013236475264023106 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/releasenotes/source/_static/.placeholder0000666000175100017510000000000013236474736025364 0ustar zuulzuul00000000000000oslo.serialization-2.24.0/releasenotes/notes/0000775000175100017510000000000013236475264021310 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/releasenotes/notes/add-reno-996dd44974d53238.yaml0000666000175100017510000000007213236474736025713 0ustar zuulzuul00000000000000--- other: - Introduce reno for deployer release notes. oslo.serialization-2.24.0/ChangeLog0000664000175100017510000002217113236475263017243 0ustar zuulzuul00000000000000CHANGES ======= 2.24.0 ------ * msgpack-python has been renamed to msgpack * Update .gitreview for stable/queens 2.23.0 ------ * Updated from global requirements * Add bandit to pep8 job 2.22.0 ------ * Remove -U from pip install * Avoid tox\_install.sh for constraints support * Remove setting of version/release from releasenotes * Updated from global requirements * Updated from global requirements 2.21.2 ------ * When serializing an exception return its 'repr' 2.21.1 ------ * jsonutils.to\_primitive(): add fallback parameter 2.21.0 ------ * Updated from global requirements * warn developers when can't convert value into primitive * Updated from global requirements * Updated from global requirements * Update reno for stable/pike * Updated from global requirements 2.20.0 ------ * Revert "Explicitly raise ValueError in to\_primitive" * Update URLs in documents according to document migration * rearrange existing documentation to fit the new standard layout * switch from oslosphinx to openstackdocstheme 2.19.1 ------ 2.19.0 ------ * Updated from global requirements * Don't iterate through addresses in netaddr.IPNetwork * Updated from global requirements * Updated from global requirements * Explicitly raise ValueError in to\_primitive * Updated from global requirements * Updated from global requirements 2.18.0 ------ * Use Sphinx 1.5 warning-is-error 2.17.0 ------ * Updated from global requirements * [Fix gate]Update test requirement * Updated from global requirements * Update reno for stable/ocata * Remove references to Python 3.4 2.16.0 ------ * Prefer raising the python2.x type error for b64 decode errors * Add Constraints support * Don't raise TypeError for invalid b64 * Replace six.iteritems() with .items() * Replaces uuid.uuid4 with uuidutils.generate\_uuid() * Show team and repo badges on README 2.15.0 ------ * Updated from global requirements * Updated from global requirements * Add reno for release notes management * Updated from global requirements 2.14.0 ------ * Add a title to the API Documentation page * Updated from global requirements * modify the home-page info with the developer documentation 2.13.0 ------ * Drop H803 in flake8 ignore list * Fix serialization of binary strings in Python3 2.12.0 ------ * Updated from global requirements * Fix parameters of assertEqual are misplaced * Add Python 3.5 classifier and venv 2.11.0 ------ * Updated from global requirements * Updated from global requirements * Use {} instead of dict() 2.10.0 ------ * Updated from global requirements 2.9.0 ----- 2.8.0 ----- * Replace TypeError by ValueError in msgpackutils * Support serializing ipaddress objs with jsonutils * Updated from global requirements * Updated from global requirements * Updated from global requirements 2.7.0 ----- * Trivial: ignore openstack/common in flake8 exclude list 2.6.0 ----- * [Trivial] Remove executable privilege of doc/source/conf.py 2.5.0 ----- * Drop babel as requirement since its not used * Updated from global requirements * Unified and simplified API for all serializers * Make msgpack registries copyable (and add \_\_contains\_\_) * msgpack: fix datetime serialization 2.4.0 ----- * Updated from global requirements 2.3.0 ----- * Updated from global requirements * Updated from global requirements * Updated from global requirements * Remove fallback to simplejson in jsonutils 2.2.0 ----- * Remove iso8601 dependency * Updated from global requirements * Updated from global requirements * Trival: Remove 'MANIFEST.in' 2.1.0 ----- * msgpackutils: drop Python 2.6 support 2.0.0 ----- * Updated from global requirements * Updated from global requirements * Remove python 2.6 classifier * Fix bug track URL * Remove python 2.6 and cleanup tox.ini * Updated from global requirements 1.11.0 ------ * Updated from global requirements * Use versionadded and versionchanged in doc * Fix coverage configuration and execution 1.10.0 ------ * Add utilities for base64 * Also check for the existence of \`items\` in to\_primitive() * Move 'history' -> release notes section * Add jsonutils.dump\_as\_bytes() function for py3 * Change ignore-errors to ignore\_errors * Updated from global requirements 1.9.0 ----- * Updated from global requirements * Updated from global requirements * Updated from global requirements * Updated from global requirements * Updated from global requirements 1.8.0 ----- * Updated from global requirements * Updated from global requirements * Updated from global requirements * Updated from global requirements * Updated from global requirements * Drop stale test - test\_jsonutils 1.7.0 ----- * Stop using deprecated oslo\_utils.timeutils.strtime * Add tox target to find missing requirements * Remove oslo namespace package * Do not use oslo namespace for oslo.i18n lib * Updated from global requirements * Updated from global requirements * Switch badges from 'pypip.in' to 'shields.io' 1.6.0 ----- * Revert "jsonutils: replace strtime() usage with isoformat()" * jsonutils: encode dict keys * jsonutils: simplify simple value handling * jsonutils: replace strtime() usage with isoformat() * Advertise support for Python3.4 / Remove support for Python 3.3 * Do not sync run\_cross\_tests.sh * Updated from global requirements * Remove run\_cross\_tests.sh * Fixes wrong folder for listing tests 1.5.0 ----- * Expose base msgpack exceptions so users don't need to import * Uncap library requirements for liberty * More docstring cleanups/tweaks * Add docstring(s) to handler registry(s) * Add pypi download + version badges * Cleanup README.rst and setup.cfg * Make the msgpackutils handlers more extendable * Updated from global requirements 1.4.0 ----- * Updated from global requirements 1.3.0 ----- * add dependency warning to requirements.txt * Correctly load and dump items with datetime.date(s) * Avoid using strtime for serializing datetimes * jsonutils: add set() tests and simplify recursive code * jsonutils: support UUID encoding * Use default in dumps() * Updated from global requirements * Update Oslo imports to remove namespace package * Add a messagepack utils helper module * Bump to hacking 0.10 * Updated from global requirements * fix bug tracker link in README.rst 1.2.0 ----- * Move files out of the namespace package * Activate pep8 check that \_ is imported * Updated from global requirements * Workflow documentation is now in infra-manual 1.1.0 ----- * Add pbr to installation requirements * Updated from global requirements * Fix pep8, docs, requirements issues in jsonutils and tests * Remove extraneous vim editor configuration comments * Support building wheels (PEP-427) * Fix coverage testing * Updated from global requirements * Support 'built-in' datetime module 1.0.0 ----- * Updated from global requirements * Add history/changelog to docs 0.2.0 ----- * Check for namedtuple\_as\_object support before using it * Work toward Python 3.4 support and testing 0.1.0 ----- * Updated from global requirements * Clean up docs before first release * Updated from global requirements * Added JSONEncoder and JSONDecoder * Add some basic docstring(s) * Fix docs build to run properly * Use oslo libraries - i18n and utils * Specify namedtuple\_as\_object=False when using simplejson * Get unit tests passing * exported from oslo-incubator by graduate.sh * Added missing jsonutils.dump() function * pep8: fixed multiple violations * Add kwargs to jsonutils.load(s) functions * Enforce unicode json output for jsonutils.load[s]() * jsonutils.load() accepts file pointer, not string * On Python <= 2.6, use simplejson if available * Use oslotest instead of common test module * Python3: enable test\_jsonutils.py * Use six.moves.xmlrpc\_client instead of xmlrpclib * Translation Message improvements * Python3 support for xmlrpclib * Use six.iteritems to make dict work on Python2/3 * Remove vim header * Ensure that Message objects will be sent via RPC in unicode format * jsonutils: make types py3 compatible * jsonutils: do not require xmlrpclib * Make dependency on netaddr optional * Bump hacking to 0.7.0 * Replace using tests.utils with openstack.common.test * Enable H302 hacking check * Add netaddr.IPAddress support to to\_primitive() * python3: python3 binary/text data compatbility * Convert unicode for python3 portability * Optimise to\_primitive common cases * Update to use flake8 * Fix Copyright Headers - Rename LLC to Foundation * Don't LOG.error on max\_depth (by default) * to\_primitive imposes what seems to be an arbitary data structure depth of 3, but there is at least on case in Nova (Security group Rules) which requires a depth beyond this * Allow to\_primitive to ignore datetimes * Replace direct use of testtools BaseTestCase * Use testtools as test base class * Fixes import order errors * Make project pyflakes clean * Add missing convert\_instances arg * Track to\_primitive() depth after iteritems() * Update iteritems test case to actually test iteritems * Use strtime() in to\_primitive() for datetime objs * Add 'filedecoder' method to the jsonutils wrapper module * Make jsonutils.dumps more general * Handle xmlrpclib.DateTime types when serializing to JSON * Revert "Add a load function wrapper to jsonutils" * Add a load function wrapper to jsonutils * Create openstack.common.jsonutils oslo.serialization-2.24.0/setup.cfg0000666000175100017510000000237213236475264017316 0ustar zuulzuul00000000000000[metadata] name = oslo.serialization summary = Oslo Serialization library description-file = README.rst author = OpenStack author-email = openstack-dev@lists.openstack.org home-page = http://docs.openstack.org/developer/oslo.serialization/ classifier = Environment :: OpenStack Intended Audience :: Information Technology Intended Audience :: System Administrators License :: OSI Approved :: Apache Software License Operating System :: POSIX :: Linux Programming Language :: Python Programming Language :: Python :: 2 Programming Language :: Python :: 2.7 Programming Language :: Python :: 3 Programming Language :: Python :: 3.5 [files] packages = oslo_serialization [build_sphinx] all-files = 1 warning-is-error = 1 source-dir = doc/source build-dir = doc/build [upload_sphinx] upload-dir = doc/build/html [compile_catalog] directory = oslo.serialization/locale domain = oslo.serialization [update_catalog] domain = oslo.serialization output_dir = oslo.serialization/locale input_file = oslo.serialization/locale/oslo.serialization.pot [extract_messages] keywords = _ gettext ngettext l_ lazy_gettext mapping_file = babel.cfg output_file = oslo.serialization/locale/oslo.serialization.pot [wheel] universal = 1 [egg_info] tag_build = tag_date = 0 oslo.serialization-2.24.0/oslo.serialization.egg-info/0000775000175100017510000000000013236475264023011 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/oslo.serialization.egg-info/dependency_links.txt0000664000175100017510000000000113236475263027056 0ustar zuulzuul00000000000000 oslo.serialization-2.24.0/oslo.serialization.egg-info/pbr.json0000664000175100017510000000005613236475263024467 0ustar zuulzuul00000000000000{"git_version": "d4ae9c0", "is_release": true}oslo.serialization-2.24.0/oslo.serialization.egg-info/PKG-INFO0000664000175100017510000000400413236475263024103 0ustar zuulzuul00000000000000Metadata-Version: 1.1 Name: oslo.serialization Version: 2.24.0 Summary: Oslo Serialization library Home-page: http://docs.openstack.org/developer/oslo.serialization/ Author: OpenStack Author-email: openstack-dev@lists.openstack.org License: UNKNOWN Description-Content-Type: UNKNOWN Description: ======================== Team and repository tags ======================== .. image:: http://governance.openstack.org/badges/oslo.serialization.svg :target: http://governance.openstack.org/reference/tags/index.html .. Change things from this point on ==================== oslo.serialization ==================== .. image:: https://img.shields.io/pypi/v/oslo.serialization.svg :target: https://pypi.python.org/pypi/oslo.serialization/ :alt: Latest Version .. image:: https://img.shields.io/pypi/dm/oslo.serialization.svg :target: https://pypi.python.org/pypi/oslo.serialization/ :alt: Downloads The oslo.serialization library provides support for representing objects in transmittable and storable formats, such as Base64, JSON and MessagePack. * Free software: Apache license * Documentation: https://docs.openstack.org/oslo.serialization/latest/ * Source: https://git.openstack.org/cgit/openstack/oslo.serialization * Bugs: https://docs.openstack.org/oslo.serialization/latest/ Platform: UNKNOWN Classifier: Environment :: OpenStack Classifier: Intended Audience :: Information Technology Classifier: Intended Audience :: System Administrators Classifier: License :: OSI Approved :: Apache Software License Classifier: Operating System :: POSIX :: Linux Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.5 oslo.serialization-2.24.0/oslo.serialization.egg-info/SOURCES.txt0000664000175100017510000000261413236475264024700 0ustar zuulzuul00000000000000.coveragerc .mailmap .testr.conf AUTHORS CONTRIBUTING.rst ChangeLog HACKING.rst LICENSE README.rst babel.cfg requirements.txt setup.cfg setup.py test-requirements.txt tox.ini doc/source/conf.py doc/source/index.rst doc/source/contributor/index.rst doc/source/install/index.rst doc/source/reference/index.rst doc/source/user/history.rst doc/source/user/index.rst oslo.serialization.egg-info/PKG-INFO oslo.serialization.egg-info/SOURCES.txt oslo.serialization.egg-info/dependency_links.txt oslo.serialization.egg-info/not-zip-safe oslo.serialization.egg-info/pbr.json oslo.serialization.egg-info/requires.txt oslo.serialization.egg-info/top_level.txt oslo_serialization/__init__.py oslo_serialization/base64.py oslo_serialization/jsonutils.py oslo_serialization/msgpackutils.py oslo_serialization/serializer/__init__.py oslo_serialization/serializer/base_serializer.py oslo_serialization/serializer/json_serializer.py oslo_serialization/serializer/msgpack_serializer.py oslo_serialization/tests/__init__.py oslo_serialization/tests/test_base64.py oslo_serialization/tests/test_jsonutils.py oslo_serialization/tests/test_msgpackutils.py releasenotes/notes/add-reno-996dd44974d53238.yaml releasenotes/source/conf.py releasenotes/source/index.rst releasenotes/source/ocata.rst releasenotes/source/pike.rst releasenotes/source/unreleased.rst releasenotes/source/_static/.placeholder releasenotes/source/_templates/.placeholderoslo.serialization-2.24.0/oslo.serialization.egg-info/top_level.txt0000664000175100017510000000002313236475263025535 0ustar zuulzuul00000000000000oslo_serialization oslo.serialization-2.24.0/oslo.serialization.egg-info/requires.txt0000664000175100017510000000011613236475263025406 0ustar zuulzuul00000000000000pbr!=2.1.0,>=2.0.0 six>=1.10.0 msgpack>=0.4.0 oslo.utils>=3.33.0 pytz>=2013.6 oslo.serialization-2.24.0/oslo.serialization.egg-info/not-zip-safe0000664000175100017510000000000113236475222025231 0ustar zuulzuul00000000000000 oslo.serialization-2.24.0/doc/0000775000175100017510000000000013236475264016234 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/doc/source/0000775000175100017510000000000013236475264017534 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/doc/source/index.rst0000666000175100017510000000101213236474736021374 0ustar zuulzuul00000000000000============================================== Welcome to oslo.serialization's documentation! ============================================== The `oslo`_ serialization library provides support for representing objects in transmittable and storable formats, such as JSON and MessagePack. .. toctree:: :maxdepth: 1 install/index user/index contributor/index reference/index .. rubric:: Indices and tables * :ref:`genindex` * :ref:`modindex` * :ref:`search` .. _oslo: https://wiki.openstack.org/wiki/Oslo oslo.serialization-2.24.0/doc/source/reference/0000775000175100017510000000000013236475264021472 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/doc/source/reference/index.rst0000666000175100017510000000043313236474736023340 0ustar zuulzuul00000000000000============= API Reference ============= base64 ====== .. automodule:: oslo_serialization.base64 :members: jsonutils ========= .. automodule:: oslo_serialization.jsonutils :members: msgpackutils ============ .. automodule:: oslo_serialization.msgpackutils :members: oslo.serialization-2.24.0/doc/source/user/0000775000175100017510000000000013236475264020512 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/doc/source/user/index.rst0000666000175100017510000000040613236474736022360 0ustar zuulzuul00000000000000======================== Using oslo.serialization ======================== .. toctree:: :maxdepth: 2 .. Add more contents here .. history contains a lot of sections, toctree with maxdepth 1 is used. .. toctree:: :maxdepth: 1 Release Notes oslo.serialization-2.24.0/doc/source/user/history.rst0000666000175100017510000000004013236474736022744 0ustar zuulzuul00000000000000.. include:: ../../../ChangeLog oslo.serialization-2.24.0/doc/source/conf.py0000666000175100017510000000516013236474736021042 0ustar zuulzuul00000000000000# -*- coding: utf-8 -*- # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. # See the License for the specific language governing permissions and # limitations under the License. import os import sys sys.path.insert(0, os.path.abspath('../..')) # -- General configuration ---------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ 'sphinx.ext.autodoc', #'sphinx.ext.intersphinx', 'openstackdocstheme' ] # openstackdocstheme options repository_name = 'openstack/oslo.serialization' bug_project = 'oslo.serialization' bug_tag = '' # autodoc generation is a bit aggressive and a nuisance when doing heavy # text edit cycles. # execute "export SPHINX_DEBUG=1" in your terminal to disable # The suffix of source filenames. source_suffix = '.rst' # The master toctree document. master_doc = 'index' # General information about the project. project = u'oslo.serialization' copyright = u'2014, OpenStack Foundation' # If true, '()' will be appended to :func: etc. cross-reference text. add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). add_module_names = True # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # -- Options for HTML output -------------------------------------------------- # The theme to use for HTML and HTML Help pages. Major themes that come with # Sphinx are currently 'default' and 'sphinxdoc'. # html_theme_path = ["."] # html_theme = '_theme' # html_static_path = ['static'] html_theme = 'openstackdocs' html_last_updated_fmt = '%Y-%m-%d %H:%M' # Output file base name for HTML help builder. htmlhelp_basename = '%sdoc' % project # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass # [howto/manual]). latex_documents = [ ('index', '%s.tex' % project, u'%s Documentation' % project, u'OpenStack Foundation', 'manual'), ] # Example configuration for intersphinx: refer to the Python standard library. #intersphinx_mapping = {'http://docs.python.org/': None} oslo.serialization-2.24.0/doc/source/install/0000775000175100017510000000000013236475264021202 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/doc/source/install/index.rst0000666000175100017510000000033613236474736023052 0ustar zuulzuul00000000000000============ Installation ============ At the command line:: $ pip install oslo.serialization Or, if you have virtualenvwrapper installed:: $ mkvirtualenv oslo.serialization $ pip install oslo.serializationoslo.serialization-2.24.0/doc/source/contributor/0000775000175100017510000000000013236475264022106 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/doc/source/contributor/index.rst0000666000175100017510000000012413236474736023751 0ustar zuulzuul00000000000000============== Contributing ============== .. include:: ../../../CONTRIBUTING.rst oslo.serialization-2.24.0/requirements.txt0000666000175100017510000000117313236474736020762 0ustar zuulzuul00000000000000# The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. # NOTE(harlowja): Because oslo.serialization is used by the client libraries, # we do not want to add a lot of dependencies to it. If you find that # adding a new feature to oslo.serialization means adding a new dependency, # that is a likely indicator that the feature belongs somewhere else. pbr!=2.1.0,>=2.0.0 # Apache-2.0 six>=1.10.0 # MIT msgpack>=0.4.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 pytz>=2013.6 # MIT oslo.serialization-2.24.0/HACKING.rst0000666000175100017510000000025513236474736017274 0ustar zuulzuul00000000000000oslo.serialization Style Commandments ====================================================== Read the OpenStack Style Commandments https://docs.openstack.org/hacking/latestoslo.serialization-2.24.0/PKG-INFO0000664000175100017510000000400413236475264016562 0ustar zuulzuul00000000000000Metadata-Version: 1.1 Name: oslo.serialization Version: 2.24.0 Summary: Oslo Serialization library Home-page: http://docs.openstack.org/developer/oslo.serialization/ Author: OpenStack Author-email: openstack-dev@lists.openstack.org License: UNKNOWN Description-Content-Type: UNKNOWN Description: ======================== Team and repository tags ======================== .. image:: http://governance.openstack.org/badges/oslo.serialization.svg :target: http://governance.openstack.org/reference/tags/index.html .. Change things from this point on ==================== oslo.serialization ==================== .. image:: https://img.shields.io/pypi/v/oslo.serialization.svg :target: https://pypi.python.org/pypi/oslo.serialization/ :alt: Latest Version .. image:: https://img.shields.io/pypi/dm/oslo.serialization.svg :target: https://pypi.python.org/pypi/oslo.serialization/ :alt: Downloads The oslo.serialization library provides support for representing objects in transmittable and storable formats, such as Base64, JSON and MessagePack. * Free software: Apache license * Documentation: https://docs.openstack.org/oslo.serialization/latest/ * Source: https://git.openstack.org/cgit/openstack/oslo.serialization * Bugs: https://docs.openstack.org/oslo.serialization/latest/ Platform: UNKNOWN Classifier: Environment :: OpenStack Classifier: Intended Audience :: Information Technology Classifier: Intended Audience :: System Administrators Classifier: License :: OSI Approved :: Apache Software License Classifier: Operating System :: POSIX :: Linux Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.5 oslo.serialization-2.24.0/AUTHORS0000664000175100017510000000504613236475263016543 0ustar zuulzuul00000000000000Akihiro Motoki Alexander Gorodnev Andreas Jaeger Andreas Jaeger Ann Kamyshnikova Ben Nemec Brant Knudson Chang Bo Guo ChangBo Guo(gcb) Christian Berendt Chuck Short Cyril Roelandt Dan Prince Dan Smith Davanum Srinivas (dims) Davanum Srinivas Davanum Srinivas Dirk Mueller Doug Hellmann Edan David Eric Brown Flavio Percoco Gary Kotton Gevorg Davoian He Jie Xu Ian Cordasco Ihar Hrachyshka James Carey James Page Jay Pipes Jeremy Stanley Jim Baker Joe Gordon Joe Gordon Johannes Erdfelt John L. Villalovos Joshua Harlow Joshua Harlow Joshua Harlow Julien Danjou Luis A. Garcia Luong Anh Tuan Matt Riedemann Mehdi Abaakouk Mike Heald Monty Taylor Nataliia Uvarova OpenStack Release Bot Phil Day Ronald Bradford Russell Bryant Sirushti Murugesan Stanislaw Pitucha Stephen Finucane Steve Martinelli Thomas Goirand Tim Daly Jr Tony Breeds Victor Sergeyev Victor Stinner YAMAMOTO Takashi ZhiQiang Fan Zhongyue Luo Zhongyue Luo Zuul avnish gecong1973 ricolin xianming.mao yanheven oslo.serialization-2.24.0/.testr.conf0000666000175100017510000000047613236474736017571 0ustar zuulzuul00000000000000[DEFAULT] test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \ ${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION test_id_option=--load-list $IDFILE test_list_option=--listoslo.serialization-2.24.0/tox.ini0000666000175100017510000000273413236474736017015 0ustar zuulzuul00000000000000[tox] minversion = 2.0 envlist = py35,py27,pypy,pep8 [testenv] install_command = pip install {opts} {packages} deps = -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} -r{toxinidir}/test-requirements.txt -r{toxinidir}/requirements.txt commands = python setup.py testr --slowest --testr-args='{posargs}' [testenv:pep8] deps = -r{toxinidir}/test-requirements.txt commands = flake8 # Run security linter bandit -r oslo_serialization tests -n5 [testenv:venv] commands = {posargs} [testenv:docs] commands = python setup.py build_sphinx [testenv:cover] commands = python setup.py test --coverage --coverage-package-name=oslo_serialization --testr-args='{posargs}' [flake8] # E123, E125 skipped as they are invalid PEP-8. show-source = True ignore = E123,E125 exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build [testenv:pip-missing-reqs] # do not install test-requirements as that will pollute the virtualenv for # determining missing packages # this also means that pip-missing-reqs must be installed separately, outside # of the requirements.txt files deps = pip_missing_reqs commands = pip-missing-reqs -d --ignore-module=oslo_serialization* --ignore-module=pkg_resources --ignore-file=oslo_serialization/test.py --ignore-file=oslo_serialization/tests/* oslo_serialization [testenv:releasenotes] commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html oslo.serialization-2.24.0/CONTRIBUTING.rst0000666000175100017510000000103113236474736020130 0ustar zuulzuul00000000000000If you would like to contribute to the development of OpenStack, you must follow the steps in this page: http://docs.openstack.org/infra/manual/developers.html Once those steps have been completed, changes to OpenStack should be submitted for review via the Gerrit tool, following the workflow documented at: http://docs.openstack.org/infra/manual/developers.html#development-workflow Pull requests submitted through GitHub will be ignored. Bugs should be filed on Launchpad, not GitHub: https://bugs.launchpad.net/oslo.serialization oslo.serialization-2.24.0/.mailmap0000666000175100017510000000013013236474736017107 0ustar zuulzuul00000000000000# Format is: # # oslo.serialization-2.24.0/setup.py0000666000175100017510000000200613236474736017204 0ustar zuulzuul00000000000000# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. # See the License for the specific language governing permissions and # limitations under the License. # THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT import setuptools # In python < 2.7.4, a lazy loading of package `pbr` will break # setuptools if some other modules registered functions in `atexit`. # solution from: http://bugs.python.org/issue15881#msg170215 try: import multiprocessing # noqa except ImportError: pass setuptools.setup( setup_requires=['pbr>=2.0.0'], pbr=True) oslo.serialization-2.24.0/README.rst0000666000175100017510000000175713236474736017175 0ustar zuulzuul00000000000000======================== Team and repository tags ======================== .. image:: http://governance.openstack.org/badges/oslo.serialization.svg :target: http://governance.openstack.org/reference/tags/index.html .. Change things from this point on ==================== oslo.serialization ==================== .. image:: https://img.shields.io/pypi/v/oslo.serialization.svg :target: https://pypi.python.org/pypi/oslo.serialization/ :alt: Latest Version .. image:: https://img.shields.io/pypi/dm/oslo.serialization.svg :target: https://pypi.python.org/pypi/oslo.serialization/ :alt: Downloads The oslo.serialization library provides support for representing objects in transmittable and storable formats, such as Base64, JSON and MessagePack. * Free software: Apache license * Documentation: https://docs.openstack.org/oslo.serialization/latest/ * Source: https://git.openstack.org/cgit/openstack/oslo.serialization * Bugs: https://docs.openstack.org/oslo.serialization/latest/ oslo.serialization-2.24.0/.coveragerc0000666000175100017510000000017713236474736017622 0ustar zuulzuul00000000000000[run] branch = True source = oslo_serialization omit = oslo_serialization/tests/* [report] ignore_errors = True precision = 2 oslo.serialization-2.24.0/LICENSE0000666000175100017510000002363613236474736016513 0ustar zuulzuul00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. oslo.serialization-2.24.0/test-requirements.txt0000666000175100017510000000115613236474765021742 0ustar zuulzuul00000000000000# The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 ipaddress>=1.0.16;python_version<'3.3' # PSF mock>=2.0.0 # BSD netaddr>=0.7.18 # BSD # this is required for the docs build jobs sphinx>=1.6.2 # BSD openstackdocstheme>=1.17.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 reno>=2.5.0 # Apache-2.0 # Bandit security code scanner bandit>=1.1.0 # Apache-2.0 oslo.serialization-2.24.0/babel.cfg0000666000175100017510000000002013236474736017212 0ustar zuulzuul00000000000000[python: **.py] oslo.serialization-2.24.0/oslo_serialization/0000775000175100017510000000000013236475264021400 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/oslo_serialization/__init__.py0000666000175100017510000000000013236474736023504 0ustar zuulzuul00000000000000oslo.serialization-2.24.0/oslo_serialization/jsonutils.py0000666000175100017510000002475713236474736024030 0ustar zuulzuul00000000000000# Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # Copyright 2011 Justin Santa Barbara # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. ''' JSON related utilities. This module provides a few things: #. A handy function for getting an object down to something that can be JSON serialized. See :func:`.to_primitive`. #. Wrappers around :func:`.loads` and :func:`.dumps`. The :func:`.dumps` wrapper will automatically use :func:`.to_primitive` for you if needed. #. This sets up ``anyjson`` to use the :func:`.loads` and :func:`.dumps` wrappers if ``anyjson`` is available. ''' import codecs import datetime import functools import inspect import itertools import json import uuid import warnings from oslo_utils import encodeutils from oslo_utils import importutils from oslo_utils import timeutils import six import six.moves.xmlrpc_client as xmlrpclib ipaddress = importutils.try_import("ipaddress") netaddr = importutils.try_import("netaddr") _nasty_type_tests = [inspect.ismodule, inspect.isclass, inspect.ismethod, inspect.isfunction, inspect.isgeneratorfunction, inspect.isgenerator, inspect.istraceback, inspect.isframe, inspect.iscode, inspect.isbuiltin, inspect.isroutine, inspect.isabstract] _simple_types = ((six.text_type,) + six.integer_types + (type(None), bool, float)) def to_primitive(value, convert_instances=False, convert_datetime=True, level=0, max_depth=3, encoding='utf-8', fallback=None): """Convert a complex object into primitives. Handy for JSON serialization. We can optionally handle instances, but since this is a recursive function, we could have cyclical data structures. To handle cyclical data structures we could track the actual objects visited in a set, but not all objects are hashable. Instead we just track the depth of the object inspections and don't go too deep. Therefore, ``convert_instances=True`` is lossy ... be aware. If the object cannot be converted to primitive, it is returned unchanged if fallback is not set, return fallback(value) otherwise. .. versionchanged:: 2.22 Added *fallback* parameter. .. versionchanged:: 1.3 Support UUID encoding. .. versionchanged:: 1.6 Dictionary keys are now also encoded. """ orig_fallback = fallback if fallback is None: fallback = six.text_type # handle obvious types first - order of basic types determined by running # full tests on nova project, resulting in the following counts: # 572754 # 460353 # 379632 # 274610 # 199918 # 114200 # 51817 # 26164 # 6491 # 283 # 19 if isinstance(value, _simple_types): return value if isinstance(value, six.binary_type): if six.PY3: value = value.decode(encoding=encoding) return value # It's not clear why xmlrpclib created their own DateTime type, but # for our purposes, make it a datetime type which is explicitly # handled if isinstance(value, xmlrpclib.DateTime): value = datetime.datetime(*tuple(value.timetuple())[:6]) if isinstance(value, datetime.datetime): if convert_datetime: return value.strftime(timeutils.PERFECT_TIME_FORMAT) else: return value if isinstance(value, uuid.UUID): return six.text_type(value) if netaddr and isinstance(value, (netaddr.IPAddress, netaddr.IPNetwork)): return six.text_type(value) if ipaddress and isinstance(value, (ipaddress.IPv4Address, ipaddress.IPv6Address)): return six.text_type(value) # For exceptions, return the 'repr' of the exception object if isinstance(value, Exception): return repr(value) # value of itertools.count doesn't get caught by nasty_type_tests # and results in infinite loop when list(value) is called. if type(value) == itertools.count: return fallback(value) if any(test(value) for test in _nasty_type_tests): return fallback(value) # FIXME(vish): Workaround for LP bug 852095. Without this workaround, # tests that raise an exception in a mocked method that # has a @wrap_exception with a notifier will fail. If # we up the dependency to 0.5.4 (when it is released) we # can remove this workaround. if getattr(value, '__module__', None) == 'mox': return 'mock' if level > max_depth: return None # The try block may not be necessary after the class check above, # but just in case ... try: recursive = functools.partial(to_primitive, convert_instances=convert_instances, convert_datetime=convert_datetime, level=level, max_depth=max_depth, encoding=encoding, fallback=orig_fallback) if isinstance(value, dict): return {recursive(k): recursive(v) for k, v in value.items()} elif hasattr(value, 'iteritems'): return recursive(dict(value.iteritems()), level=level + 1) # Python 3 does not have iteritems elif hasattr(value, 'items'): return recursive(dict(value.items()), level=level + 1) elif hasattr(value, '__iter__'): return list(map(recursive, value)) elif convert_instances and hasattr(value, '__dict__'): # Likely an instance of something. Watch for cycles. # Ignore class member vars. return recursive(value.__dict__, level=level + 1) except TypeError: # Class objects are tricky since they may define something like # __iter__ defined but it isn't callable as list(). return fallback(value) if orig_fallback is not None: return orig_fallback(value) # TODO(gcb) raise ValueError in version 3.0 warnings.warn("Cannot convert %r to primitive, will raise ValueError " "instead of warning in version 3.0" % (value,)) return value JSONEncoder = json.JSONEncoder JSONDecoder = json.JSONDecoder def dumps(obj, default=to_primitive, **kwargs): """Serialize ``obj`` to a JSON formatted ``str``. :param obj: object to be serialized :param default: function that returns a serializable version of an object, :func:`to_primitive` is used by default. :param kwargs: extra named parameters, please see documentation \ of `json.dumps `_ :returns: json formatted string Use dump_as_bytes() to ensure that the result type is ``bytes`` on Python 2 and Python 3. """ return json.dumps(obj, default=default, **kwargs) def dump_as_bytes(obj, default=to_primitive, encoding='utf-8', **kwargs): """Serialize ``obj`` to a JSON formatted ``bytes``. :param obj: object to be serialized :param default: function that returns a serializable version of an object, :func:`to_primitive` is used by default. :param encoding: encoding used to encode the serialized JSON output :param kwargs: extra named parameters, please see documentation \ of `json.dumps `_ :returns: json formatted string .. versionadded:: 1.10 """ serialized = dumps(obj, default=default, **kwargs) if isinstance(serialized, six.text_type): # On Python 3, json.dumps() returns Unicode serialized = serialized.encode(encoding) return serialized def dump(obj, fp, *args, **kwargs): """Serialize ``obj`` as a JSON formatted stream to ``fp`` :param obj: object to be serialized :param fp: a ``.write()``-supporting file-like object :param default: function that returns a serializable version of an object, :func:`to_primitive` is used by default. :param args: extra arguments, please see documentation \ of `json.dump `_ :param kwargs: extra named parameters, please see documentation \ of `json.dump `_ .. versionchanged:: 1.3 The *default* parameter now uses :func:`to_primitive` by default. """ default = kwargs.get('default', to_primitive) return json.dump(obj, fp, default=default, *args, **kwargs) def loads(s, encoding='utf-8', **kwargs): """Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON :param s: string to deserialize :param encoding: encoding used to interpret the string :param kwargs: extra named parameters, please see documentation \ of `json.loads `_ :returns: python object """ return json.loads(encodeutils.safe_decode(s, encoding), **kwargs) def load(fp, encoding='utf-8', **kwargs): """Deserialize ``fp`` to a Python object. :param fp: a ``.read()`` -supporting file-like object :param encoding: encoding used to interpret the string :param kwargs: extra named parameters, please see documentation \ of `json.loads `_ :returns: python object """ return json.load(codecs.getreader(encoding)(fp), **kwargs) try: import anyjson except ImportError: pass else: anyjson._modules.append((__name__, 'dumps', TypeError, 'loads', ValueError, 'load')) anyjson.force_implementation(__name__) oslo.serialization-2.24.0/oslo_serialization/serializer/0000775000175100017510000000000013236475264023551 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/oslo_serialization/serializer/__init__.py0000666000175100017510000000000013236474736025655 0ustar zuulzuul00000000000000oslo.serialization-2.24.0/oslo_serialization/serializer/msgpack_serializer.py0000666000175100017510000000242013236474736030004 0ustar zuulzuul00000000000000# Copyright 2016 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from oslo_serialization import msgpackutils from oslo_serialization.serializer.base_serializer import BaseSerializer class MessagePackSerializer(BaseSerializer): """MessagePack serializer based on the msgpackutils module.""" def __init__(self, registry=None): self._registry = registry def dump(self, obj, fp): return msgpackutils.dump(obj, fp, registry=self._registry) def dump_as_bytes(self, obj): return msgpackutils.dumps(obj, registry=self._registry) def load(self, fp): return msgpackutils.load(fp, registry=self._registry) def load_from_bytes(self, s): return msgpackutils.loads(s, registry=self._registry) oslo.serialization-2.24.0/oslo_serialization/serializer/json_serializer.py0000666000175100017510000000254013236474736027333 0ustar zuulzuul00000000000000# Copyright 2016 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from oslo_serialization import jsonutils from oslo_serialization.serializer.base_serializer import BaseSerializer class JSONSerializer(BaseSerializer): """JSON serializer based on the jsonutils module.""" def __init__(self, default=jsonutils.to_primitive, encoding='utf-8'): self._default = default self._encoding = encoding def dump(self, obj, fp): return jsonutils.dump(obj, fp) def dump_as_bytes(self, obj): return jsonutils.dump_as_bytes(obj, default=self._default, encoding=self._encoding) def load(self, fp): return jsonutils.load(fp, encoding=self._encoding) def load_from_bytes(self, s): return jsonutils.loads(s, encoding=self._encoding) oslo.serialization-2.24.0/oslo_serialization/serializer/base_serializer.py0000666000175100017510000000321313236474736027272 0ustar zuulzuul00000000000000# Copyright 2016 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Unified and simplified API for oslo.serialization's serializers. """ import abc import six @six.add_metaclass(abc.ABCMeta) class BaseSerializer(object): """Generic (de-)serialization definition abstract base class.""" @abc.abstractmethod def dump(self, obj, fp): """Serialize ``obj`` as a stream to ``fp``. :param obj: python object to be serialized :param fp: ``.write()``-supporting file-like object """ @abc.abstractmethod def dump_as_bytes(self, obj): """Serialize ``obj`` to a byte string. :param obj: python object to be serialized :returns: byte string """ @abc.abstractmethod def load(self, fp): """Deserialize ``fp`` to a python object. :param fp: ``.read()``-supporting file-like object :returns: python object """ @abc.abstractmethod def load_from_bytes(self, s): """Deserialize ``s`` to a python object. :param s: byte string to be deserialized :returns: python object """ oslo.serialization-2.24.0/oslo_serialization/msgpackutils.py0000666000175100017510000003617713236474736024503 0ustar zuulzuul00000000000000# Copyright (C) 2015 Yahoo! Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. ''' MessagePack related utilities. This module provides a few things: #. A handy registry for getting an object down to something that can be msgpack serialized. See :class:`.HandlerRegistry`. #. Wrappers around :func:`.loads` and :func:`.dumps`. The :func:`.dumps` wrapper will automatically use the :py:attr:`~oslo_serialization.msgpackutils.default_registry` for you if needed. .. versionadded:: 1.3 ''' import datetime import functools import itertools import uuid import msgpack from oslo_utils import importutils from pytz import timezone import six import six.moves.xmlrpc_client as xmlrpclib netaddr = importutils.try_import("netaddr") class Interval(object): """Small and/or simple immutable integer/float interval class. Interval checking is **inclusive** of the min/max boundaries. """ def __init__(self, min_value, max_value): if min_value > max_value: raise ValueError("Minimum value %s must be less than" " or equal to maximum value %s" % (min_value, max_value)) self._min_value = min_value self._max_value = max_value @property def min_value(self): return self._min_value @property def max_value(self): return self._max_value def __contains__(self, value): return value >= self.min_value and value <= self.max_value def __repr__(self): return 'Interval(%s, %s)' % (self._min_value, self._max_value) # Expose these so that users don't have to import msgpack to gain these. PackException = msgpack.PackException UnpackException = msgpack.UnpackException class HandlerRegistry(object): """Registry of *type* specific msgpack handlers extensions. See: https://github.com/msgpack/msgpack/blob/master/spec.md#formats-ext Do note that due to the current limitations in the msgpack python library we can not *currently* dump/load a tuple without converting it to a list. This may be fixed in: https://github.com/msgpack/msgpack-python/pull/100 .. versionadded:: 1.5 """ reserved_extension_range = Interval(0, 32) """ These ranges are **always** reserved for use by ``oslo.serialization`` and its own add-ons extensions (these extensions are meant to be generally applicable to all of python). """ non_reserved_extension_range = Interval(33, 127) """ These ranges are **always** reserved for use by applications building their own type specific handlers (the meaning of extensions in this range will typically vary depending on application). """ min_value = 0 """ Applications can assign 0 to 127 to store application (or library) specific type handlers; see above ranges for what is reserved by this library and what is not. """ max_value = 127 """ Applications can assign 0 to 127 to store application (or library) specific type handlers; see above ranges for what is reserved by this library and what is not. """ def __init__(self): self._handlers = {} self._num_handlers = 0 self.frozen = False def __iter__(self): """Iterates over **all** registered handlers.""" for handlers in six.itervalues(self._handlers): for h in handlers: yield h def register(self, handler, reserved=False, override=False): """Register a extension handler to handle its associated type.""" if self.frozen: raise ValueError("Frozen handler registry can't be modified") if reserved: ok_interval = self.reserved_extension_range else: ok_interval = self.non_reserved_extension_range ident = handler.identity if ident < ok_interval.min_value: raise ValueError("Handler '%s' identity must be greater" " or equal to %s" % (handler, ok_interval.min_value)) if ident > ok_interval.max_value: raise ValueError("Handler '%s' identity must be less than" " or equal to %s" % (handler, ok_interval.max_value)) if ident in self._handlers and override: existing_handlers = self._handlers[ident] # Insert at the front so that overrides get selected before # whatever existed before the override... existing_handlers.insert(0, handler) self._num_handlers += 1 elif ident in self._handlers and not override: raise ValueError("Already registered handler(s) with" " identity %s: %s" % (ident, self._handlers[ident])) else: self._handlers[ident] = [handler] self._num_handlers += 1 def __len__(self): """Return how many extension handlers are registered.""" return self._num_handlers def __contains__(self, identity): """Return if any handler exists for the given identity (number).""" return identity in self._handlers def copy(self, unfreeze=False): """Deep copy the given registry (and its handlers).""" c = type(self)() for ident, handlers in self._handlers.items(): cloned_handlers = [] for h in handlers: if hasattr(h, 'copy'): h = h.copy(c) cloned_handlers.append(h) c._handlers[ident] = cloned_handlers c._num_handlers += len(cloned_handlers) if not unfreeze and self.frozen: c.frozen = True return c def get(self, identity): """Get the handler for the given numeric identity (or none).""" maybe_handlers = self._handlers.get(identity) if maybe_handlers: # Prefer the first (if there are many) as this is how we # override built-in extensions (for those that wish to do this). return maybe_handlers[0] else: return None def match(self, obj): """Match the registries handlers to the given object (or none).""" for possible_handlers in six.itervalues(self._handlers): for h in possible_handlers: if isinstance(obj, h.handles): return h return None class UUIDHandler(object): identity = 0 handles = (uuid.UUID,) @staticmethod def serialize(obj): return six.text_type(obj.hex).encode('ascii') @staticmethod def deserialize(data): return uuid.UUID(hex=six.text_type(data, encoding='ascii')) class DateTimeHandler(object): identity = 1 handles = (datetime.datetime,) def __init__(self, registry): self._registry = registry def copy(self, registry): return type(self)(registry) def serialize(self, dt): dct = { u'day': dt.day, u'month': dt.month, u'year': dt.year, u'hour': dt.hour, u'minute': dt.minute, u'second': dt.second, u'microsecond': dt.microsecond, } if dt.tzinfo: tz = dt.tzinfo.tzname(None) if six.PY2: tz = tz.decode("ascii") dct[u'tz'] = tz return dumps(dct, registry=self._registry) def deserialize(self, blob): dct = loads(blob, registry=self._registry) if six.PY3 and b"day" in dct: # NOTE(sileht): oslo.serialization <= 2.4.1 was # storing thing as unicode for py3 while is was # bytes for py2 # For python2, we don't care bytes or unicode works # for dict keys and tz # But for python3, we have some backward compability # to take care in case of the payload have been produced # by python2 and now read by python3 dct = dict((k.decode("ascii"), v) for k, v in dct.items()) if 'tz' in dct: dct['tz'] = dct['tz'].decode("ascii") dt = datetime.datetime(day=dct['day'], month=dct['month'], year=dct['year'], hour=dct['hour'], minute=dct['minute'], second=dct['second'], microsecond=dct['microsecond']) if 'tz' in dct: tzinfo = timezone(dct['tz']) dt = tzinfo.localize(dt) return dt class CountHandler(object): identity = 2 handles = (itertools.count,) @staticmethod def serialize(obj): # FIXME(harlowja): figure out a better way to avoid hacking into # the string representation of count to get at the right numbers... obj = six.text_type(obj) start = obj.find("(") + 1 end = obj.rfind(")") pieces = obj[start:end].split(",") if len(pieces) == 1: start = int(pieces[0]) step = 1 else: start = int(pieces[0]) step = int(pieces[1]) return msgpack.packb([start, step]) @staticmethod def deserialize(data): value = msgpack.unpackb(data) start, step = value return itertools.count(start, step) if netaddr is not None: class NetAddrIPHandler(object): identity = 3 handles = (netaddr.IPAddress,) @staticmethod def serialize(obj): return msgpack.packb(obj.value) @staticmethod def deserialize(data): return netaddr.IPAddress(msgpack.unpackb(data)) else: NetAddrIPHandler = None class SetHandler(object): identity = 4 handles = (set,) def __init__(self, registry): self._registry = registry def copy(self, registry): return type(self)(registry) def serialize(self, obj): return dumps(list(obj), registry=self._registry) def deserialize(self, data): return self.handles[0](loads(data, registry=self._registry)) class FrozenSetHandler(SetHandler): identity = 5 handles = (frozenset,) class XMLRPCDateTimeHandler(object): handles = (xmlrpclib.DateTime,) identity = 6 def __init__(self, registry): self._handler = DateTimeHandler(registry) def copy(self, registry): return type(self)(registry) def serialize(self, obj): dt = datetime.datetime(*tuple(obj.timetuple())[:6]) return self._handler.serialize(dt) def deserialize(self, blob): dt = self._handler.deserialize(blob) return xmlrpclib.DateTime(dt.timetuple()) class DateHandler(object): identity = 7 handles = (datetime.date,) def __init__(self, registry): self._registry = registry def copy(self, registry): return type(self)(registry) def serialize(self, d): dct = { u'year': d.year, u'month': d.month, u'day': d.day, } return dumps(dct, registry=self._registry) def deserialize(self, blob): dct = loads(blob, registry=self._registry) if six.PY3 and b"day" in dct: # NOTE(sileht): see DateTimeHandler.deserialize() dct = dict((k.decode("ascii"), v) for k, v in dct.items()) return datetime.date(year=dct['year'], month=dct['month'], day=dct['day']) def _serializer(registry, obj): handler = registry.match(obj) if handler is None: raise ValueError("No serialization handler registered" " for type '%s'" % (type(obj).__name__)) return msgpack.ExtType(handler.identity, handler.serialize(obj)) def _unserializer(registry, code, data): handler = registry.get(code) if not handler: return msgpack.ExtType(code, data) else: return handler.deserialize(data) def _create_default_registry(): registry = HandlerRegistry() registry.register(DateTimeHandler(registry), reserved=True) registry.register(DateHandler(registry), reserved=True) registry.register(UUIDHandler(), reserved=True) registry.register(CountHandler(), reserved=True) registry.register(SetHandler(registry), reserved=True) registry.register(FrozenSetHandler(registry), reserved=True) if netaddr is not None: registry.register(NetAddrIPHandler(), reserved=True) registry.register(XMLRPCDateTimeHandler(registry), reserved=True) registry.frozen = True return registry default_registry = _create_default_registry() """ Default, read-only/frozen registry that will be used when none is provided. This registry has msgpack extensions for the following: * ``DateTime`` objects. * ``Date`` objects. * ``UUID`` objects. * ``itertools.count`` objects/iterators. * ``set`` and ``frozenset`` container(s). * ``netaddr.IPAddress`` objects (only if ``netaddr`` is importable). * ``xmlrpclib.DateTime`` datetime objects. .. versionadded:: 1.5 """ def load(fp, registry=None): """Deserialize ``fp`` into a Python object. .. versionchanged:: 1.5 Added *registry* parameter. """ if registry is None: registry = default_registry # NOTE(harlowja): the reason we can't use the more native msgpack functions # here is that the unpack() function (oddly) doesn't seem to take a # 'ext_hook' parameter.. ext_hook = functools.partial(_unserializer, registry) return msgpack.Unpacker(fp, ext_hook=ext_hook, encoding='utf-8').unpack() def dump(obj, fp, registry=None): """Serialize ``obj`` as a messagepack formatted stream to ``fp``. .. versionchanged:: 1.5 Added *registry* parameter. """ if registry is None: registry = default_registry return msgpack.pack(obj, fp, default=functools.partial(_serializer, registry), use_bin_type=True) def dumps(obj, registry=None): """Serialize ``obj`` to a messagepack formatted ``str``. .. versionchanged:: 1.5 Added *registry* parameter. """ if registry is None: registry = default_registry return msgpack.packb(obj, default=functools.partial(_serializer, registry), use_bin_type=True) def loads(s, registry=None): """Deserialize ``s`` messagepack ``str`` into a Python object. .. versionchanged:: 1.5 Added *registry* parameter. """ if registry is None: registry = default_registry ext_hook = functools.partial(_unserializer, registry) return msgpack.unpackb(s, ext_hook=ext_hook, encoding='utf-8') oslo.serialization-2.24.0/oslo_serialization/tests/0000775000175100017510000000000013236475264022542 5ustar zuulzuul00000000000000oslo.serialization-2.24.0/oslo_serialization/tests/__init__.py0000666000175100017510000000000013236474736024646 0ustar zuulzuul00000000000000oslo.serialization-2.24.0/oslo_serialization/tests/test_msgpackutils.py0000666000175100017510000001512013236474736026665 0ustar zuulzuul00000000000000# Copyright (C) 2015 Yahoo! Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import datetime import itertools import netaddr from oslotest import base as test_base from pytz import timezone import six import six.moves.xmlrpc_client as xmlrpclib from oslo_serialization import msgpackutils from oslo_utils import uuidutils _TZ_FMT = '%Y-%m-%d %H:%M:%S %Z%z' class Color(object): def __init__(self, r, g, b): self.r = r self.g = g self.b = b class ColorHandler(object): handles = (Color,) identity = ( msgpackutils.HandlerRegistry.non_reserved_extension_range.min_value + 1 ) @staticmethod def serialize(obj): blob = '%s, %s, %s' % (obj.r, obj.g, obj.b) if six.PY3: blob = blob.encode("ascii") return blob @staticmethod def deserialize(data): chunks = [int(c.strip()) for c in data.split(b",")] return Color(chunks[0], chunks[1], chunks[2]) class MySpecialSetHandler(object): handles = (set,) identity = msgpackutils.SetHandler.identity def _dumps_loads(obj): obj = msgpackutils.dumps(obj) return msgpackutils.loads(obj) class MsgPackUtilsTest(test_base.BaseTestCase): def test_list(self): self.assertEqual([1, 2, 3], _dumps_loads([1, 2, 3])) def test_empty_list(self): self.assertEqual([], _dumps_loads([])) def test_tuple(self): # Seems like we do lose whether it was a tuple or not... # # Maybe fixed someday: # # https://github.com/msgpack/msgpack-python/issues/98 self.assertEqual([1, 2, 3], _dumps_loads((1, 2, 3))) def test_dict(self): self.assertEqual(dict(a=1, b=2, c=3), _dumps_loads(dict(a=1, b=2, c=3))) def test_empty_dict(self): self.assertEqual({}, _dumps_loads({})) def test_complex_dict(self): src = { 'now': datetime.datetime(1920, 2, 3, 4, 5, 6, 7), 'later': datetime.datetime(1921, 2, 3, 4, 5, 6, 9), 'a': 1, 'b': 2.0, 'c': [], 'd': set([1, 2, 3]), 'zzz': uuidutils.generate_uuid(), 'yyy': 'yyy', 'ddd': b'bbb', 'today': datetime.date.today(), } self.assertEqual(src, _dumps_loads(src)) def test_itercount(self): it = itertools.count(1) six.next(it) six.next(it) it2 = _dumps_loads(it) self.assertEqual(six.next(it), six.next(it2)) it = itertools.count(0) it2 = _dumps_loads(it) self.assertEqual(six.next(it), six.next(it2)) def test_itercount_step(self): it = itertools.count(1, 3) it2 = _dumps_loads(it) self.assertEqual(six.next(it), six.next(it2)) def test_set(self): self.assertEqual(set([1, 2]), _dumps_loads(set([1, 2]))) def test_empty_set(self): self.assertEqual(set([]), _dumps_loads(set([]))) def test_frozenset(self): self.assertEqual(frozenset([1, 2]), _dumps_loads(frozenset([1, 2]))) def test_empty_frozenset(self): self.assertEqual(frozenset([]), _dumps_loads(frozenset([]))) def test_datetime_preserve(self): x = datetime.datetime(1920, 2, 3, 4, 5, 6, 7) self.assertEqual(x, _dumps_loads(x)) def test_datetime(self): x = xmlrpclib.DateTime() x.decode("19710203T04:05:06") self.assertEqual(x, _dumps_loads(x)) def test_ipaddr(self): thing = {'ip_addr': netaddr.IPAddress('1.2.3.4')} self.assertEqual(thing, _dumps_loads(thing)) def test_today(self): today = datetime.date.today() self.assertEqual(today, _dumps_loads(today)) def test_datetime_tz_clone(self): eastern = timezone('US/Eastern') now = datetime.datetime.now() e_dt = eastern.localize(now) e_dt2 = _dumps_loads(e_dt) self.assertEqual(e_dt, e_dt2) self.assertEqual(e_dt.strftime(_TZ_FMT), e_dt2.strftime(_TZ_FMT)) def test_datetime_tz_different(self): eastern = timezone('US/Eastern') pacific = timezone('US/Pacific') now = datetime.datetime.now() e_dt = eastern.localize(now) p_dt = pacific.localize(now) self.assertNotEqual(e_dt, p_dt) self.assertNotEqual(e_dt.strftime(_TZ_FMT), p_dt.strftime(_TZ_FMT)) e_dt2 = _dumps_loads(e_dt) p_dt2 = _dumps_loads(p_dt) self.assertNotEqual(e_dt2, p_dt2) self.assertNotEqual(e_dt2.strftime(_TZ_FMT), p_dt2.strftime(_TZ_FMT)) self.assertEqual(e_dt, e_dt2) self.assertEqual(p_dt, p_dt2) def test_copy_then_register(self): registry = msgpackutils.default_registry self.assertRaises(ValueError, registry.register, MySpecialSetHandler(), reserved=True, override=True) registry = registry.copy(unfreeze=True) registry.register(MySpecialSetHandler(), reserved=True, override=True) h = registry.match(set()) self.assertIsInstance(h, MySpecialSetHandler) def test_bad_register(self): registry = msgpackutils.default_registry self.assertRaises(ValueError, registry.register, MySpecialSetHandler(), reserved=True, override=True) self.assertRaises(ValueError, registry.register, MySpecialSetHandler()) registry = registry.copy(unfreeze=True) registry.register(ColorHandler()) self.assertRaises(ValueError, registry.register, ColorHandler()) def test_custom_register(self): registry = msgpackutils.default_registry.copy(unfreeze=True) registry.register(ColorHandler()) c = Color(255, 254, 253) c_b = msgpackutils.dumps(c, registry=registry) c = msgpackutils.loads(c_b, registry=registry) self.assertEqual(255, c.r) self.assertEqual(254, c.g) self.assertEqual(253, c.b) def test_object(self): self.assertRaises(ValueError, msgpackutils.dumps, object()) oslo.serialization-2.24.0/oslo_serialization/tests/test_base64.py0000666000175100017510000000463013236474736025247 0ustar zuulzuul00000000000000# Copyright 2015 Red Hat # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from oslo_serialization import base64 from oslotest import base as test_base class Base64Tests(test_base.BaseTestCase): def test_encode_as_bytes(self): self.assertEqual(b'dGV4dA==', base64.encode_as_bytes(b'text')) self.assertEqual(b'dGV4dA==', base64.encode_as_bytes(u'text')) self.assertEqual(b'ZTrDqQ==', base64.encode_as_bytes(u'e:\xe9')) self.assertEqual(b'ZTrp', base64.encode_as_bytes(u'e:\xe9', encoding='latin1')) def test_encode_as_text(self): self.assertEqual(u'dGV4dA==', base64.encode_as_text(b'text')) self.assertEqual(u'dGV4dA==', base64.encode_as_text(u'text')) self.assertEqual(u'ZTrDqQ==', base64.encode_as_text(u'e:\xe9')) self.assertEqual(u'ZTrp', base64.encode_as_text(u'e:\xe9', encoding='latin1')) def test_decode_as_bytes(self): self.assertEqual(b'text', base64.decode_as_bytes(b'dGV4dA==')) self.assertEqual(b'text', base64.decode_as_bytes(u'dGV4dA==')) def test_decode_as_bytes__error(self): self.assertRaises(TypeError, base64.decode_as_bytes, 'hello world') def test_decode_as_text(self): self.assertEqual(u'text', base64.decode_as_text(b'dGV4dA==')) self.assertEqual(u'text', base64.decode_as_text(u'dGV4dA==')) self.assertEqual(u'e:\xe9', base64.decode_as_text(u'ZTrDqQ==')) self.assertEqual(u'e:\xe9', base64.decode_as_text(u'ZTrp', encoding='latin1')) oslo.serialization-2.24.0/oslo_serialization/tests/test_jsonutils.py0000666000175100017510000003200313236474736026210 0ustar zuulzuul00000000000000# Copyright 2011 OpenStack Foundation. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import collections import datetime import functools import ipaddress import itertools import json import mock import netaddr from oslo_i18n import fixture from oslotest import base as test_base import six import six.moves.xmlrpc_client as xmlrpclib from oslo_serialization import jsonutils class ReprObject(object): def __repr__(self): return 'repr' class JSONUtilsTestMixin(object): json_impl = None def setUp(self): super(JSONUtilsTestMixin, self).setUp() self.json_patcher = mock.patch.multiple( jsonutils, json=self.json_impl, ) self.json_impl_mock = self.json_patcher.start() def tearDown(self): self.json_patcher.stop() super(JSONUtilsTestMixin, self).tearDown() def test_dumps(self): self.assertEqual('{"a": "b"}', jsonutils.dumps({'a': 'b'})) def test_dumps_default(self): args = [ReprObject()] convert = functools.partial(jsonutils.to_primitive, fallback=repr) self.assertEqual('["repr"]', jsonutils.dumps(args, default=convert)) def test_dump_as_bytes(self): self.assertEqual(b'{"a": "b"}', jsonutils.dump_as_bytes({'a': 'b'})) def test_dumps_namedtuple(self): n = collections.namedtuple("foo", "bar baz")(1, 2) self.assertEqual('[1, 2]', jsonutils.dumps(n)) def test_dump(self): expected = '{"a": "b"}' json_dict = {'a': 'b'} fp = six.StringIO() jsonutils.dump(json_dict, fp) self.assertEqual(expected, fp.getvalue()) def test_dump_namedtuple(self): expected = '[1, 2]' json_dict = collections.namedtuple("foo", "bar baz")(1, 2) fp = six.StringIO() jsonutils.dump(json_dict, fp) self.assertEqual(expected, fp.getvalue()) def test_loads(self): self.assertEqual({'a': 'b'}, jsonutils.loads('{"a": "b"}')) def test_loads_unicode(self): self.assertIsInstance(jsonutils.loads(b'"foo"'), six.text_type) self.assertIsInstance(jsonutils.loads(u'"foo"'), six.text_type) # 'test' in Ukrainian i18n_str_unicode = u'"\u0442\u0435\u0441\u0442"' self.assertIsInstance(jsonutils.loads(i18n_str_unicode), six.text_type) i18n_str = i18n_str_unicode.encode('utf-8') self.assertIsInstance(jsonutils.loads(i18n_str), six.text_type) def test_loads_with_kwargs(self): jsontext = u'{"foo": 3}' result = jsonutils.loads(jsontext, parse_int=lambda x: 5) self.assertEqual(5, result['foo']) def test_load(self): jsontext = u'{"a": "\u0442\u044d\u0441\u0442"}' expected = {u'a': u'\u0442\u044d\u0441\u0442'} for encoding in ('utf-8', 'cp1251'): fp = six.BytesIO(jsontext.encode(encoding)) result = jsonutils.load(fp, encoding=encoding) self.assertEqual(expected, result) for key, val in result.items(): self.assertIsInstance(key, six.text_type) self.assertIsInstance(val, six.text_type) def test_dumps_exception_value(self): self.assertEqual('{"a": "ValueError(\'hello\',)"}', jsonutils.dumps({"a": ValueError("hello")})) class JSONUtilsTestJson(JSONUtilsTestMixin, test_base.BaseTestCase): json_impl = json class ToPrimitiveTestCase(test_base.BaseTestCase): def setUp(self): super(ToPrimitiveTestCase, self).setUp() self.trans_fixture = self.useFixture(fixture.Translation()) def test_bytes(self): self.assertEqual(jsonutils.to_primitive(b'abc'), 'abc') def test_list(self): self.assertEqual([1, 2, 3], jsonutils.to_primitive([1, 2, 3])) def test_empty_list(self): self.assertEqual([], jsonutils.to_primitive([])) def test_tuple(self): self.assertEqual([1, 2, 3], jsonutils.to_primitive((1, 2, 3))) def test_dict(self): self.assertEqual(dict(a=1, b=2, c=3), jsonutils.to_primitive(dict(a=1, b=2, c=3))) def test_empty_dict(self): self.assertEqual({}, jsonutils.to_primitive({})) def test_datetime(self): x = datetime.datetime(1920, 2, 3, 4, 5, 6, 7) self.assertEqual('1920-02-03T04:05:06.000007', jsonutils.to_primitive(x)) def test_datetime_preserve(self): x = datetime.datetime(1920, 2, 3, 4, 5, 6, 7) self.assertEqual(x, jsonutils.to_primitive(x, convert_datetime=False)) def test_DateTime(self): x = xmlrpclib.DateTime() x.decode("19710203T04:05:06") self.assertEqual('1971-02-03T04:05:06.000000', jsonutils.to_primitive(x)) def test_iter(self): class IterClass(object): def __init__(self): self.data = [1, 2, 3, 4, 5] self.index = 0 def __iter__(self): return self def next(self): if self.index == len(self.data): raise StopIteration self.index = self.index + 1 return self.data[self.index - 1] __next__ = next x = IterClass() self.assertEqual([1, 2, 3, 4, 5], jsonutils.to_primitive(x)) def test_iteritems(self): class IterItemsClass(object): def __init__(self): self.data = dict(a=1, b=2, c=3).items() self.index = 0 def iteritems(self): return self.data x = IterItemsClass() p = jsonutils.to_primitive(x) self.assertEqual({'a': 1, 'b': 2, 'c': 3}, p) def test_iteritems_with_cycle(self): class IterItemsClass(object): def __init__(self): self.data = dict(a=1, b=2, c=3) self.index = 0 def iteritems(self): return self.data.items() x = IterItemsClass() x2 = IterItemsClass() x.data['other'] = x2 x2.data['other'] = x # If the cycle isn't caught, to_primitive() will eventually result in # an exception due to excessive recursion depth. jsonutils.to_primitive(x) def test_items(self): # Use items() when iteritems() is not available. class ItemsClass(object): def __init__(self): self.data = dict(a=1, b=2, c=3) def items(self): return self.data.items() x = ItemsClass() p = jsonutils.to_primitive(x) self.assertEqual({'a': 1, 'b': 2, 'c': 3}, p) def test_precedence_items_iteritems(self): class ItemsIterItemsClass(object): def items(self): return {'items': 'items'} def iteritems(self): return {'iteritems': 'iteritems'} x = ItemsIterItemsClass() p = jsonutils.to_primitive(x) # Prefer iteritems over items self.assertEqual({'iteritems': 'iteritems'}, p) def test_mapping(self): # Make sure collections.Mapping is converted to a dict # and not a list. class MappingClass(collections.Mapping): def __init__(self): self.data = dict(a=1, b=2, c=3) def __getitem__(self, val): return self.data[val] def __iter__(self): return iter(self.data) def __len__(self): return len(self.data) x = MappingClass() p = jsonutils.to_primitive(x) self.assertEqual({'a': 1, 'b': 2, 'c': 3}, p) @mock.patch('warnings.warn') def test_instance(self, warn_mock): class MysteryClass(object): a = 10 def __init__(self): self.b = 1 x = MysteryClass() self.assertEqual(dict(b=1), jsonutils.to_primitive(x, convert_instances=True)) self.assertEqual(x, jsonutils.to_primitive(x)) warn_mock.assert_called_once() def test_typeerror(self): x = bytearray # Class, not instance if six.PY3: self.assertEqual(u"", jsonutils.to_primitive(x)) else: self.assertEqual(u"", jsonutils.to_primitive(x)) def test_nasties(self): def foo(): pass x = [datetime, foo, dir] ret = jsonutils.to_primitive(x) self.assertEqual(3, len(ret)) self.assertTrue(ret[0].startswith(u".foo at 0x' )) else: self.assertTrue(ret[1].startswith('', ret[2]) def test_depth(self): class LevelsGenerator(object): def __init__(self, levels): self._levels = levels def iteritems(self): if self._levels == 0: return iter([]) else: return iter([(0, LevelsGenerator(self._levels - 1))]) l4_obj = LevelsGenerator(4) json_l2 = {0: {0: None}} json_l3 = {0: {0: {0: None}}} json_l4 = {0: {0: {0: {0: None}}}} ret = jsonutils.to_primitive(l4_obj, max_depth=2) self.assertEqual(json_l2, ret) ret = jsonutils.to_primitive(l4_obj, max_depth=3) self.assertEqual(json_l3, ret) ret = jsonutils.to_primitive(l4_obj, max_depth=4) self.assertEqual(json_l4, ret) def test_ipaddr_using_netaddr(self): thing = {'ip_addr': netaddr.IPAddress('1.2.3.4')} ret = jsonutils.to_primitive(thing) self.assertEqual({'ip_addr': '1.2.3.4'}, ret) def test_ipaddr_using_ipaddress_v4(self): thing = {'ip_addr': ipaddress.ip_address(u'192.168.0.1')} ret = jsonutils.to_primitive(thing) self.assertEqual({'ip_addr': '192.168.0.1'}, ret) def test_ipaddr_using_ipaddress_v6(self): thing = {'ip_addr': ipaddress.ip_address(u'2001:db8::')} ret = jsonutils.to_primitive(thing) self.assertEqual({'ip_addr': '2001:db8::'}, ret) def test_ipnet_using_netaddr(self): thing = {'ip_net': netaddr.IPNetwork('1.2.3.0/24')} ret = jsonutils.to_primitive(thing) self.assertEqual({'ip_net': '1.2.3.0/24'}, ret) def test_message_with_param(self): msg = self.trans_fixture.lazy('A message with param: %s') msg = msg % 'test_domain' ret = jsonutils.to_primitive(msg) self.assertEqual(msg, ret) def test_message_with_named_param(self): msg = self.trans_fixture.lazy('A message with params: %(param)s') msg = msg % {'param': 'hello'} ret = jsonutils.to_primitive(msg) self.assertEqual(msg, ret) def test_fallback(self): obj = ReprObject() ret = jsonutils.to_primitive(obj) self.assertIs(obj, ret) ret = jsonutils.to_primitive(obj, fallback=repr) self.assertEqual('repr', ret) def test_fallback_list(self): obj = ReprObject() obj_list = [obj] ret = jsonutils.to_primitive(obj_list) self.assertEqual([obj], ret) ret = jsonutils.to_primitive(obj_list, fallback=repr) self.assertEqual(['repr'], ret) def test_fallback_itertools_count(self): obj = itertools.count(1) ret = jsonutils.to_primitive(obj) self.assertEqual(six.text_type(obj), ret) ret = jsonutils.to_primitive(obj, fallback=lambda _: 'itertools_count') self.assertEqual('itertools_count', ret) def test_fallback_nasty(self): obj = int ret = jsonutils.to_primitive(obj) self.assertEqual(six.text_type(obj), ret) def formatter(typeobj): return 'type:%s' % typeobj.__name__ ret = jsonutils.to_primitive(obj, fallback=formatter) self.assertEqual("type:int", ret) def test_fallback_typeerror(self): class NotIterable(object): # __iter__ is not callable, cause a TypeError in to_primitive() __iter__ = None obj = NotIterable() ret = jsonutils.to_primitive(obj) self.assertEqual(six.text_type(obj), ret) ret = jsonutils.to_primitive(obj, fallback=lambda _: 'fallback') self.assertEqual('fallback', ret) def test_exception(self): self.assertEqual("ValueError('an exception',)", jsonutils.to_primitive(ValueError("an exception"))) oslo.serialization-2.24.0/oslo_serialization/base64.py0000666000175100017510000000535513236474736023053 0ustar zuulzuul00000000000000# Copyright 2015 Red Hat # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Utilities to encode and decode Base64. .. versionadded:: 1.10 """ from __future__ import absolute_import import base64 import binascii import six def encode_as_bytes(s, encoding='utf-8'): """Encode a string using Base64. If *s* is a text string, first encode it to *encoding* (UTF-8 by default). :param s: bytes or text string to be encoded :param encoding: encoding used to encode *s* if it's a text string :returns: Base64 encoded byte string (bytes) Use encode_as_text() to get the Base64 encoded string as text. """ if isinstance(s, six.text_type): s = s.encode(encoding) return base64.b64encode(s) def encode_as_text(s, encoding='utf-8'): """Encode a string using Base64. If *s* is a text string, first encode it to *encoding* (UTF-8 by default). :param s: bytes or text string to be encoded :param encoding: encoding used to encode *s* if it's a text string :returns: Base64 encoded text string (Unicode) Use encode_as_bytes() to get the Base64 encoded string as bytes. """ encoded = encode_as_bytes(s, encoding=encoding) return encoded.decode('ascii') def decode_as_bytes(encoded): """Decode a Base64 encoded string. :param encoded: bytes or text Base64 encoded string to be decoded :returns: decoded bytes string (bytes) Use decode_as_text() to get the decoded string as text. A TypeError is raised if the input is invalid (or incorrectly padded). """ if isinstance(encoded, bytes): encoded = encoded.decode('ascii') try: return base64.b64decode(encoded) except binascii.Error as e: # Transform this exception for consistency. raise TypeError(str(e)) def decode_as_text(encoded, encoding='utf-8'): """Decode a Base64 encoded string. Decode the Base64 string and then decode the result from *encoding* (UTF-8 by default). :param encoded: bytes or text Base64 encoded string to be decoded :returns: decoded text string (bytes) Use decode_as_bytes() to get the decoded string as bytes. """ decoded = decode_as_bytes(encoded) return decoded.decode(encoding)