Hello community, here is the log from the commit of package python-pybeam for openSUSE:Factory checked in at 2019-01-28 20:45:19 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-pybeam (Old) and /work/SRC/openSUSE:Factory/.python-pybeam.new.28833 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-pybeam" Mon Jan 28 20:45:19 2019 rev:13 rq:662304 version:0.5 Changes: -------- --- /work/SRC/openSUSE:Factory/python-pybeam/python-pybeam.changes 2018-12-27 00:27:47.327741789 +0100 +++ /work/SRC/openSUSE:Factory/.python-pybeam.new.28833/python-pybeam.changes 2019-01-28 20:45:21.742099774 +0100 @@ -1,0 +2,6 @@ +Wed Dec 26 12:45:48 UTC 2018 - [email protected] + +- Version 0.5 + - ported to construct 2.9.x + +------------------------------------------------------------------- Old: ---- LICENSE pybeam-0.4.1.tar.gz New: ---- pybeam-0.5.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-pybeam.spec ++++++ --- /var/tmp/diff_new_pack.1PEe9A/_old 2019-01-28 20:45:23.358098075 +0100 +++ /var/tmp/diff_new_pack.1PEe9A/_new 2019-01-28 20:45:23.358098075 +0100 @@ -12,26 +12,28 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# Please submit bugfixes or comments via http://bugs.opensuse.org/ # %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-pybeam -Version: 0.4.1 +Version: 0.5 Release: 0 Summary: Python module to parse Erlang BEAM files License: MIT Group: Development/Languages/Python URL: http://github.com/matwey/pybeam Source: https://files.pythonhosted.org/packages/source/p/pybeam/pybeam-%{version}.tar.gz -Source1: LICENSE -BuildRequires: %{python_module construct < 2.9} -BuildRequires: %{python_module construct >= 2.8} +BuildRequires: %{python_module Sphinx} +BuildRequires: %{python_module construct < 2.10} +BuildRequires: %{python_module construct >= 2.9} BuildRequires: %{python_module setuptools} BuildRequires: %{python_module six} +BuildRequires: fdupes BuildRequires: python-rpm-macros -Requires: python-construct +Requires: python-construct < 2.10 +Requires: python-construct >= 2.9 Requires: python-six >= 1.4.0 BuildArch: noarch %python_subpackages @@ -43,13 +45,16 @@ %prep %setup -q -n pybeam-%{version} -cp %{SOURCE1} . %build %python_build %install %python_install +%fdupes %{buildroot}/%{_prefix} + +%check +%python_exec setup.py test %files %{python_files} %license LICENSE ++++++ pybeam-0.4.1.tar.gz -> pybeam-0.5.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/LICENSE new/pybeam-0.5/LICENSE --- old/pybeam-0.4.1/LICENSE 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/LICENSE 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2013 Matwey V. Kornilov <[email protected]> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/MANIFEST.in new/pybeam-0.5/MANIFEST.in --- old/pybeam-0.4.1/MANIFEST.in 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/MANIFEST.in 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,5 @@ +include LICENSE +include README.md +include doc/* +include requirements.txt +recursive-include test *.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/PKG-INFO new/pybeam-0.5/PKG-INFO --- old/pybeam-0.4.1/PKG-INFO 2018-03-19 12:22:35.000000000 +0100 +++ new/pybeam-0.5/PKG-INFO 2018-12-28 09:40:48.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: pybeam -Version: 0.4.1 +Version: 0.5 Summary: Python module to parse Erlang BEAM files Home-page: http://github.com/matwey/pybeam Author: Matwey V. Kornilov diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/README.md new/pybeam-0.5/README.md --- old/pybeam-0.4.1/README.md 2018-03-19 12:22:19.000000000 +0100 +++ new/pybeam-0.5/README.md 2018-12-28 09:40:23.000000000 +0100 @@ -1,25 +1,25 @@ -pybeam -====== [](https://travis-ci.org/matwey/pybeam) [](https://badge.fury.io/py/pybeam) +[](http://pybeam.readthedocs.io/en/latest/?badge=latest) +pybeam +====== Python module to parse Erlang BEAM files. -This is not ready yet, so pull-requests are welcome. +Both python 2.7 and python 3.3 are supported. Python 3.2 are known not to work. +Pull-requests are always welcome. -Quick start: +## Quick start: ```python import pybeam -p=pybeam.BeamFile("/usr/lib64/erlang/lib/appmon-2.1.14.1/ebin/appmon.beam") -print p.imports -print p.exports -print p.atoms +p = pybeam.BeamFile("/usr/lib64/erlang/lib/appmon-2.1.14.1/ebin/appmon.beam") +print(p.imports) +print(p.exports) +print(p.atoms) ``` -Both python 2.7 and python 3.3 are supported. Python 3.2 are known not to work. - ## References * [Erlang BEAM file format](http://www.erlang.se/~bjorn/beam_file_format.html) * [Erlang external term format](http://erlang.org/doc/apps/erts/erl_ext_dist.html) * [BEAM file format](http://synrc.com/publications/cat/Functional%20Languages/Erlang/BEAM.pdf) - +* [BEAM Wisdoms](http://beam-wisdoms.clau.se/en/latest/) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/doc/conf.py new/pybeam-0.5/doc/conf.py --- old/pybeam-0.4.1/doc/conf.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/doc/conf.py 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,160 @@ +# -*- coding: utf-8 -*- +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +# -- Path setup -------------------------------------------------------------- + +# 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. +# +import os +import sys +sys.path.insert(0, os.path.abspath('./..')) + + +# -- Project information ----------------------------------------------------- + +project = 'pybeam' +copyright = '2018, Matwey V. Kornilov' +author = 'Matwey V. Kornilov' + +# The short X.Y version +version = '' +# The full version, including alpha/beta/rc tags +release = '' + + +# -- 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 = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.doctest', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path . +exclude_patterns = [] + +# 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. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# 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 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'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'pybeamdoc' + + +# -- 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': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# 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 = [ + (master_doc, 'pybeam.tex', 'pybeam Documentation', + 'Matwey V. Kornilov', 'manual'), +] + + +# -- Options for manual page output ------------------------------------------ + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'pybeam', 'pybeam Documentation', + [author], 1) +] + + +# -- 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 = [ + (master_doc, 'pybeam', 'pybeam Documentation', + author, 'pybeam', 'One line description of project.', + 'Miscellaneous'), +] + + +# -- Extension configuration ------------------------------------------------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/doc/index.rst new/pybeam-0.5/doc/index.rst --- old/pybeam-0.4.1/doc/index.rst 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/doc/index.rst 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,19 @@ +.. pybeam documentation master file, created by + sphinx-quickstart on Thu May 3 18:01:53 2018. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to pybeam's documentation! +================================== + +.. toctree:: + :maxdepth: 2 + + modules.rst + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/doc/modules.rst new/pybeam-0.5/doc/modules.rst --- old/pybeam-0.4.1/doc/modules.rst 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/doc/modules.rst 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,7 @@ +pybeam +====== + +.. toctree:: + :maxdepth: 4 + + pybeam diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/doc/pybeam.rst new/pybeam-0.5/doc/pybeam.rst --- old/pybeam-0.4.1/doc/pybeam.rst 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/doc/pybeam.rst 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,29 @@ +pybeam package +============== + +Submodules +---------- + +pybeam.beam\_file module +------------------------ + +.. automodule:: pybeam.beam_file + :members: + :undoc-members: + :show-inheritance: + +pybeam.erlang\_types module +--------------------------- + +.. automodule:: pybeam.erlang_types + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: pybeam + :members: + :undoc-members: + :show-inheritance: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam/__init__.py new/pybeam-0.5/pybeam/__init__.py --- old/pybeam-0.4.1/pybeam/__init__.py 2018-03-19 12:22:19.000000000 +0100 +++ new/pybeam-0.5/pybeam/__init__.py 2018-12-28 09:40:23.000000000 +0100 @@ -1,5 +1,5 @@ # -# Copyright (c) 2013 Matwey V. Kornilov <[email protected]> +# Copyright (c) 2013-2018 Matwey V. Kornilov <[email protected]> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -7,7 +7,7 @@ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # @@ -23,4 +23,3 @@ from pybeam.beam_file import BeamFile __all__ = ["BeamFile"] - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam/beam_construct.py new/pybeam-0.5/pybeam/beam_construct.py --- old/pybeam-0.4.1/pybeam/beam_construct.py 2018-03-19 12:22:19.000000000 +0100 +++ new/pybeam-0.5/pybeam/beam_construct.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,98 +0,0 @@ -# -# Copyright (c) 2013 Matwey V. Kornilov <[email protected]> -# Copyright (c) 2013 Fredrik Ahlberg <[email protected]> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -from construct import * -from pybeam.eetf_construct import external_term - -chunk_atom = PrefixedArray(Int32ub, PascalString(lengthfield = Int8ub, encoding="latin1")) - -chunk_atu8 = PrefixedArray(Int32ub, PascalString(lengthfield = Int8ub, encoding="utf8")) - -chunk_attr = external_term - -chunk_cinf = external_term - -chunk_code = Struct("headerlen" / Int32ub, - "set" / Int32ub, - "opcode_max" / Int32ub, - "labels" / Int32ub, - "functions" / Int32ub, - Bytes(lambda ctx: ctx.headerlen-16), - Bytes(lambda ctx: ctx._.size-ctx.headerlen-4), - ) - -chunk_expt = Struct("entry" / PrefixedArray(Int32ub, Struct("function" / Int32ub, - "arity" / Int32ub, - "label" / Int32ub))) - -chunk_impt = Struct("entry" / PrefixedArray(Int32ub, Struct("module" / Int32ub, - "function" / Int32ub, - "arity" / Int32ub))) - -uncomp_chunk_litt = Struct("entry" / PrefixedArray(Int32ub, Prefixed(Int32ub, Struct("term" / external_term)))) -chunk_litt = Struct(Int32ub, - "data" / Prefixed(Computed(lambda ctx: ctx._.size-4), - Compressed(uncomp_chunk_litt, "zlib") - ) -) - -chunk_loct = PrefixedArray(Int32ub, Struct("function" / Int32ub, - "arity" / Int32ub, - "label" / Int32ub)) - -chunk = Struct( - "chunk_name" / String(4), - "size" / Int32ub, - "payload" / Switch(this.chunk_name, - { -# "Abst" : chunk_abst, - b"Atom" : chunk_atom, - b"AtU8" : chunk_atu8, - b"Attr" : chunk_attr, - b"CInf" : chunk_cinf, - b"Code" : chunk_code, - b"ExpT" : chunk_expt, -# "FunT" : chunk_funt, - b"ImpT" : chunk_impt, -# "Line" : chink_line, - b"LitT" : chunk_litt, - b"LocT" : chunk_loct, -# "StrT" : chunk_strt, -# "Trac" : chunk_trac, - }, - default = Bytes(lambda ctx: ctx.size) - ), -# Aligned(4, ..) - Padding(lambda ctx: (4 - ctx.size % 4) % 4, pattern = b'\00'), - ) - -beam = Struct( - "for1" / Const(b'FOR1'), - "size" / Int32ub, - "beam" / Const(b'BEAM'), - "chunk" / GreedyRange(chunk), - Terminated, - ) - -__all__ = ["beam"] - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam/beam_file.py new/pybeam-0.5/pybeam/beam_file.py --- old/pybeam-0.4.1/pybeam/beam_file.py 2018-03-19 12:22:19.000000000 +0100 +++ new/pybeam-0.5/pybeam/beam_file.py 2018-12-28 09:40:23.000000000 +0100 @@ -1,5 +1,5 @@ # -# Copyright (c) 2013 Matwey V. Kornilov <[email protected]> +# Copyright (c) 2013-2018 Matwey V. Kornilov <[email protected]> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -7,7 +7,7 @@ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # @@ -20,7 +20,7 @@ # THE SOFTWARE. # -from pybeam.beam_construct import beam +from pybeam.schema import beam class BeamFile(object): def __init__(self, f): @@ -29,7 +29,7 @@ self._tree = beam.parse(f.read()) def selectChunkByName(self, name): - for c in self._tree.chunk: + for c in self._tree.chunks: if c.chunk_name == name: return c raise KeyError(name) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam/eetf_construct.py new/pybeam-0.5/pybeam/eetf_construct.py --- old/pybeam-0.4.1/pybeam/eetf_construct.py 2018-03-19 12:22:19.000000000 +0100 +++ new/pybeam-0.5/pybeam/eetf_construct.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,221 +0,0 @@ -# -# Copyright (c) 2013 Matwey V. Kornilov <[email protected]> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -# External Term Format - -from pybeam.erlang_types import AtomCacheReference, Reference, Port, Pid, String as etString, Binary, Fun, MFA, BitBinary -from construct import * -import sys - -if sys.version > '3': - long = int - -class TupleAdapter(Adapter): - def _decode(self, obj, ctx): - # we got a list from construct and want to see a tuple - return tuple(obj) - def _encode(self, obj, ctx): - return list(obj) - -class ListAdapter(Adapter): - def _decode(self, obj, ctx): - if isinstance(obj[2], list) and obj[2] == []: - return obj[1] - obj[1].append(obj[2]) - return obj[1] - def _encode(self, obj, ctx): - return (len(obj), obj, []) - -class MapAdapter(Adapter): - def _decode(self, obj, ctx): - return dict(obj) - def _encode(self, obj, ctx): - return list(obj.items()) - -def BigInteger(length_field): - def decode_big(obj,ctx): - (length, isNegative, value) = obj - ret = sum([d << i*8 for (d,i) in zip(value,range(0,len(value)))]) - if isNegative: - return -ret - return ret - - def encode_big(obj,ctx): - isNegative = 0 - if obj < 0: - isNegative = 1 - obj = -obj - value = [] - while obj > 0: - value.append(obj & 0xFF) - obj = obj >> 8 - return (len(value), isNegative, value) - - return ExprAdapter(Sequence("len" / length_field, - "isNegative" / Int8ub, - "value" / Array(lambda ctx: ctx.len, Int8ub)), - encoder = encode_big, - decoder = decode_big) - -def tag(obj,ctx): - mapping = { - AtomCacheReference : 82, - int : 98, - float : 70, - str : 100, - Reference : 114, - Port : 102, - Pid : 103, - tuple : 105, - etString : 107, - list : 108, - Binary : 109, - long : 111, - Fun : 112, - MFA : 113, - map : 116, - BitBinary : 77, - } - if obj == []: - return 106 - else: - return mapping[obj.__class__] - -# Recurrent term -term_ = LazyBound(lambda ctx: term) - -atom_cache_ref = ExprAdapter(Int8ub, - encoder = lambda obj,ctx: obj.index, - decoder = lambda obj,ctx: AtomCacheReference(obj)) -small_integer = Int8ub -integer = Int32sb -float_ = ExprAdapter(String(31,padchar=b'\00',encoding="latin1"), - encoder = lambda obj,ctx: "%.20e " % obj, - decoder = lambda obj,ctx: float(obj.strip())) -atom = PascalString(lengthfield = Int16ub, encoding="latin1") -reference = ExprAdapter(Sequence("node" / term_, - "id" / Int32ub, - "creation" / Int8ub), - encoder = lambda obj,ctx: (obj.node, obj.id, obj.creation), - decoder = lambda obj,ctx: Reference(*obj)) -port = ExprAdapter(Sequence("node" / term_, - "id" / Int32ub, - "creation" / Int8ub), - encoder = lambda obj,ctx: (obj.node, obj.id, obj.creation), - decoder = lambda obj,ctx: Port(*obj)) -pid = ExprAdapter(Sequence("node" / term_, - "id" / Int32ub, - "serial" / Int32ub, - "creation" / Int8ub), - encoder = lambda obj,ctx: (obj.node, obj.id, obj.serial, obj.creation), - decoder = lambda obj,ctx: Pid(*obj)) -small_tuple = TupleAdapter(PrefixedArray(Int8ub, term_)) -large_tuple = TupleAdapter(PrefixedArray(Int32ub, term_)) -nil = ExprAdapter(Sequence(), - encoder = lambda obj,ctx: (), - decoder = lambda obj,ctx: []) -string = ExprAdapter(PascalString(lengthfield = Int16ub, encoding=None), - encoder = lambda obj,ctx: obj.value, - decoder = lambda obj,ctx: etString(obj)) -list_ = ListAdapter(Sequence("len" / Int32ub, - Array(this.len, term_), - term_)) -binary = ExprAdapter(PascalString(lengthfield = Int32ub), - encoder = lambda obj,ctx: obj.value, - decoder = lambda obj,ctx: Binary(obj)) -small_big = BigInteger(Int8ub) -large_big = BigInteger(Int32ub) -new_reference = ExprAdapter(Sequence("len" / Int16ub, - "node" / term_, - "creation" / Int8ub, - "id" / Array(this.len, Int32ub)), - encoder = lambda obj,ctx: (len(obj.id), obj.node, obj.creation, obj.id), - decoder = lambda obj,ctx: Reference(obj[1], obj[3], obj[2])) -small_atom = PascalString(lengthfield = Int8ub, encoding="latin1") -fun = ExprAdapter(Sequence("num_free" / Int32ub, - "pid" / term_, - "module" / term_, - "oldindex" / term_, - "olduniq" / term_, - "free" / Array(this.num_free, term_)), - encoder = lambda obj,ctx: (len(obj.free), obj.pid, obj.module, obj.oldindex, obj.olduniq, obj.free) , - decoder = lambda obj,ctx: Fun(None, None, None, obj[2], obj[3], obj[4], obj[1], obj[5])) -# new fun to be implemented later -new_fun = fun -export = ExprAdapter(Sequence("module" / LazyBound(lambda ctx: term), - "function" / LazyBound(lambda ctx: term), - "arity" / LazyBound(lambda ctx: term)), - encoder = lambda obj,ctx: (obj.module, obj.function, obj.arity), - decoder = lambda obj,ctx: MFA(*obj)) -bit_binary = ExprAdapter(Sequence("len" / Int32ub, - "bits" / Int8ub, - "data" / String(this.len)), - encoder = lambda obj,ctx: (len(obj.value), obj.bits, obj.value), - decoder = lambda obj,ctx: BitBinary(obj[2],obj[1])) -new_float = Float64b -atom_utf8 = PascalString(lengthfield = Int16ub, encoding="utf8") -small_atom_utf8 = PascalString(lengthfield = Int8ub, encoding="utf8") -key_value = ExprAdapter(Sequence(term_,term_), - encoder = lambda obj,ctx: obj, - decoder = lambda obj,ctx: tuple(obj)) -map_ = MapAdapter(PrefixedArray(Int32ub, key_value)) - -term = ExprAdapter(Sequence("tag" / Int8ub, - Switch(this.tag, { - 82: atom_cache_ref, - 97: small_integer, - 98: integer, - 99: float_, - 100: atom, - 101: reference, - 102: port, - 103: pid, - 104: small_tuple, - 105: large_tuple, - 106: nil, - 107: string, - 108: list_, - 109: binary, - 110: small_big, - 111: large_big, - 114: new_reference, - 115: small_atom, - 116: map_, - 117: fun, - 112: new_fun, - 113: export, - 77: bit_binary, - 70: new_float, - 118: atom_utf8, - 119: small_atom_utf8, - })), - lambda obj,ctx: (tag(obj, ctx), obj), - lambda obj,ctx: obj[1] - ) - -erl_version_magic = Const(b'\x83') - -external_term = ExprAdapter(Sequence(erl_version_magic, term), - encoder = lambda obj,ctx: (None, obj), - decoder = lambda obj,ctx: obj[1]) - -__all__ = ["term", "external_term"] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam/erlang_types.py new/pybeam-0.5/pybeam/erlang_types.py --- old/pybeam-0.4.1/pybeam/erlang_types.py 2018-03-19 12:22:19.000000000 +0100 +++ new/pybeam-0.5/pybeam/erlang_types.py 2018-12-28 09:40:23.000000000 +0100 @@ -1,5 +1,5 @@ # -# Copyright (c) 2013 Matwey V. Kornilov <[email protected]> +# Copyright (c) 2013-2018 Matwey V. Kornilov <[email protected]> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -7,7 +7,7 @@ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # @@ -103,4 +103,3 @@ self.bits = bits def __eq__(self, other): return self.value == other.value and self.bits == other.bits - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam/schema/__init__.py new/pybeam-0.5/pybeam/schema/__init__.py --- old/pybeam-0.4.1/pybeam/schema/__init__.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/pybeam/schema/__init__.py 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,26 @@ +# +# Copyright (c) 2013-2018 Matwey V. Kornilov <[email protected]> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +from pybeam.schema.beam import beam +from pybeam.schema.eetf import external_term + +__all__ = ["beam", "external_term"] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam/schema/beam/__init__.py new/pybeam-0.5/pybeam/schema/beam/__init__.py --- old/pybeam-0.4.1/pybeam/schema/beam/__init__.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/pybeam/schema/beam/__init__.py 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,39 @@ +# +# Copyright (c) 2013-2018 Matwey V. Kornilov <[email protected]> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +from construct import this +from construct import ( + Const, + FixedSized, + GreedyRange, + Int32ub, + Struct,) + +from pybeam.schema.beam.chunks import chunk + +beam = Struct( + "for1" / Const(b'FOR1'), + "size" / Int32ub, + "beam" / Const(b'BEAM'), + "chunks" / FixedSized(this.size-4, GreedyRange(chunk))) + +__all__ = ["beam"] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam/schema/beam/chunks.py new/pybeam-0.5/pybeam/schema/beam/chunks.py --- old/pybeam-0.4.1/pybeam/schema/beam/chunks.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/pybeam/schema/beam/chunks.py 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,99 @@ +# +# Copyright (c) 2013-2018 Matwey V. Kornilov <[email protected]> +# Copyright (c) 2013 Fredrik Ahlberg <[email protected]> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +from construct import this +from construct import ( + Aligned, + Bytes, + Compressed, + Computed, + FixedSized, + GreedyBytes, + Int32ub, + Int8ub, + PascalString, + Prefixed, + PrefixedArray, + Struct, + Switch,) + +from pybeam.schema.eetf import external_term + +Atom = PrefixedArray(Int32ub, PascalString(lengthfield=Int8ub, encoding="latin1")) + +AtU8 = PrefixedArray(Int32ub, PascalString(lengthfield=Int8ub, encoding="utf8")) + +Attr = external_term + +CInf = external_term + +Code = Struct("headerlen" / Int32ub, + "set" / Int32ub, + "opcode_max" / Int32ub, + "labels" / Int32ub, + "functions" / Int32ub, + Bytes(lambda ctx: ctx.headerlen-16), + Bytes(lambda ctx: ctx._.size-ctx.headerlen-4), + ) + +ExpT = Struct("entry" / PrefixedArray(Int32ub, Struct("function" / Int32ub, + "arity" / Int32ub, + "label" / Int32ub))) + +ImpT = Struct("entry" / PrefixedArray(Int32ub, Struct("module" / Int32ub, + "function" / Int32ub, + "arity" / Int32ub))) + +uncomp_chunk_litt = Struct("entry" / PrefixedArray(Int32ub, Prefixed(Int32ub, Struct("term" / external_term)))) +LitT = Struct(Int32ub, + "data" / Prefixed(Computed(lambda ctx: ctx._.size-4), + Compressed(uncomp_chunk_litt, "zlib") + ) +) + +LocT = PrefixedArray(Int32ub, Struct("function" / Int32ub, + "arity" / Int32ub, + "label" / Int32ub)) + +chunk = Struct( + "chunk_name" / Bytes(4), + "size" / Int32ub, + "payload" / Aligned(4, FixedSized(this.size, Switch(this.chunk_name, { +# "Abst" : chunk_abst, + b"Atom" : Atom, + b"AtU8" : AtU8, + b"Attr" : Attr, + b"CInf" : CInf, + b"Code" : Code, + b"ExpT" : ExpT, +# "FunT" : chunk_funt, + b"ImpT" : ImpT, +# "Line" : chink_line, + b"LitT" : LitT, + b"LocT" : LocT, +# "StrT" : chunk_strt, +# "Trac" : chunk_trac, + }, default=GreedyBytes))), + ) + +__all__ = ["chunk"] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam/schema/eetf.py new/pybeam-0.5/pybeam/schema/eetf.py --- old/pybeam-0.4.1/pybeam/schema/eetf.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/pybeam/schema/eetf.py 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,250 @@ +# +# Copyright (c) 2013-2018 Matwey V. Kornilov <[email protected]> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +import sys +from six import text_type + +from construct import this +from construct import ( + Adapter, + Array, + Bytes, + Const, + ExprAdapter, + Float64b, + GreedyBytes, + Int16ub, + Int32sb, + Int32ub, + Int8ub, + LazyBound, + PaddedString, + PascalString, + Prefixed, + PrefixedArray, + Sequence, + Switch, + ) + +from pybeam.erlang_types import ( + AtomCacheReference, + Binary, + BitBinary, + Fun, + MFA, + Pid, + Port, + Reference, + String as etString,) + +if sys.version > '3': + long = int + +class TupleAdapter(Adapter): + def _decode(self, obj, context, path): + # we got a list from construct and want to see a tuple + return tuple(obj) + def _encode(self, obj, context, path): + return list(obj) + +class ListAdapter(Adapter): + def _decode(self, obj, context, path): + if isinstance(obj[2], list) and obj[2] == []: + return obj[1] + obj[1].append(obj[2]) + return obj[1] + def _encode(self, obj, context, path): + return (len(obj), obj, []) + +class MapAdapter(Adapter): + def _decode(self, obj, context, path): + return dict(obj) + def _encode(self, obj, context, path): + return list(obj.items()) + +def BigInteger(length_field): + def decode_big(obj, _ctx): + (_length, isNegative, value) = obj + ret = sum([d << i*8 for (d, i) in zip(value, range(0, len(value)))]) + if isNegative: + return -ret + return ret + + def encode_big(obj, _ctx): + isNegative = 0 + if obj < 0: + isNegative = 1 + obj = -obj + value = [] + while obj > 0: + value.append(obj & 0xFF) + obj = obj >> 8 + return (len(value), isNegative, value) + + return ExprAdapter(Sequence("len" / length_field, + "isNegative" / Int8ub, + "value" / Array(lambda ctx: ctx.len, Int8ub)), + encoder=encode_big, + decoder=decode_big) + +def tag(obj): + mapping = { + AtomCacheReference : 82, + int : 98, + float : 70, + text_type : 118, # unicode in Python 2 and str in Python 3 + Reference : 114, + Port : 102, + Pid : 103, + tuple : 105, + etString : 107, + list : 108, + Binary : 109, + long : 111, + Fun : 112, + MFA : 113, + map : 116, + BitBinary : 77, + } + if obj == []: + return 106 + return mapping[obj.__class__] + +# Recurrent term +term_ = LazyBound(lambda: term) + +atom_cache_ref = ExprAdapter(Int8ub, + encoder=lambda obj, ctx: obj.index, + decoder=lambda obj, ctx: AtomCacheReference(obj)) +small_integer = Int8ub +integer = Int32sb +float_ = ExprAdapter(PaddedString(31, encoding="ascii"), + encoder=lambda obj, ctx: u"{:.20e} ".format(obj), + decoder=lambda obj, ctx: float(obj)) +atom = PascalString(lengthfield=Int16ub, encoding="latin1") +reference = ExprAdapter(Sequence("node" / term_, + "id" / Int32ub, + "creation" / Int8ub), + encoder=lambda obj, ctx: (obj.node, obj.id, obj.creation), + decoder=lambda obj, ctx: Reference(*obj)) +port = ExprAdapter(Sequence("node" / term_, + "id" / Int32ub, + "creation" / Int8ub), + encoder=lambda obj, ctx: (obj.node, obj.id, obj.creation), + decoder=lambda obj, ctx: Port(*obj)) +pid = ExprAdapter(Sequence("node" / term_, + "id" / Int32ub, + "serial" / Int32ub, + "creation" / Int8ub), + encoder=lambda obj, ctx: (obj.node, obj.id, obj.serial, obj.creation), + decoder=lambda obj, ctx: Pid(*obj)) +small_tuple = TupleAdapter(PrefixedArray(Int8ub, term_)) +large_tuple = TupleAdapter(PrefixedArray(Int32ub, term_)) +nil = ExprAdapter(Sequence(), + encoder=lambda obj, ctx: (), + decoder=lambda obj, ctx: []) +string = ExprAdapter(Prefixed(Int16ub, GreedyBytes), + encoder=lambda obj, ctx: obj.value, + decoder=lambda obj, ctx: etString(obj)) +list_ = ListAdapter(Sequence("len" / Int32ub, + Array(this.len, term_), + term_)) +binary = ExprAdapter(Prefixed(Int32ub, GreedyBytes), + encoder=lambda obj, ctx: obj.value, + decoder=lambda obj, ctx: Binary(obj)) +small_big = BigInteger(Int8ub) +large_big = BigInteger(Int32ub) +new_reference = ExprAdapter(Sequence("len" / Int16ub, + "node" / term_, + "creation" / Int8ub, + "id" / Array(this.len, Int32ub)), + encoder=lambda obj, ctx: (len(obj.id), obj.node, obj.creation, obj.id), + decoder=lambda obj, ctx: Reference(obj[1], obj[3], obj[2])) +small_atom = PascalString(lengthfield=Int8ub, encoding="latin1") +fun = ExprAdapter(Sequence("num_free" / Int32ub, + "pid" / term_, + "module" / term_, + "oldindex" / term_, + "olduniq" / term_, + "free" / Array(this.num_free, term_)), + encoder=lambda obj, ctx: (len(obj.free), obj.pid, obj.module, obj.oldindex, obj.olduniq, obj.free), + decoder=lambda obj, ctx: Fun(None, None, None, obj[2], obj[3], obj[4], obj[1], obj[5])) +# new fun to be implemented later +new_fun = fun +export = ExprAdapter(Sequence("module" / LazyBound(lambda: term), + "function" / LazyBound(lambda: term), + "arity" / LazyBound(lambda: term)), + encoder=lambda obj, ctx: (obj.module, obj.function, obj.arity), + decoder=lambda obj, ctx: MFA(*obj)) +bit_binary = ExprAdapter(Sequence("len" / Int32ub, + "bits" / Int8ub, + "data" / Bytes(this.len)), + encoder=lambda obj, ctx: (len(obj.value), obj.bits, obj.value), + decoder=lambda obj, ctx: BitBinary(obj[2], obj[1])) +new_float = Float64b +atom_utf8 = PascalString(lengthfield=Int16ub, encoding="utf8") +small_atom_utf8 = PascalString(lengthfield=Int8ub, encoding="utf8") +key_value = ExprAdapter(Sequence(term_, term_), + encoder=lambda obj, ctx: obj, + decoder=lambda obj, ctx: tuple(obj)) +map_ = MapAdapter(PrefixedArray(Int32ub, key_value)) + +term = ExprAdapter(Sequence("tag" / Int8ub, + Switch(this.tag, { + 82: atom_cache_ref, + 97: small_integer, + 98: integer, + 99: float_, + 100: atom, + 101: reference, + 102: port, + 103: pid, + 104: small_tuple, + 105: large_tuple, + 106: nil, + 107: string, + 108: list_, + 109: binary, + 110: small_big, + 111: large_big, + 114: new_reference, + 115: small_atom, + 116: map_, + 117: fun, + 112: new_fun, + 113: export, + 77: bit_binary, + 70: new_float, + 118: atom_utf8, + 119: small_atom_utf8, + })), + encoder=lambda obj, ctx: (tag(obj), obj), + decoder=lambda obj, ctx: obj[1], + ) + +erl_version_magic = Const(b'\x83') + +external_term = ExprAdapter(Sequence(erl_version_magic, term), + encoder=lambda obj, ctx: (None, obj), + decoder=lambda obj, ctx: obj[1]) + +__all__ = ["term", "external_term"] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam.egg-info/PKG-INFO new/pybeam-0.5/pybeam.egg-info/PKG-INFO --- old/pybeam-0.4.1/pybeam.egg-info/PKG-INFO 2018-03-19 12:22:35.000000000 +0100 +++ new/pybeam-0.5/pybeam.egg-info/PKG-INFO 2018-12-28 09:40:48.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: pybeam -Version: 0.4.1 +Version: 0.5 Summary: Python module to parse Erlang BEAM files Home-page: http://github.com/matwey/pybeam Author: Matwey V. Kornilov diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam.egg-info/SOURCES.txt new/pybeam-0.5/pybeam.egg-info/SOURCES.txt --- old/pybeam-0.4.1/pybeam.egg-info/SOURCES.txt 2018-03-19 12:22:35.000000000 +0100 +++ new/pybeam-0.5/pybeam.egg-info/SOURCES.txt 2018-12-28 09:40:48.000000000 +0100 @@ -1,13 +1,26 @@ +LICENSE +MANIFEST.in README.md +requirements.txt setup.py +doc/conf.py +doc/index.rst +doc/modules.rst +doc/pybeam.rst pybeam/__init__.py -pybeam/beam_construct.py pybeam/beam_file.py -pybeam/eetf_construct.py pybeam/erlang_types.py pybeam.egg-info/PKG-INFO pybeam.egg-info/SOURCES.txt pybeam.egg-info/dependency_links.txt pybeam.egg-info/not-zip-safe pybeam.egg-info/requires.txt -pybeam.egg-info/top_level.txt \ No newline at end of file +pybeam.egg-info/top_level.txt +pybeam/schema/__init__.py +pybeam/schema/eetf.py +pybeam/schema/beam/__init__.py +pybeam/schema/beam/chunks.py +test/__init__.py +test/beam_file.py +test/schema_beam.py +test/schema_eetf.py \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/pybeam.egg-info/requires.txt new/pybeam-0.5/pybeam.egg-info/requires.txt --- old/pybeam-0.4.1/pybeam.egg-info/requires.txt 2018-03-19 12:22:35.000000000 +0100 +++ new/pybeam-0.5/pybeam.egg-info/requires.txt 2018-12-28 09:40:48.000000000 +0100 @@ -1,2 +1,3 @@ -construct<2.9,>=2.8 +construct<2.10,>=2.9 six +sphinx diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/requirements.txt new/pybeam-0.5/requirements.txt --- old/pybeam-0.4.1/requirements.txt 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/requirements.txt 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,3 @@ +construct>=2.9,<2.10 +six +sphinx diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/setup.py new/pybeam-0.5/setup.py --- old/pybeam-0.4.1/setup.py 2018-03-19 12:22:19.000000000 +0100 +++ new/pybeam-0.5/setup.py 2018-12-28 09:40:23.000000000 +0100 @@ -1,13 +1,27 @@ -from setuptools import setup +from setuptools import find_packages, setup +from sphinx.setup_command import BuildDoc +cmdclass = {'build_sphinx': BuildDoc} -setup(name='pybeam', - version='0.4.1', - description='Python module to parse Erlang BEAM files', - url='http://github.com/matwey/pybeam', - author='Matwey V. Kornilov', - author_email='[email protected]', - license='MIT', - packages=['pybeam'], - test_suite = 'test', - install_requires=['construct>=2.8,<2.9', 'six'], - zip_safe=False) +name="pybeam" +version="0.5" +test_suite="test" + +setup(name=name, + version=version, + description='Python module to parse Erlang BEAM files', + url='http://github.com/matwey/pybeam', + author='Matwey V. Kornilov', + author_email='[email protected]', + license='MIT', + packages=find_packages(exclude=(test_suite,)), + test_suite=test_suite, + install_requires=['construct>=2.9,<2.10', 'six', 'sphinx'], + command_options={ + 'build_sphinx': { + 'project': ('setup.py', name), + 'version': ('setup.py', version), + 'release': ('setup.py', version), + 'source_dir': ('setup.py', 'doc') + } + }, + zip_safe=False) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/test/__init__.py new/pybeam-0.5/test/__init__.py --- old/pybeam-0.4.1/test/__init__.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/test/__init__.py 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,4 @@ +from test.schema_beam import BEAMConstructTest +from test.schema_eetf import EETFConstructTest +from test.beam_file import BEAMFileTest +import unittest diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/test/beam_file.py new/pybeam-0.5/test/beam_file.py --- old/pybeam-0.4.1/test/beam_file.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/test/beam_file.py 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,53 @@ +# +# Copyright (c) 2016 Matwey V. Kornilov <[email protected]> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +from pybeam import beam_file +from pybeam.erlang_types import String +import unittest +import io + +class BEAMFileTest(unittest.TestCase): + def setUp(self): + self.raw = b'FOR1\x00\x00\x02\xb4BEAMAtom\x00\x00\x00U\x00\x00\x00\x08\x08ssh_math\x04ipow\x06crypto\x07mod_pow\x10bytes_to_integer\x0bmodule_info\x06erlang\x0fget_module_info\x00\x00\x00Code\x00\x00\x00\\\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x99\x00\x00\x00\x07\x00\x00\x00\x03\x01\x10\x99\x10\x02\x12"0\x01 \'\x15\x01#(\x15\x13\x01\x0c\x000\x99 \x070\x00\x99 \x08\x10\x10\x00\x010\x99\x00\x02\x12b\x00\x01@@\x12\x03\x99\x00N\x10 \x01P\x99\x00\x02\x12b\x10\x01`@\x03\x13@\x12\x03\x99\x00N 0\x03StrT\x00\x00\x00\x00ImpT\x00\x00\x004\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x02ExpT\x00\x00\x00(\x00\x00\x00\x03\x00\x00\x00\x06\x00\x00\x00\x01\x00\x00\x00\x06\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x02Attr\x00\x00\x00(\x83l\x00\x00\x00\x01h\x02d\x00\x03vsnl\x00\x00\x00\x01n\x10\x00\x8f\xde\xf9V}\xf3wr\x8a\x93\xc1p\xedDK\x9ajjCInf\x00\x00\x01@\x83l\x00\x00\x00\x04h\x02d\x00\x07optionsl\x00\x00\x00\x04h\x02d\x00\x06outdirk\x00</home/abuild/rpmbuild/BUILD/otp_src_17.1/lib/ssh/src/../ebinh\x02d\x00\x01ik\x007/home/abuild/rpmbuild/BUILD/otp_src_17.1/lib/kernel/srcd\x00\x10warn_unused_varsd\x00\ndebug_infojh\x02d\x00\x07versionk\x00\x055.0.1h\x02d\x00\x04timeh\x06b\x00\x00\x07\xe0a\x02a\x0fa\x0ba\x08a\x12h\x02d\x00\x06sourcek\x00A/home/abuild/rpmbuild/BUILD/otp_src_17.1/lib/ssh/src/ssh_math.erlj' + self.io = io.BytesIO(self.raw) + self.beam = beam_file.BeamFile(self.io) + def test_attr(self): + self.assertDictEqual({'vsn': [205091931631091061218511176690734587535]}, self.beam.attributes) + def test_atoms(self): + self.assertListEqual(['ssh_math','ipow','crypto','mod_pow','bytes_to_integer','module_info','erlang','get_module_info'], self.beam.atoms) + def test_compileinfo(self): + self.assertDictEqual({ + 'source': String(b'/home/abuild/rpmbuild/BUILD/otp_src_17.1/lib/ssh/src/ssh_math.erl'), + 'time': (2016, 2, 15, 11, 8, 18), + 'version': String(b'5.0.1'), + 'options': [ + ('outdir', String(b'/home/abuild/rpmbuild/BUILD/otp_src_17.1/lib/ssh/src/../ebin')), + ('i', String(b'/home/abuild/rpmbuild/BUILD/otp_src_17.1/lib/kernel/src')), + 'warn_unused_vars', + 'debug_info' + ]}, self.beam.compileinfo) + def test_exports(self): + self.assertListEqual([('module_info', 1, 6), ('module_info', 0, 4), ('ipow', 3, 2)], self.beam.exports) + def test_imports(self): + self.assertListEqual([('crypto', 'mod_pow', 3), ('crypto', 'bytes_to_integer', 1), ('erlang', 'get_module_info', 1), ('erlang', 'get_module_info', 2)], self.beam.imports) + def test_modulename(self): + self.assertEqual('ssh_math', self.beam.modulename) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/test/schema_beam.py new/pybeam-0.5/test/schema_beam.py --- old/pybeam-0.4.1/test/schema_beam.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/test/schema_beam.py 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,71 @@ +# +# Copyright (c) 2013 Matwey V. Kornilov <[email protected]> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +from pybeam.schema import beam +from pybeam.schema.beam.chunks import Atom, AtU8, Attr, CInf, chunk +from construct import Container, StreamError +import unittest + +class BEAMConstructTest(unittest.TestCase): + def setUp(self): + pass + def test_beam1(self): + c = beam + self.assertEqual(c.parse(b'FOR1\x00\x00\x00\x04BEAM'), Container(for1=b"FOR1", beam=b"BEAM", chunks=[], size=4)) + def test_beam2(self): + c = beam + raw = b'FOR1\x00\x00\x02TBEAMAtU8\x00\x00\x002\x00\x00\x00\x07\x01m\x04fact\x06erlang\x01-\x01*\x0bmodule_info\x0fget_module_info\x00\x00Code\x00\x00\x00w\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x99\x00\x00\x00\x08\x00\x00\x00\x03\x01\x10\x99\x10\x02\x12"\x10\x01 \'5\x01\x03\x0e\x10\x10\x99\x10}\x05\x10\x00\x03\x11\x13@\x03\x04@\x13\x03\x99\x10\x04\x10%\x99\x10}\x05\x10\x10\x04\x03\x03\x12\x10\x13\x010+\x15\x03\x01@\x11\x03\x13\x01@\x99\x00\x02\x12b\x00\x01P@\x12\x03\x99\x00N\x10 \x01`\x99\x00\x02\x12b\x10\x01p@\x03\x13@\x12\x03\x99\x00N 0\x03\x00StrT\x00\x00\x00\x00ImpT\x00\x00\x004\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x05\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x07\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\x07\x00\x00\x00\x02ExpT\x00\x00\x00(\x00\x00\x00\x03\x00\x00\x00\x06\x00\x00\x00\x01\x00\x00\x00\x07\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02LocT\x00\x00\x00\x04\x00\x00\x00\x00Attr\x00\x00\x00(\x83l\x00\x00\x00\x01h\x02d\x00\x03vsnl\x00\x00\x00\x01n\x10\x007\xfc\x18\xc42\x03\xc0\xfa\xe0\x91w.a\xb8\xebqjjCInf\x00\x00\x00l\x83l\x00\x00\x00\x03h\x02d\x00\x07optionsl\x00\x00\x00\x01d\x00\rno_debug_infojh\x02d\x00\x07versionk\x00\x057.1.5h\x02d\x00\x06sourcek\x00!/home/matwey/rpmbuild/BUILD/m.erljDbgi\x00\x00\x00F\x83h\x03d\x00\rdebug_info_v1d\x00\x11erl_abstract_codeh\x02d\x00\x04nonel\x00\x00\x00\x01d\x00\rno_debug_infoj\x00\x00Line\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00A\x00\x00\x00' + parsed = c.parse(raw) + self.assertEqual(len(raw), 604) + self.assertEqual(parsed.for1, b'FOR1') + self.assertEqual(parsed.size, 596) + self.assertEqual(parsed.beam, b'BEAM') + def test_chunk_atom(self): + c = Atom + self.assertEqual(c.parse(b'\x00\x00\x00\x00'), []) + self.assertEqual(c.parse(b'\x00\x00\x00\x01\x08burtovoy'),[u"burtovoy"]) + self.assertEqual(c.parse(b'\x00\x00\x00\x02\x08burtovoy\x08yegorsaf'), [u"burtovoy",u"yegorsaf"]) + self.assertEqual(c.parse(c.build([])), []) + self.assertEqual(c.parse(c.build([u"burtovoy"])), [u"burtovoy"]) + self.assertEqual(c.parse(c.build([u"burtovoy",u"yegorsaf"])), [u"burtovoy",u"yegorsaf"]) + self.assertRaises(StreamError, c.parse, b'\x00\x00\xff\x00') + def test_chunk_atu8(self): + c = AtU8 + self.assertEqual(c.parse(b'\x00\x00\x00\x00'), []) + self.assertEqual(c.parse(b'\x00\x00\x00\x01\x08burtovoy'),[u"burtovoy"]) + self.assertEqual(c.parse(b'\x00\x00\x00\x01\x10\xd0\x91\xd1\x83\xd1\x80\xd1\x82\xd0\xbe\xd0\xb2\xd0\xbe\xd0\xb9'),[u"\u0411\u0443\u0440\u0442\u043e\u0432\u043e\u0439"]) + def test_chunk_attr(self): + c = Attr + self.assertEqual(c.parse(b'\x83\x64\x00\x08burtovoy'), u"burtovoy") + self.assertEqual(c.parse(c.build(u"burtovoy")), u"burtovoy") + self.assertEqual(c.parse(b'\x83\x6a'), []) + def test_chunk_cinf(self): + c = CInf + self.assertEqual(c.parse(b'\x83\x64\x00\x08burtovoy'), u"burtovoy") + self.assertEqual(c.parse(c.build(u"burtovoy")), u"burtovoy") + self.assertEqual(c.parse(b'\x83\x6a'), []) + def test_chunk_litt(self): + c = chunk + littc = b'x\x9cc```d```j\xce\x02\x00\x01\x87\x00\xf1' + litt = b'LitT\x00\x00\x00\x16\x00\x00\x00\x0a' + littc + b'\x00\x00' + self.assertEqual(c.parse(litt).payload.data.entry[0].term, []) + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pybeam-0.4.1/test/schema_eetf.py new/pybeam-0.5/test/schema_eetf.py --- old/pybeam-0.4.1/test/schema_eetf.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pybeam-0.5/test/schema_eetf.py 2018-12-28 09:40:23.000000000 +0100 @@ -0,0 +1,169 @@ +# Copyright (c) 2013 Matwey V. Kornilov <[email protected]> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +import pybeam.schema.eetf as eetf +from pybeam import erlang_types +from six import int2byte +import unittest + +class EETFConstructTest(unittest.TestCase): + def setUp(self): + pass + def test_atom_cache_ref(self): + c = eetf.atom_cache_ref + self.assertEqual(c.parse(b'\x23'), erlang_types.AtomCacheReference(0x23)) + self.assertEqual(c.parse(c.build(erlang_types.AtomCacheReference(0x23))),erlang_types.AtomCacheReference(0x23)) + def test_small_integer(self): + c = eetf.small_integer + self.assertEqual(c.parse(b'\x23'), 0x23) + self.assertEqual(c.parse(c.build(123)),123) + def test_integer(self): + c = eetf.integer + self.assertEqual(c.parse(b'\00\xff\00\x11'), 0xff0011) + self.assertEqual(c.parse(b'\xff\xff\xff\xff'), -1) + self.assertEqual(c.parse(c.build(0xff0011)),0xff0011) + def test_float(self): + c = eetf.float_ + self.assertEqual(c.parse(b' 1.12344300000000002910e+04'), 11234.43) + self.assertEqual(c.parse(b'1.00000000000000000000e+00\00\00\00\00\00'), 1.0) + self.assertEqual(c.parse(c.build(-3.1415926)),-3.1415926) + def test_new_float(self): + c = eetf.new_float + self.assertEqual(c.parse(b'\x40\x00\x00\x00\x00\x00\x00\x00'), 2.0 ) + self.assertEqual(c.parse(b'\xc0\x00\x00\x00\x00\x00\x00\x00'), -2.0 ) + self.assertEqual(c.parse(c.build(-3.1415926)),-3.1415926) + def test_atom_utf8(self): + c = eetf.atom_utf8 + self.assertEqual(c.parse(b'\x00\x08\xd0\xb0\xd1\x82\xd0\xbe\xd0\xbc'), u"\u0430\u0442\u043e\u043c") + self.assertEqual(c.parse(c.build(u"\u0430\u0442\u043e\u043c")),u"\u0430\u0442\u043e\u043c") + def test_small_atom_utf8(self): + c = eetf.small_atom_utf8 + self.assertEqual(c.parse(b'\x08\xd0\xb0\xd1\x82\xd0\xbe\xd0\xbc'), u"\u0430\u0442\u043e\u043c") + self.assertEqual(c.parse(c.build(u"\u0430\u0442\u043e\u043c")),u"\u0430\u0442\u043e\u043c") + def test_atom1(self): + c = eetf.atom + self.assertEqual(c.parse(b'\x00\x06myatom'), u"myatom") + self.assertEqual(c.parse(c.build(u"robots")),u"robots") + def test_atom2(self): + raw = b'\x00\x06r\xf2b\xf3ts' + c = eetf.atom + self.assertEqual(c.parse(raw), u"r\u00f2b\u00f3ts") + def test_small_atom1(self): + c = eetf.small_atom + self.assertEqual(c.parse(b'\x06myatom'), u"myatom") + self.assertEqual(c.parse(c.build(u"robots")),u"robots") + def test_small_atom2(self): + raw = b'\x06r\xf2b\xf3ts' + c = eetf.small_atom + self.assertEqual(c.parse(raw), u"r\u00f2b\u00f3ts") + def test_reference(self): + c = eetf.reference + r = erlang_types.Reference(u"myatom",0x12,0x48) + self.assertEqual(c.parse(b'\x64\x00\x06myatom\x00\x00\x00\x12\x48'), r) + self.assertEqual(c.parse(c.build(r)),r) + self.assertEqual(c.build(r),b'\x76\x00\x06myatom\x00\x00\x00\x12\x48') + def test_new_reference(self): + c = eetf.new_reference + r = erlang_types.Reference(u"myatom",[0x12,0x13],0x48) + self.assertEqual(c.parse(b'\x00\x02\x76\x00\x06myatom\x48\x00\x00\x00\x12\x00\x00\x00\x13'), r) + self.assertEqual(c.parse(c.build(r)),r) + def test_port(self): + c = eetf.port + self.assertEqual(c.parse(b'\x64\x00\x06myatom\x00\x00\x00\x12\x48'), erlang_types.Port("myatom",0x12,0x48)) + def test_pid(self): + c = eetf.pid + self.assertEqual(c.parse(b'\x64\x00\x06myatom\x00\x00\x00\x12\x00\x00\x00\x32\x48'), erlang_types.Pid("myatom",0x12,0x32,0x48)) + def test_small_tuple(self): + c = eetf.small_tuple + self.assertEqual(c.parse(b"\x02\x64\x00\x06myatom\x64\x00\x06robert"), ("myatom","robert")) + self.assertEqual(c.parse(c.build((1,2,u"myatom"))),(1,2,u"myatom")) + def test_large_tuple(self): + c = eetf.large_tuple + self.assertEqual(c.parse(b"\x00\x00\x00\x02\x64\x00\x06myatom\x64\x00\x06robert"), ("myatom","robert")) + self.assertEqual(c.parse(c.build((1,2,u"myatom"))),(1,2,u"myatom")) + def test_list(self): + c = eetf.list_ + self.assertEqual(c.parse(b'\x00\x00\x00\x02\x64\x00\x08YegorSaf\x64\x00\x0aRoBurToVoY\x6a'), ["YegorSaf","RoBurToVoY"]) + self.assertEqual(c.parse(c.build([1,2,3,u"OO"])),[1,2,3,u"OO"]) + self.assertEqual(c.parse(c.build([u"Nu",u"poskoku"])),[u"Nu",u"poskoku"]) + attrs0 = b'\x00\x00\x00\x02h\x02d\x00\x03vsnl\x00\x00\x00\x01n\x10\x00\xb3\xf2\xab&|\xd3\xdeHL\xa0\x0fV\xdf\xc1\x05\x96jh\x02d\x00\tbehaviourl\x00\x00\x00\x01d\x00\ngen_serverjj' + self.assertEqual(c.parse(attrs0), [("vsn", [199414093051598402244823387542347575987]), ("behaviour", ["gen_server"])]) + t1 = b'\x00\x00\x00\x01d\x00\x05alignm\x00\x00\x00\x02\x01\x00' + self.assertEqual(c.parse(t1), ["align", erlang_types.Binary(b'\x01\x00')]) + def test_nil(self): + c = eetf.nil + self.assertEqual(c.parse(b'\x6a'), []) + self.assertEqual(c.parse(c.build([])),[]) + def test_bitbinary(self): + c = eetf.bit_binary + self.assertEqual(c.parse(b'\00\00\00\x0a\x03RoBurToVoY'), erlang_types.BitBinary(b'RoBurToVoY',3)) + s = erlang_types.BitBinary(b'RoBurToVoY',1) + self.assertEqual(c.parse(c.build(s)),s) + def test_string(self): + c = eetf.string + self.assertEqual(c.parse(b'\x00\x0aRoBurToVoY'), erlang_types.String(b'RoBurToVoY')) + s = erlang_types.String(b'RoBurToVoY') + self.assertEqual(c.parse(c.build(s)),s) + n = b"\x01\x00" + b"".join(map(int2byte, range(0,256))) + self.assertListEqual(list(c.parse(n)), list(range(0,256))) + self.assertEqual(c.build(erlang_types.String(b"".join(map(int2byte, range(0,256))))), n) + def test_binary(self): + c = eetf.binary + self.assertEqual(c.parse(b'\x00\x00\x00\x0aRoBurToVoY'), erlang_types.Binary(b'RoBurToVoY')) + s = erlang_types.Binary(b'RoBurToVoY') + self.assertEqual(c.parse(c.build(s)),s) + def test_small_big(self): + c = eetf.small_big + self.assertEqual(c.parse(b'\x02\x00\x02\x01'), 258) + self.assertEqual(c.parse(b'\x02\x01\x02\x01'), -258) + self.assertEqual(c.parse(c.build(123456789123456789)),123456789123456789) + def test_large_big(self): + c = eetf.large_big + self.assertEqual(c.parse(b'\x00\x00\x00\x02\x00\x02\x01'), 258) + self.assertEqual(c.parse(c.build(123456789123456789)),123456789123456789) + def test_fun(self): + c = eetf.fun + self.assertEqual(c.parse(b'\00\00\00\x02\x64\x00\x06myatom\x64\x00\x06myatom\x61\x13\x64\x00\x06myatom\x64\x00\x06myatom\x64\x00\x06myatom'), erlang_types.Fun(None,None,None,"myatom",0x13,"myatom","myatom",["myatom","myatom"])) + def test_export(self): + c = eetf.export + mfa = erlang_types.MFA(u"myatom",u"myat0m",0x13) + self.assertEqual(c.parse(b'\x64\x00\x06myatom\x64\x00\x06myat0m\x61\x13'),mfa) + self.assertEqual(c.parse(c.build(mfa)),mfa) + def test_term(self): + c = eetf.term + self.assertEqual(c.parse(b'\x6f\x00\x00\x00\x02\x00\x02\x01'), 258) + self.assertEqual(c.parse(c.build(258)), 258) + self.assertEqual(c.parse(c.build([3,2,1])), [3,2,1]) + self.assertEqual(c.build(u"BurToVoY"), b'\x76\x00\x08BurToVoY') + def test_external(self): + c = eetf.external_term + self.assertEqual(c.parse(b'\x83\x6f\x00\x00\x00\x02\x00\x02\x01'), 258) + self.assertEqual(c.parse(c.build(258)), 258) + self.assertEqual(c.parse(c.build([3,2,1])), [3,2,1]) + self.assertEqual(c.build(u"BurToVoY"), b'\x83\x76\x00\x08BurToVoY') + def test_key_value(self): + c = eetf.key_value + self.assertEqual(c.parse(b'a\x01a\x02'), (1,2)) + self.assertEqual(c.parse(c.build((1,2))), (1,2)) + def test_map(self): + c = eetf.map_ + self.assertEqual(c.parse(b'\x00\x00\x00\x02a\x01a\x02a\x03a\x04'), {1:2,3:4}) + self.assertEqual(c.parse(c.build({1:2,3:4})), {1:2,3:4})
