diff options
| -rw-r--r-- | MANIFEST.in | 2 | ||||
| -rw-r--r-- | PKG-INFO | 49 | ||||
| -rw-r--r-- | README.rst (renamed from README.md) | 42 | ||||
| -rw-r--r-- | debian/changelog | 17 | ||||
| -rw-r--r-- | debian/control | 37 | ||||
| -rw-r--r-- | debian/copyright | 2 | ||||
| -rw-r--r-- | debian/gbp.conf | 3 | ||||
| -rw-r--r-- | debian/watch | 3 | ||||
| -rw-r--r-- | kaitaistruct.egg-info/PKG-INFO | 49 | ||||
| -rw-r--r-- | kaitaistruct.egg-info/SOURCES.txt | 2 | ||||
| -rw-r--r-- | kaitaistruct.py | 76 | ||||
| -rw-r--r-- | setup.cfg | 1 | ||||
| -rwxr-xr-x | setup.py | 8 |
13 files changed, 157 insertions, 134 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index bb3ec5f..9561fb1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include README.md +include README.rst @@ -1,60 +1,63 @@ Metadata-Version: 1.1 Name: kaitaistruct -Version: 0.7 +Version: 0.8 Summary: Kaitai Struct declarative parser generator for binary data: runtime library for Python Home-page: http://kaitai.io Author: Kaitai Project Author-email: greycat@kaitai.io License: MIT -Description: # Kaitai Struct: runtime library for Python +Description-Content-Type: UNKNOWN +Description: Kaitai Struct: runtime library for Python + =========================================== This library implements Kaitai Struct API for Python. - [Kaitai Struct](http://kaitai.io) is a declarative language used for + `Kaitai Struct <http://kaitai.io>`_ is a declarative language used for describe various binary data structures, laid out in files or in memory: i.e. binary file formats, network stream packet formats, etc. - It is similar to Python's [construct] and [Construct3], but it is + It is similar to `Python's Construct 2.9 <http://construct.readthedocs.org/>`_ but it is language-agnostic. The format description is done in YAML-based .ksy format, which then can be compiled into a wide range of target languages. - [construct]: https://pypi.python.org/pypi/construct - [Construct3]: http://tomerfiliba.com/blog/Survey-of-Construct3/ - Further reading: - * [About Kaitai Struct](http://kaitai.io/) - * [About API implemented in this library](http://doc.kaitai.io/stream_api.html) - * [Python-specific notes](http://doc.kaitai.io/lang_python.html) + * `About Kaitai Struct <http://kaitai.io/>`_ + * `About API implemented in this library <http://doc.kaitai.io/stream_api.html>`_ + * `Python specific notes <http://doc.kaitai.io/lang_python.html>`_ - ## Installing + Installing + ------------------------------ - ### Using `requirements.txt` + Using `requirements.txt` + ------------------------------ If you want to use Kaitai Struct runtime in your project and you use `requirements.txt` to manage your dependencies, just add the following line to it: - ``` - kaitaistruct - ``` + :: + + kaitaistruct and then run `pip install -r requirements.txt` to update all your dependencies. - ### Using `pip` directly + Using `pip` directly + ------------------------------ You can use - ```shell - pip install kaitaistruct - ``` + :: + + pip install kaitaistruct to install the package manually using `pip` Python package manager. - ## Licensing + Licensing + ------------------------------ - Copyright 2015-2017 Kaitai Project: MIT license + Copyright 2015-2018 Kaitai Project: MIT license Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -87,3 +90,7 @@ Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: Implementation :: CPython +Classifier: Programming Language :: Python :: Implementation :: PyPy @@ -1,52 +1,54 @@ -# Kaitai Struct: runtime library for Python +Kaitai Struct: runtime library for Python +=========================================== This library implements Kaitai Struct API for Python. -[Kaitai Struct](http://kaitai.io) is a declarative language used for +`Kaitai Struct <http://kaitai.io>`_ is a declarative language used for describe various binary data structures, laid out in files or in memory: i.e. binary file formats, network stream packet formats, etc. -It is similar to Python's [construct] and [Construct3], but it is +It is similar to `Python's Construct 2.9 <http://construct.readthedocs.org/>`_ but it is language-agnostic. The format description is done in YAML-based .ksy format, which then can be compiled into a wide range of target languages. -[construct]: https://pypi.python.org/pypi/construct -[Construct3]: http://tomerfiliba.com/blog/Survey-of-Construct3/ - Further reading: -* [About Kaitai Struct](http://kaitai.io/) -* [About API implemented in this library](http://doc.kaitai.io/stream_api.html) -* [Python-specific notes](http://doc.kaitai.io/lang_python.html) +* `About Kaitai Struct <http://kaitai.io/>`_ +* `About API implemented in this library <http://doc.kaitai.io/stream_api.html>`_ +* `Python specific notes <http://doc.kaitai.io/lang_python.html>`_ -## Installing +Installing +------------------------------ -### Using `requirements.txt` +Using `requirements.txt` +------------------------------ If you want to use Kaitai Struct runtime in your project and you use `requirements.txt` to manage your dependencies, just add the following line to it: -``` -kaitaistruct -``` +:: + + kaitaistruct and then run `pip install -r requirements.txt` to update all your dependencies. -### Using `pip` directly +Using `pip` directly +------------------------------ You can use -```shell -pip install kaitaistruct -``` +:: + + pip install kaitaistruct to install the package manually using `pip` Python package manager. -## Licensing +Licensing +------------------------------ -Copyright 2015-2017 Kaitai Project: MIT license +Copyright 2015-2018 Kaitai Project: MIT license Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/debian/changelog b/debian/changelog index d6a7d5d..bfefdbb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,20 @@ +python-kaitaistruct (0.8-1) unstable; urgency=medium + + * Switch to DEP 14 + * Update Vcs-* to point to salsa.d.o + * New upstream version 0.8 + * Use https for copyright-format URL + * Use https for watch URL + * Bump-up Standards-Version + + -- Sebastien Delafond <seb@debian.org> Fri, 30 Mar 2018 14:02:03 +0200 + +python-kaitaistruct (0.7-2) unstable; urgency=medium + + * Remove markdown from debian/control (Closes: #869265) + + -- Sebastien Delafond <seb@debian.org> Tue, 25 Jul 2017 07:56:23 +0200 + python-kaitaistruct (0.7-1) unstable; urgency=low * First upload (Closes: #849556) diff --git a/debian/control b/debian/control index f21406f..3da7b35 100644 --- a/debian/control +++ b/debian/control @@ -3,10 +3,10 @@ Maintainer: Sebastien Delafond <seb@debian.org> Section: python Priority: optional Build-Depends: dh-python, python-setuptools (>= 0.6b3), python3-setuptools, python-all (>= 2.6.6-3), python3-all, debhelper (>= 9) -Standards-Version: 3.9.8 -Homepage: http://kaitai.io -Vcs-Git: https://anonscm.debian.org/git/collab-maint/python-kaitaistruct.git -Vcs-Browser: https://anonscm.debian.org/git/collab-maint/python-kaitaistruct.git +Standards-Version: 4.1.3 +Homepage: https://kaitai.io +Vcs-Git: https://salsa.debian.org/debian/python-kaitaistruct.git +Vcs-Browser: https://salsa.debian.org/debian/python-kaitaistruct X-Python-Version: >= 2.7 X-Python3-Version: >= 3.4 @@ -16,17 +16,14 @@ Depends: ${misc:Depends}, ${python:Depends} Description: Kaitai Struct declarative parser generator for binary data This library implements Kaitai Struct API for Python. . - [Kaitai Struct](http://kaitai.io) is a declarative language used for - describe various binary data structures, laid out in files or in memory: - i.e. binary file formats, network stream packet formats, etc. + Kaitai Struct is a declarative language used for describe various + binary data structures, laid out in files or in memory: i.e. binary + file formats, network stream packet formats, etc. . - It is similar to Python's [construct] and [Construct3], but it is + It is similar to Python's construct and Construct3, but it is language-agnostic. The format description is done in YAML-based .ksy - format, which then can be compiled into a wide range of target languages. - . - [construct]: https://pypi.python.org/pypi/construct - [Construct3]: http://tomerfiliba.com/blog/Survey-of-Construct3/ - . + format, which then can be compiled into a wide range of target + languages. Package: python3-kaitaistruct Architecture: all @@ -34,15 +31,13 @@ Depends: ${misc:Depends}, ${python3:Depends} Description: Kaitai Struct declarative parser generator for binary data (python3) This library implements Kaitai Struct API for Python. . - [Kaitai Struct](http://kaitai.io) is a declarative language used for - describe various binary data structures, laid out in files or in memory: - i.e. binary file formats, network stream packet formats, etc. + Kaitai Struct is a declarative language used for describe various + binary data structures, laid out in files or in memory: i.e. binary + file formats, network stream packet formats, etc. . - It is similar to Python's [construct] and [Construct3], but it is + It is similar to Python's construct and Construct3, but it is language-agnostic. The format description is done in YAML-based .ksy - format, which then can be compiled into a wide range of target languages. - . - [construct]: https://pypi.python.org/pypi/construct - [Construct3]: http://tomerfiliba.com/blog/Survey-of-Construct3/ + format, which then can be compiled into a wide range of target + languages. . This is the Python3 package.
\ No newline at end of file diff --git a/debian/copyright b/debian/copyright index 0d6ea5e..9f75599 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,4 +1,4 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: kaitaistruct Source: https://pypi.python.org/pypi/kaitaistruct diff --git a/debian/gbp.conf b/debian/gbp.conf new file mode 100644 index 0000000..2541c07 --- /dev/null +++ b/debian/gbp.conf @@ -0,0 +1,3 @@ +[DEFAULT] +debian-branch = debian/master +upstream-branch = upstream/latest diff --git a/debian/watch b/debian/watch index f82abda..ba11ea4 100644 --- a/debian/watch +++ b/debian/watch @@ -1,4 +1,3 @@ -# please also check http://pypi.debian.net/kaitaistruct/watch version=3 opts=uversionmangle=s/(rc|a|b|c)/~$1/ \ -http://pypi.debian.net/kaitaistruct/kaitaistruct-(.+)\.(?:zip|tgz|tbz|txz|(?:tar\.(?:gz|bz2|xz)))
\ No newline at end of file +https://pypi.debian.net/kaitaistruct/kaitaistruct-(.+)\.(?:zip|tgz|tbz|txz|(?:tar\.(?:gz|bz2|xz)))
\ No newline at end of file diff --git a/kaitaistruct.egg-info/PKG-INFO b/kaitaistruct.egg-info/PKG-INFO index 2b4080d..d6d9cfe 100644 --- a/kaitaistruct.egg-info/PKG-INFO +++ b/kaitaistruct.egg-info/PKG-INFO @@ -1,60 +1,63 @@ Metadata-Version: 1.1 Name: kaitaistruct -Version: 0.7 +Version: 0.8 Summary: Kaitai Struct declarative parser generator for binary data: runtime library for Python Home-page: http://kaitai.io Author: Kaitai Project Author-email: greycat@kaitai.io License: MIT -Description: # Kaitai Struct: runtime library for Python +Description-Content-Type: UNKNOWN +Description: Kaitai Struct: runtime library for Python + =========================================== This library implements Kaitai Struct API for Python. - [Kaitai Struct](http://kaitai.io) is a declarative language used for + `Kaitai Struct <http://kaitai.io>`_ is a declarative language used for describe various binary data structures, laid out in files or in memory: i.e. binary file formats, network stream packet formats, etc. - It is similar to Python's [construct] and [Construct3], but it is + It is similar to `Python's Construct 2.9 <http://construct.readthedocs.org/>`_ but it is language-agnostic. The format description is done in YAML-based .ksy format, which then can be compiled into a wide range of target languages. - [construct]: https://pypi.python.org/pypi/construct - [Construct3]: http://tomerfiliba.com/blog/Survey-of-Construct3/ - Further reading: - * [About Kaitai Struct](http://kaitai.io/) - * [About API implemented in this library](http://doc.kaitai.io/stream_api.html) - * [Python-specific notes](http://doc.kaitai.io/lang_python.html) + * `About Kaitai Struct <http://kaitai.io/>`_ + * `About API implemented in this library <http://doc.kaitai.io/stream_api.html>`_ + * `Python specific notes <http://doc.kaitai.io/lang_python.html>`_ - ## Installing + Installing + ------------------------------ - ### Using `requirements.txt` + Using `requirements.txt` + ------------------------------ If you want to use Kaitai Struct runtime in your project and you use `requirements.txt` to manage your dependencies, just add the following line to it: - ``` - kaitaistruct - ``` + :: + + kaitaistruct and then run `pip install -r requirements.txt` to update all your dependencies. - ### Using `pip` directly + Using `pip` directly + ------------------------------ You can use - ```shell - pip install kaitaistruct - ``` + :: + + pip install kaitaistruct to install the package manually using `pip` Python package manager. - ## Licensing + Licensing + ------------------------------ - Copyright 2015-2017 Kaitai Project: MIT license + Copyright 2015-2018 Kaitai Project: MIT license Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -87,3 +90,7 @@ Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: Implementation :: CPython +Classifier: Programming Language :: Python :: Implementation :: PyPy diff --git a/kaitaistruct.egg-info/SOURCES.txt b/kaitaistruct.egg-info/SOURCES.txt index 2ebf2ed..d23d1d5 100644 --- a/kaitaistruct.egg-info/SOURCES.txt +++ b/kaitaistruct.egg-info/SOURCES.txt @@ -1,5 +1,5 @@ MANIFEST.in -README.md +README.rst kaitaistruct.py setup.cfg setup.py diff --git a/kaitaistruct.py b/kaitaistruct.py index 735561e..0fb0aa7 100644 --- a/kaitaistruct.py +++ b/kaitaistruct.py @@ -1,12 +1,7 @@ import itertools import sys from struct import unpack - -try: - import cStringIO - BytesIO = cStringIO.StringIO -except ImportError: - from io import BytesIO # noqa +from io import BytesIO # noqa PY2 = sys.version_info[0] == 2 @@ -17,7 +12,7 @@ PY2 = sys.version_info[0] == 2 # KS runtime library by this version number; # * distribution utils (setup.py) use this when packaging for PyPI # -__version__ = '0.7' +__version__ = '0.8' class KaitaiStruct(object): @@ -30,6 +25,9 @@ class KaitaiStruct(object): def __exit__(self, *args, **kwargs): self.close() + def close(self): + self._io.close() + @classmethod def from_file(cls, filename): f = open(filename, 'rb') @@ -40,8 +38,13 @@ class KaitaiStruct(object): f.close() raise - def close(self): - self._io.close() + @classmethod + def from_bytes(cls, buf): + return cls(KaitaiStream(BytesIO(buf))) + + @classmethod + def from_io(cls, io): + return cls(KaitaiStream(io)) class KaitaiStream(object): @@ -82,19 +85,14 @@ class KaitaiStream(object): # current file / StringIO size, thus we use the following # trick. io = self._io - # Remember our current position cur_pos = io.tell() - # Seek to the end of the File object io.seek(0, 2) - # Remember position, which is equal to the full length full_size = io.tell() - # Seek back to the current position io.seek(cur_pos) - return full_size # ======================================================================== @@ -236,10 +234,16 @@ class KaitaiStream(object): # ======================================================================== def read_bytes(self, n): + if n < 0: + raise ValueError( + "requested invalid %d amount of bytes" % + (n,) + ) r = self._io.read(n) if len(r) < n: raise EOFError( - "requested %d bytes, but got only %d bytes" % (n, len(r)) + "requested %d bytes, but got only %d bytes" % + (n, len(r)) ) return r @@ -253,7 +257,7 @@ class KaitaiStream(object): if c == b'': if eos_error: raise Exception( - "End of stream reached, but no terminator %d found" % + "end of stream reached, but no terminator %d found" % (term,) ) else: @@ -271,32 +275,30 @@ class KaitaiStream(object): actual = self._io.read(len(expected)) if actual != expected: raise Exception( - "Unexpected fixed contents: got %s, was waiting for %s" % - (str(actual), str(expected)) + "unexpected fixed contents: got %r, was waiting for %r" % + (actual, expected) ) return actual @staticmethod - def bytes_strip_right(src, pad_byte): - new_len = len(src) + def bytes_strip_right(data, pad_byte): + new_len = len(data) if PY2: - data = bytearray(src) - else: - data = src + # data[...] must yield an integer, to compare with integer pad_byte + data = bytearray(data) - while data[new_len - 1] == pad_byte: + while new_len > 0 and data[new_len - 1] == pad_byte: new_len -= 1 return data[:new_len] @staticmethod - def bytes_terminate(src, term, include_term): + def bytes_terminate(data, term, include_term): new_len = 0 - max_len = len(src) + max_len = len(data) if PY2: - data = bytearray(src) - else: - data = src + # data[...] must yield an integer, to compare with integer term + data = bytearray(data) while new_len < max_len and data[new_len] != term: new_len += 1 @@ -313,26 +315,14 @@ class KaitaiStream(object): @staticmethod def process_xor_one(data, key): if PY2: - r = bytearray(data) - for i in range(len(r)): - r[i] ^= key - return bytes(r) + return bytes(bytearray(v ^ key for v in bytearray(data))) else: return bytes(v ^ key for v in data) @staticmethod def process_xor_many(data, key): if PY2: - r = bytearray(data) - k = bytearray(key) - ki = 0 - kl = len(k) - for i in range(len(r)): - r[i] ^= k[ki] - ki += 1 - if ki >= kl: - ki = 0 - return bytes(r) + return bytes(bytearray(a ^ b for a, b in zip(bytearray(data), itertools.cycle(bytearray(key))))) else: return bytes(a ^ b for a, b in zip(data, itertools.cycle(key))) @@ -4,5 +4,4 @@ universal = 1 [egg_info] tag_build = tag_date = 0 -tag_svn_revision = 0 @@ -2,7 +2,7 @@ from setuptools import setup from io import open from kaitaistruct import __version__ -with open('README.md', encoding='utf-8') as f: +with open('README.rst', encoding='utf-8') as f: long_description = f.read() setup( @@ -37,7 +37,11 @@ setup( 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", ], keywords='kaitai,struct,ksy,declarative,data structure,data format,file format,packet format,binary,parser,parsing,unpack,development', - py_modules=["kaitaistruct"] + py_modules=["kaitaistruct"], ) |
