chiark / gitweb /
Add 'base91-python/' from commit '749aa78cf12496cca4b9bf3eafe045809fc0da10'
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:19 +0000 (21:56 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:22 +0000 (21:56 +0000)
Upstream is
    https://github.com/Fuyukai/base91-python

git-subtree-dir: base91-python
git-subtree-mainline: 7fcfcb3210f7bdaddc5a1fc68586846b31adab63
git-subtree-split: 749aa78cf12496cca4b9bf3eafe045809fc0da10

1  2 
base91-python/.gitignore
base91-python/README.md
base91-python/base91/__init__.py
base91-python/setup.py

diff --combined base91-python/.gitignore
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..f24cd9952da6568ccae31e4d333551ade6907553
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,27 @@@
++*.py[co]
++
++# Packages
++*.egg
++*.egg-info
++dist
++build
++eggs
++parts
++bin
++var
++sdist
++develop-eggs
++.installed.cfg
++
++# Installer logs
++pip-log.txt
++
++# Unit test / coverage reports
++.coverage
++.tox
++
++#Translations
++*.mo
++
++#Mr Developer
++.mr.developer.cfg
diff --combined base91-python/README.md
index 0000000000000000000000000000000000000000,580df9880e45439cfa78883feeee10dc02101cac..580df9880e45439cfa78883feeee10dc02101cac
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,15 +1,15 @@@
+ base91-python
+ =============
+ A python implementation of Base91 as described on http://base91.sourceforge.net/ , licenced under the New BSD License.
+ Usage
+ -----
+       import base91
+       base91.encode('test')                                           #result: 'fPNKd'
+       base91.encode(b'\xfe\x03\x00W\xa9\xbc')         #result: 'VLv(GdNE'
+       base91.decode('8D9Kc)=/2$WzeFui#G9Km+<{VT2u9MZil}[A') # result: 'May a moody baby doom a yam?\n'
index 0000000000000000000000000000000000000000,d6541314f61ff97009b5ba8b88a5180603dba39a..d6541314f61ff97009b5ba8b88a5180603dba39a
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,94 +1,94 @@@
+ # Base91 encode/decode for Python 2 and Python 3
+ #
+ # Copyright (c) 2012 Adrien Beraud
+ # Copyright (c) 2015 Guillaume Jacquenot
+ # All rights reserved.
+ #
+ # Redistribution and use in source and binary forms, with or without
+ # modification, are permitted provided that the following conditions are met:
+ #
+ #   * Redistributions of source code must retain the above copyright notice,
+ #     this list of conditions and the following disclaimer.
+ #   * Redistributions in binary form must reproduce the above copyright notice,
+ #     this list of conditions and the following disclaimer in the documentation
+ #     and/or other materials provided with the distribution.
+ #   * Neither the name of Adrien Beraud, Wisdom Vibes Pte. Ltd., nor the names
+ #     of its contributors may be used to endorse or promote products derived
+ #     from this software without specific prior written permission.
+ #
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ #
+ import struct
+ base91_alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+                    'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+                    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+                    'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+                    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#', '$',
+                    '%', '&', '(', ')', '*', '+', ',', '.', '/', ':', ';', '<', '=',
+                    '>', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~', '"']
+ decode_table = dict((v, k) for k, v in enumerate(base91_alphabet))
+ def decode(encoded_str):
+     ''' Decode Base91 string to a bytearray '''
+     v = -1
+     b = 0
+     n = 0
+     out = bytearray()
+     for strletter in encoded_str:
+         if not strletter in decode_table:
+             continue
+         c = decode_table[strletter]
+         if (v < 0):
+             v = c
+         else:
+             v += c * 91
+             b |= v << n
+             n += 13 if (v & 8191) > 88 else 14
+             while True:
+                 out += struct.pack('B', b & 255)
+                 b >>= 8
+                 n -= 8
+                 if not n > 7:
+                     break
+             v = -1
+     if v + 1:
+         out += struct.pack('B', (b | v << n) & 255)
+     return out
+ def encode(bindata):
+     ''' Encode a bytearray to a Base91 string '''
+     b = 0
+     n = 0
+     out = ''
+     for count in range(len(bindata)):
+         byte = bindata[count:count + 1]
+         b |= struct.unpack('B', byte)[0] << n
+         n += 8
+         if n > 13:
+             v = b & 8191
+             if v > 88:
+                 b >>= 13
+                 n -= 13
+             else:
+                 v = b & 16383
+                 b >>= 14
+                 n -= 14
+             out += base91_alphabet[v % 91] + base91_alphabet[v // 91]
+     if n:
+         out += base91_alphabet[b % 91]
+         if n > 7 or b > 90:
+             out += base91_alphabet[b // 91]
+     return out
diff --combined base91-python/setup.py
index 0000000000000000000000000000000000000000,8fb8d22ccf5eb270997655d8b94e91ff5b14516e..8fb8d22ccf5eb270997655d8b94e91ff5b14516e
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,12 +1,12 @@@
+ from setuptools import setup
+ setup(
+     name='base91',
+     version='1.0.1',
+     packages=['base91'],
+     url='https://github.com/SunDwarf/base91-python',
+     license='New BSD',
+     author='',
+     author_email='',
+     description='Base91 encoding in Python'
+ )