Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for providing custom registries #109

Merged
merged 12 commits into from
Nov 30, 2018
16 changes: 16 additions & 0 deletions docs/eth_abi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ eth\_abi.base module
:members: BaseCoder
:show-inheritance:

eth\_abi.codec module
---------------------

.. automodule:: eth_abi.codec
:members:
:undoc-members:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davesque / @carver - Do we care to have this turned on or just display documented members?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it's good to have it on. If we don't want something public, it should be _-prefixed.

:show-inheritance:

eth\_abi.codec_packed module
----------------------------

.. automodule:: eth_abi.codec_packed
:members:
:undoc-members:
:show-inheritance:

eth\_abi.decoding module
------------------------

Expand Down
36 changes: 18 additions & 18 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ v2.0.0-beta.1
the parsing API more consistent with the new parsimonious parser.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were warnings showing up when running make build-docs about the title underline being too short, so I fixed this up to clean up the warnings.


v2.0.0-alpha.1
-------------
--------------

Released July 19, 2018

Expand All @@ -49,7 +49,7 @@ Released July 19, 2018
- Various documentation updates and type annotations

v1.2.1
-------------
------

Released October 16, 2018

Expand All @@ -59,7 +59,7 @@ Released October 16, 2018
(backport from v2)

v1.2.0
-------------
------

Released August 28, 2018

Expand All @@ -69,7 +69,7 @@ Released August 28, 2018
version 2 ABI

v1.1.1
-------------
------

Released May 10, 2018

Expand All @@ -82,7 +82,7 @@ Released May 10, 2018
:class:`TypeError` when trying to encode a :class:`float` into a ``fixed<M>x<N>`` type.

v1.1.0
-------------
------

Released May 8, 2018

Expand All @@ -106,7 +106,7 @@ Released May 8, 2018
- Drop Python 2 support cruft

v1.0.0
-------------
------

Released Feb 28, 2018

Expand All @@ -123,63 +123,63 @@ Released Feb 5, 2018
- Add support for eth-utils v1-beta1

v0.5.0
--------
------

- Rename to ``eth-abi`` for consistency across github/pypi/python-module

v0.4.4
-----
------

- Better error messages for decoder errors.

v0.4.3
-----
------

- Bugfix for ``process_type`` to support byte string type arrguments

v0.4.2
-----
------

- ``process_type`` now auto-expands all types which have omittied their sizes.

v0.4.1
-----
------

- Support for ``function`` types.

v0.3.1
-----
------

- Bugfix for small signed integer and real encoding/decoding

v0.3.1
-----
------

- Bugfix for faulty release.

v0.3.0
-----
------

- Depart from the original pyethereum encoding/decoding logic.
- Fully rewritten encoder and decoder functionality.

v0.2.2
-----
------

- Fix a handful of bytes encoding issues.

v0.2.1
-----
------

- Use pyrlp utility functions for big_endian int operations

v0.2.0
-----
------

- Bugfixes from upstream pyethereum repository for encoding/decoding
- Python 3 Support

v0.1.0
-----
------

- Initial release
25 changes: 25 additions & 0 deletions eth_abi/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@


class BaseABICodecEncoder():
"""
Base codec used to encode values.
"""

def __init__(self, registry):
"""
Constructor.

:param registry: The registry providing the encoders to be used when encoding
values. May not be ``None``.

:returns: An instance of `~BaseABICodecEncoder`.
"""
if registry is None:
raise ValueError("`registry` may not be None")

Expand Down Expand Up @@ -100,7 +112,20 @@ def is_encodable(self, typ: TypeStr, arg: Any) -> bool:


class ABICodec(BaseABICodecEncoder):
"""
Codec used to encode and decode values.
"""

def __init__(self, registry: ABIRegistry=None):
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davesque / @carver - I noticed that the __init__ methods aren't showing up in the docs; also, I haven't really seen constructors be documented in the project. I think it could be valuable to have this documented as the API isn't self-documenting in regards to what registry is being used or even that there is a default registry being used. Not sure if this is something we'd move up to the class doc or just not have it at all?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we can get the __init__ docs added to the class docs by adding autoclass_content = 'both' to the docs conf. Can you experiment with it to see if that works as expected, looks okay, etc? https://stackoverflow.com/a/9772922/8412986

If so, we will probably add it to our project template so that it eventually gets filters to all our other projects.

Constructor.

:param registry: The registry providing the encoders and decoders
to be used when encoding and decoding values. If no ``registry``
is provided, `~eth_abi.registry.default_registry` will be used.

:returns: An instance of `~eth_abi.codec.ABICodec`.
"""
if registry is None:
BaseABICodecEncoder.__init__(self, default_registry)
else:
Expand Down
18 changes: 16 additions & 2 deletions eth_abi/codec_packed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
)
from eth_abi.registry import (
ABIRegistry,
registry_packed as default_packed_registry,
registry_packed as default_registry_packed,
)

warnings.warn(
Expand All @@ -15,8 +15,22 @@


class ABICodecPacked(BaseABICodecEncoder):
"""
Codec used to encode values in packed mode. Decoding of values in not
supported.
"""

def __init__(self, registry: ABIRegistry=None):
"""
Constructor.

:param registry: The registry providing the encoders and decoders
to be used when encoding and decoding values. If no ``registry``
is provided, `~eth_abi.registry.default_registry_packed` will be used.

:returns: An instance of `~eth_abi.codec_packed.ABICodecPacked`.
"""
if registry is None:
BaseABICodecEncoder.__init__(self, default_packed_registry)
BaseABICodecEncoder.__init__(self, default_registry_packed)
else:
BaseABICodecEncoder.__init__(self, registry)