sphinx-compatible docstring (only DAL remains)
This commit is contained in:
+18
-14
@@ -2,11 +2,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
This file is part of the web2py Web Framework
|
||||
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
|
||||
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
| This file is part of the web2py Web Framework
|
||||
| Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
|
||||
| License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
This file specifically includes utilities for security.
|
||||
--------------------------------------------------------
|
||||
"""
|
||||
|
||||
import threading
|
||||
@@ -65,7 +66,7 @@ def AES_new(key, IV=None):
|
||||
|
||||
|
||||
def compare(a, b):
|
||||
""" compares two strings and not vulnerable to timing attacks """
|
||||
""" Compares two strings and not vulnerable to timing attacks """
|
||||
if len(a) != len(b):
|
||||
return False
|
||||
result = 0
|
||||
@@ -75,7 +76,7 @@ def compare(a, b):
|
||||
|
||||
|
||||
def md5_hash(text):
|
||||
""" Generate a md5 hash with the given text """
|
||||
""" Generates a md5 hash with the given text """
|
||||
return md5(text).hexdigest()
|
||||
|
||||
def simple_hash(text, key='', salt='', digest_alg='md5'):
|
||||
@@ -177,7 +178,7 @@ def secure_loads(data, encryption_key, hash_key=None, compression_level=None):
|
||||
def initialize_urandom():
|
||||
"""
|
||||
This function and the web2py_uuid follow from the following discussion:
|
||||
http://groups.google.com/group/web2py-developers/browse_thread/thread/7fd5789a7da3f09
|
||||
`http://groups.google.com/group/web2py-developers/browse_thread/thread/7fd5789a7da3f09`
|
||||
|
||||
At startup web2py compute a unique ID that identifies the machine by adding
|
||||
uuid.getnode() + int(time.time() * 1e3)
|
||||
@@ -225,7 +226,7 @@ UNPACKED_CTOKENS, HAVE_URANDOM = initialize_urandom()
|
||||
|
||||
def fast_urandom16(urandom=[], locker=threading.RLock()):
|
||||
"""
|
||||
this is 4x faster than calling os.urandom(16) and prevents
|
||||
This is 4x faster than calling os.urandom(16) and prevents
|
||||
the "too many files open" issue with concurrent access to os.urandom()
|
||||
"""
|
||||
try:
|
||||
@@ -243,7 +244,7 @@ def fast_urandom16(urandom=[], locker=threading.RLock()):
|
||||
def web2py_uuid(ctokens=UNPACKED_CTOKENS):
|
||||
"""
|
||||
This function follows from the following discussion:
|
||||
http://groups.google.com/group/web2py-developers/browse_thread/thread/7fd5789a7da3f09
|
||||
`http://groups.google.com/group/web2py-developers/browse_thread/thread/7fd5789a7da3f09`
|
||||
|
||||
It works like uuid.uuid4 except that tries to use os.urandom() if possible
|
||||
and it XORs the output with the tokens uniquely associated with this machine.
|
||||
@@ -263,12 +264,15 @@ REGEX_IPv4 = re.compile('(\d+)\.(\d+)\.(\d+)\.(\d+)')
|
||||
|
||||
def is_valid_ip_address(address):
|
||||
"""
|
||||
>>> is_valid_ip_address('127.0')
|
||||
False
|
||||
>>> is_valid_ip_address('127.0.0.1')
|
||||
True
|
||||
>>> is_valid_ip_address('2001:660::1')
|
||||
True
|
||||
Examples:
|
||||
Better than a thousand words::
|
||||
|
||||
>>> is_valid_ip_address('127.0')
|
||||
False
|
||||
>>> is_valid_ip_address('127.0.0.1')
|
||||
True
|
||||
>>> is_valid_ip_address('2001:660::1')
|
||||
True
|
||||
"""
|
||||
# deal with special cases
|
||||
if address.lower() in ('127.0.0.1', 'localhost', '::1', '::ffff:127.0.0.1'):
|
||||
|
||||
Reference in New Issue
Block a user