Skip to content

Commit 9692130

Browse files
author
brentru
committed
add readme, index docs
1 parent edcd42c commit 9692130

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

README.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Introduction
1313
:target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_binascii
1414
:alt: Build Status
1515

16-
Helpers for conversions between binary and ASCII
17-
16+
The binascii module contains a number of methods to convert between binary and various ASCII-encoded binary representations.
1817

1918
Dependencies
2019
=============
@@ -31,9 +30,6 @@ Installing from PyPI
3130
.. note:: This library is not available on PyPI yet. Install documentation is included
3231
as a standard element. Stay tuned for PyPI availability!
3332

34-
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
35-
If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
36-
3733
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
3834
PyPI <https://pypi.org/project/adafruit-circuitpython-binascii/>`_. To install for current user:
3935

@@ -59,7 +55,21 @@ To install in a virtual environment in your current project:
5955
Usage Example
6056
=============
6157

62-
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
58+
Hex <-> Binary Conversions
59+
60+
.. code-block:: python
61+
62+
from adafruit_binascii import hexlify, unhexlify
63+
# Binary data.
64+
data = b"CircuitPython is Awesome!"
65+
66+
# Get the hexadecimal representation of the binary data
67+
hex_data = hexlify(data)
68+
print("Hex Data: ", hex_data)
69+
70+
# Get the binary data represented by hex_data
71+
bin_data = unhexlify(hex_data)
72+
print("Binary Data: ", bin_data)
6373
6474
Contributing
6575
============

docs/index.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
2826

2927
.. toctree::
3028
:caption: Related Products
3129

32-
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
33-
the toctree above for use later.
3430

3531
.. toctree::
3632
:caption: Other Links

examples/binascii_simpletest.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
from adafruit_binascii import hexlify, unhexlify, a2b_base64, b2a_base64
22

3+
print("-- Binary<->Hex Conversions --")
34
# Binary data.
45
data = b"CircuitPython is Awesome!"
6+
print("Original Binary Data: ", data)
57

68
# Get the hexadecimal representation of the binary data
79
hex_data = hexlify(data)
810
# Verify data
9-
assert (
10-
hex_data == b"43697263756974507974686f6e20697320417765736f6d6521",
11-
), "hexlified data does not match expected data."
11+
print("Hex Data: ", hex_data)
12+
assert hex_data == b"43697263756974507974686f6e20697320417765736f6d6521", "hexlified data does not match expected data."
1213

1314
# Get the binary data represented by hex_data
1415
bin_data = unhexlify(hex_data)
16+
print("Binary Data: ", bin_data)
1517
# Verify data
1618
assert bin_data == data, "unhexlified binary data does not match original binary data."
1719

20+
print("-- Base64 ASCII <-> Binary Conversions --")
21+
data = b"Blinka"
22+
print("Original Binary Data: ", data)
1823
# Convert binary data to a line of ASCII characters in base64 coding.
19-
assert b2a_base64(b"Blinka") == b"Qmxpbmth\n", "Expected base64 coding does not match."
24+
b64_ascii_data = b2a_base64(data)
25+
print("Base64 ASCII Data: ", b64_ascii_data)
26+
assert b64_ascii_data == b"Qmxpbmth\n", "Expected base64 coding does not match."
2027

2128
# Convert a block of base64 data back to binary data.
22-
assert a2b_base64(b"Qmxpbmth\n") == b"Blinka", "Expected binary data does not match."
29+
bin_data = a2b_base64(b"Qmxpbmth\n")
30+
print("Converted b64 ASCII->Binary Data: ", bin_data)
31+
assert bin_data == data, "Expected binary data does not match."
32+
33+
print("All checks OK!")

0 commit comments

Comments
 (0)