Commits

Gora Khargosh committed 895d45b

Some lint clean up.

Signed-off-by: Gora Khargosh <gora.khargosh@gmail.com>

Comments (0)

Files changed (10)

 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+"""
+:module: mom
+:synopsis: Mother of all our Python projects.
+"""
+
 from mom import codec, security, builtins, decorators, math
 
 __all__ = [
 from __future__ import absolute_import
 
 try:
-    _BytesType = bytes
-except Exception:
-    _BytesType = str
+    bytes_type = bytes
+except NameError:
+    bytes_type = str
 
 try:
     # Not Python3
-    _UnicodeType = unicode
-    _BasestringType = basestring
-except Exception:
+    unicode_type = unicode
+    basestring_type = basestring
+except NameError:
     # Python3.
-    _UnicodeType = str
-    _BasestringType = (str, bytes)
+    unicode_type = str
+    basestring_type = (str, bytes)
 
 

mom/_types/__init__.py

 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
+"""
+:module: mom._types
+:synopsis: Internal types.
+"""
 import sys
 import math
 
-from mom._builtins import _BytesType, _UnicodeType, _BasestringType
+from mom._builtins import bytes_type, unicode_type, basestring_type
 
 
 def is_python3():
 # up a lot of code. The transition between Python 2.x and 3.x
 # simply does not allow us to use "str", so we're forced to use
 # ``bytes`` and ``unicode`` instead of the usual ``str`` calls.
-bytes = _BytesType
-unicode = _UnicodeType
+bytes = bytes_type
+unicode = unicode_type
 
 
 def bin(num, prefix="0b"):
     return prefix + bit_string
 
 
-def _bin_lookup(num, prefix="0b"):
-    """
-    Converts a long value to its binary representation based on a lookup table.
-
-    Alternative implementation of :func:``bin``.
-
-    :param num:
-        Long value.
-    :param prefix:
-        The prefix to use for the bitstring. Default "0b" to mimic Python
-        builtin ``bin()``.
-    :returns:
-        Bit string.
-    """
-    prefix = prefix or ""
-    bit_string = ''
-    lookup = {'0':'000','1':'001','2':'010','3':'011',
-              '4':'100','5':'101','6':'110','7':'111'}
-    for c in oct(num)[1:]:
-        bit_string += lookup[c]
-    return prefix + bit_string
-
-
-def _bin_recursive(num, prefix="0b"):
-    """
-    Converts a long value to its binary representation recursively.
-
-    Alternative implementation of :func:``bin``.
-
-    :param num:
-        Long value.
-    :param prefix:
-        The prefix to use for the bitstring. Default "0b" to mimic Python
-        builtin ``bin()``.
-    :returns:
-        Bit string.
-    """
-    prefix = prefix or ""
-    if num <= 1:
-        bitstring = bytes(num)
-    else:
-        bitstring = _bin_recursive(num >> 1) + bytes(num & 1)
-    return prefix + bitstring
+#def _bin_lookup(num, prefix="0b"):
+#    """
+#    Converts a long value to its binary representation based on a lookup table.
+#
+#    Alternative implementation of :func:``bin``.
+#
+#    :param num:
+#        Long value.
+#    :param prefix:
+#        The prefix to use for the bitstring. Default "0b" to mimic Python
+#        builtin ``bin()``.
+#    :returns:
+#        Bit string.
+#    """
+#    prefix = prefix or ""
+#    bit_string = ''
+#    lookup = {'0':'000', '1':'001', '2':'010', '3':'011',
+#              '4':'100', '5':'101', '6':'110', '7':'111'}
+#    for c in oct(num)[1:]:
+#        bit_string += lookup[c]
+#    return prefix + bit_string
+#
+#
+#def _bin_recursive(num, prefix="0b"):
+#    """
+#    Converts a long value to its binary representation recursively.
+#
+#    Alternative implementation of :func:``bin``.
+#
+#    :param num:
+#        Long value.
+#    :param prefix:
+#        The prefix to use for the bitstring. Default "0b" to mimic Python
+#        builtin ``bin()``.
+#    :returns:
+#        Bit string.
+#    """
+#    prefix = prefix or ""
+#    if num <= 1:
+#        bitstring = bytes(num)
+#    else:
+#        bitstring = _bin_recursive(num >> 1) + bytes(num & 1)
+#    return prefix + bitstring
 
 
 def hex(num, prefix="0x"):
     :returns:
         ``True`` if ``value`` is a Unicode string; ``False`` otherwise.
     """
-    return isinstance(obj, _UnicodeType)
+    return isinstance(obj, unicode_type)
 
 
 def is_bytes(obj):
     :returns:
         ``True`` if ``value`` is a byte string; ``False`` otherwise.
     """
-    return isinstance(obj, _BytesType)
+    return isinstance(obj, bytes_type)
 
 
 def is_bytes_or_unicode(obj):
     :returns:
         ``True`` if ``value`` is a string; ``False`` otherwise.
     """
-    return isinstance(obj, _BasestringType)
+    return isinstance(obj, basestring_type)
 
 
 def unicode_to_utf8(obj):

mom/codec/__init__.py

 
 try:
     # Check whether we have reduce as a built-in.
-    reduce_test = reduce((lambda num1, num2: num1 + num2), [1, 2, 3, 4])
+    __reduce_test__ = reduce((lambda num1, num2: num1 + num2), [1, 2, 3, 4])
 except NameError:
     # Python 3k
     from functools import reduce
     encoded = encoded.lower()  # Hex string
     if encoded[:2] == "0x":
         encoded = encoded[2:]
-    for c in encoded:  # Hex character
+    for character in encoded:  # Hex character
         num *= 16
-        if "0" <= c <= "9":
-            num += ord(c) - ord("0")
-        elif "a" <= c <= "f":
-            num += ord(c) - ord("a") + 10
+        if "0" <= character <= "9":
+            num += ord(character) - ord("0")
+        elif "a" <= character <= "f":
+            num += ord(character) - ord("a") + 10
         else:
-            raise ValueError(c)
+            raise ValueError(character)
     return num
 
 

mom/codec/json.py

 
 from __future__ import absolute_import
 from mom.builtins import to_unicode_recursively, bytes_to_unicode
-from mom.codec._json import json_dumps, json_loads
 
 try:
     # Built-in JSON library.

mom/decorators.py

         return func(*args, **kwargs)
     return new_func
 
-

mom/security/hash.py

 from __future__ import absolute_import
 
 import hmac
-from hashlib import sha1, md5
+import hashlib
 from mom.codec import bytes_to_base64, bytes_to_hex
 
 
     :returns:
         A byte string containing the SHA-1 message digest.
     """
-    hash_func = sha1()
+    hash_func = hashlib.sha1()
     for i in inputs:
         hash_func.update(i)
     return hash_func.digest()
     :returns:
         A byte string containing the MD5 message digest.
     """
-    hash_func = md5()
+    hash_func = hashlib.md5()
     for i in inputs:
         hash_func.update(i)
     return hash_func.digest()
     :returns:
         HMAC SHA-1 Digest.
     """
-    return hmac.new(key, data, sha1).digest()
+    return hmac.new(key, data, hashlib.sha1).digest()
 
 
 def hmac_sha1_base64_digest(key, data):

mom/security/random.py

         return os.urandom(count)
 except AttributeError:
     try:
-        urandom_device = open("/dev/urandom", "rb")
+        __urandom_device__ = open("/dev/urandom", "rb")
         def generate_random_bytes(count):
             """
             Generates a random byte string with ``count`` bytes.
             :returns:
                 Random byte string.
             """
-            return urandom_device.read(count)
+            return __urandom_device__.read(count)
     except IOError:
         #Else get Win32 CryptoAPI PRNG
         try:

mom/security/rsa/keys.py

 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+"""
+:module: mom.security.rsa.keys
+:synopsis:Implements abstract classes for keys.
+"""
+
 from __future__ import absolute_import
 
 from mom.codec import long_to_bytes, bytes_to_long