Merge ssh://github.com/web2py/web2py

This commit is contained in:
Michele Comitini
2013-08-05 15:28:28 +02:00
8 changed files with 112 additions and 59 deletions

View File

@@ -1 +1 @@
Version 2.6.0-development+timestamp.2013.08.01.08.22.32
Version 2.6.0-development+timestamp.2013.08.05.02.33.02

View File

@@ -211,12 +211,13 @@
},
trap_form: function (action, target) {
var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working...";
$('#' + target + ' form').each(function (i) {
var form = $(this);
form.attr('data-w2p_target', target);
if(!form.hasClass('no_trap')) {
//should be there by default ?
form.find('input[type=submit]').attr('data-w2p_disable_with', 'Working...');
form.find('input[type=submit]').attr('data-w2p_disable_with', disable_with_message);
form.submit(function (e) {
web2py.hide_flash();
web2py.ajax_page('post', action, form.serialize(), target, form);
@@ -431,11 +432,12 @@
disableElement: function (el) {
el.addClass('disabled');
var method = el.prop('type') == 'submit' ? 'val' : 'html';
var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working...";
// store enabled state
el.data('w2p:enable-with', el[method]());
/* little addition by default*/
if((el.data('w2p_disable_with') == 'default') || (el.data('w2p_disable_with') === undefined)) {
el.data('w2p_disable_with', 'Working...');
el.data('w2p_disable_with', disable_with_message);
}
// set to disabled state
el[method](el.data('w2p_disable_with'));

View File

@@ -40,11 +40,11 @@
<script src="{{=URL('static','js/modernizr.custom.js')}}"></script>
<!-- include stylesheets -->
{{
response.files.append(URL('static','css/web2py.css'))
response.files.append(URL('static','css/bootstrap.min.css'))
response.files.append(URL('static','css/bootstrap-responsive.min.css'))
response.files.append(URL('static','css/web2py_bootstrap.css'))
{{
response.files.insert(0,URL('static','css/web2py.css'))
response.files.insert(1,URL('static','css/bootstrap.min.css'))
response.files.insert(2,URL('static','css/bootstrap-responsive.min.css'))
response.files.insert(3,URL('static','css/web2py_bootstrap.css'))
}}
{{include 'web2py_ajax.html'}}

View File

@@ -1,6 +1,7 @@
<script type="text/javascript"><!--
// These variables are used by the web2py_ajax_init function in web2py_ajax.js (which is loaded below).
var w2p_ajax_confirm_message = "{{=T('Are you sure you want to delete this object?')}}";
var w2p_ajax_disable_with_message = "{{=T('Working...')}}";
var w2p_ajax_date_format = "{{=T('%Y-%m-%d')}}";
var w2p_ajax_datetime_format = "{{=T('%Y-%m-%d %H:%M:%S')}}";
var ajax_error_500 = '{{=XML(T('An error occured, please %s the page') % A(T('reload'), _href=URL(args=request.args, vars=request.get_vars))) }}'

View File

@@ -34,14 +34,29 @@ def commoncrypto_hashlib_to_crypto_map_get(hashfunc):
raise ValueError('Unkwnown digest %s' % hashfunc)
return crypto_hashfunc
def commoncrypto_pbkdf2(c_pass, c_passlen,
c_salt, c_saltlen,
c_iter, digest, c_keylen, c_buff):
def commoncrypto_pbkdf2(data, salt, iterations, digest, keylen):
"""Common Crypto compatibile wrapper
"""
c_hashfunc = ctypes.c_int(commoncrypto_hashlib_to_crypto_map_get(digest))
c_hashfunc = ctypes.c_uint32(commoncrypto_hashlib_to_crypto_map_get(digest))
c_pass = ctypes.c_char_p(data)
c_passlen = ctypes.c_size_t(len(data))
c_salt = ctypes.c_char_p(salt)
c_saltlen = ctypes.c_size_t(len(salt))
c_iter = ctypes.c_uint(iterations)
c_keylen = ctypes.c_size_t(keylen)
c_buff = ctypes.create_string_buffer(keylen)
return 1 - crypto.CCKeyDerivationPBKDF(2, # hardcoded 2-> PBKDF2
crypto.CCKeyDerivationPBKDF.restype = ctypes.c_int
crypto.CCKeyDerivationPBKDF.argtypes = [ctypes.c_uint32,
ctypes.c_char_p,
ctypes.c_size_t,
ctypes.c_char_p,
ctypes.c_size_t,
ctypes.c_uint32,
ctypes.c_uint,
ctypes.c_char_p,
ctypes.c_size_t]
ret = crypto.CCKeyDerivationPBKDF(2, # hardcoded 2-> PBKDF2
c_pass, c_passlen,
c_salt, c_saltlen,
c_hashfunc,
@@ -49,6 +64,7 @@ def commoncrypto_pbkdf2(c_pass, c_passlen,
c_buff,
c_keylen)
return (1 - ret, c_buff)
def openssl_hashlib_to_crypto_map_get(hashfunc):
hashlib_to_crypto_map = {hashlib.md5: crypto.EVP_md5,
@@ -64,58 +80,76 @@ def openssl_hashlib_to_crypto_map_get(hashfunc):
return crypto_hashfunc()
def openssl_pbkdf2(c_pass, c_passlen,
c_salt, c_saltlen,
c_iter, digest, c_keylen, c_buff):
def openssl_pbkdf2(data, salt, iterations, digest, keylen):
"""OpenSSL compatibile wrapper
"""
c_hashfunc = ctypes.c_void_p(openssl_hashlib_to_crypto_map_get(digest))
return crypto.PKCS5_PBKDF2_HMAC(c_pass, c_passlen,
c_salt, c_saltlen,
c_iter,
c_hashfunc,
c_keylen,
c_buff)
try: # check that we have proper OpenSSL or Common Crypto on the system.
system = platform.system()
if system == 'Windows':
if platform.architecture()[0] == '64bit':
crypto = ctypes.CDLL(os.path.basename(
ctypes.util.find_library('libeay64')))
else:
crypto = ctypes.CDLL(os.path.basename(
ctypes.util.find_library('libeay32')))
_pbkdf2_hmac = openssl_pbkdf2
crypto.PKCS5_PBKDF2_HMAC # test compatibility
elif system == 'Darwin': # think different(TM)! i.e. break things!
raise ImportError('Not yet available on OS X')
else:
crypto = ctypes.CDLL(os.path.basename(
ctypes.util.find_library('crypto')))
_pbkdf2_hmac = openssl_pbkdf2
crypto.PKCS5_PBKDF2_HMAC # test compatibility
except (OSError, AttributeError), e:
raise ImportError('Cannot find a compatible OpenSSL installation '
'on your system')
def pkcs5_pbkdf2_hmac(data, salt, iterations=1000, keylen=24, hashfunc=None):
c_pass = ctypes.c_char_p(data)
c_passlen = ctypes.c_int(len(data))
c_salt = ctypes.c_char_p(salt)
c_saltlen = ctypes.c_int(len(salt))
c_iter = ctypes.c_int(iterations)
c_keylen = ctypes.c_int(keylen)
c_buff = ctypes.create_string_buffer('\000' * keylen)
err = _pbkdf2_hmac(c_pass, c_passlen,
c_buff = ctypes.create_string_buffer(keylen)
# PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
# const unsigned char *salt, int saltlen, int iter,
# const EVP_MD *digest,
# int keylen, unsigned char *out);
crypto.PKCS5_PBKDF2_HMAC.argtypes = [ctypes.c_char_p, ctypes.c_int,
ctypes.c_char_p, ctypes.c_int,
ctypes.c_int, ctypes.c_void_p,
ctypes.c_int, ctypes.c_char_p]
crypto.PKCS5_PBKDF2_HMAC.restype = ctypes.c_int
err = crypto.PKCS5_PBKDF2_HMAC(c_pass, c_passlen,
c_salt, c_saltlen,
c_iter,
hashfunc,
c_hashfunc,
c_keylen,
c_buff)
return (err, c_buff)
try: # check that we have proper OpenSSL or Common Crypto on the system.
system = platform.system()
if system == 'Windows':
if platform.architecture()[0] == '64bit':
libname = ctypes.util.find_library('libeay64')
if not libname:
raise OSError('Library not found')
crypto = ctypes.CDLL(os.path.basename(libname))
else:
libname = ctypes.util.find_library('libeay32')
if not libname:
raise OSError('Library not found')
crypto = ctypes.CDLL(os.path.basename(libname))
_pbkdf2_hmac = openssl_pbkdf2
crypto.PKCS5_PBKDF2_HMAC # test compatibility
elif system == 'Darwin': # think different(TM)! i.e. break things!
libname = ctypes.util.find_library('System')
if not libname:
raise OSError('Library not found')
crypto = ctypes.CDLL(os.path.basename(libname))
_pbkdf2_hmac = commoncrypto_pbkdf2
else:
libname = ctypes.util.find_library('crypto')
if not libname:
raise OSError('not found')
crypto = ctypes.CDLL(os.path.basename(libname))
_pbkdf2_hmac = openssl_pbkdf2
crypto.PKCS5_PBKDF2_HMAC # test compatibility
except (OSError, AttributeError), e:
raise ImportError('Cannot find a compatible cryptographic library '
'on your system')
def pkcs5_pbkdf2_hmac(data, salt, iterations=1000, keylen=24, hashfunc=None):
err, c_buff = _pbkdf2_hmac(data, salt, iterations, hashfunc, keylen)
if err == 0:
raise ValueError('wrong parameters')
@@ -135,8 +169,8 @@ if __name__ == '__main__':
crypto.SSLeay_version.restype = ctypes.c_char_p
print crypto.SSLeay_version(0)
except:
print "Not using OpenSSL"
pass
for h in [hashlib.sha1, hashlib.sha224, hashlib.sha256,
hashlib.sha384, hashlib.sha512]:
pkcs5_pbkdf2_hmac('secret' * 11, 'salt', hashfunc=h)
print pkcs5_pbkdf2_hmac('secret' * 11, 'salt', hashfunc=h).encode('hex')

View File

@@ -5347,6 +5347,9 @@ class MongoDBAdapter(NoSQLAdapter):
# mongodb doesn't has a time object and so it must datetime,
# string or integer
return datetime.datetime.combine(d, value)
elif fieldtype == "blob":
from bson import Binary
return Binary(value)
elif (isinstance(fieldtype, basestring) and
fieldtype.startswith('list:')):
if fieldtype.startswith('list:reference'):

View File

@@ -454,6 +454,15 @@ class Scheduler(MetaScheduler):
self.define_tables(db, migrate=migrate)
def __get_migrate(self, tablename, migrate=True):
if migrate is False:
return False
elif migrate is True:
return True
elif isinstance(migrate, str):
return "%s%s.table" % (migrate , tablename)
return True
def now(self):
return self.utc_time and datetime.datetime.utcnow() or datetime.datetime.now()
@@ -505,7 +514,8 @@ class Scheduler(MetaScheduler):
Field('last_run_time', 'datetime', writable=False, readable=False),
Field('assigned_worker_name', default='', writable=False),
on_define=self.set_requirements,
migrate=migrate, format='%(task_name)s')
migrate=self.__get_migrate('scheduler_task', migrate),
format='%(task_name)s')
db.define_table(
'scheduler_run',
@@ -517,7 +527,8 @@ class Scheduler(MetaScheduler):
Field('run_result', 'text'),
Field('traceback', 'text'),
Field('worker_name', default=self.worker_name),
migrate=migrate)
migrate=self.__get_migrate('scheduler_run', migrate)
)
db.define_table(
'scheduler_worker',
@@ -526,9 +537,11 @@ class Scheduler(MetaScheduler):
Field('last_heartbeat', 'datetime'),
Field('status', requires=IS_IN_SET(WORKER_STATUS)),
Field('is_ticker', 'boolean', default=False, writable=False),
Field('group_names', 'list:string', default=self.group_names),#FIXME writable=False or give the chance to update dinamically the groups?
migrate=migrate)
if migrate:
Field('group_names', 'list:string', default=self.group_names),
migrate=self.__get_migrate('scheduler_worker', migrate)
)
if migrate is not False:
db.commit()
def loop(self, worker_name=None):

View File

@@ -5106,7 +5106,7 @@ class Wiki(object):
requires=[IS_SLUG(),
IS_NOT_IN_DB(db, 'wiki_page.slug')],
writable=False),
Field('title', unique=True),
Field('title', length=255, unique=True),
Field('body', 'text', notnull=True),
Field('tags', 'list:string'),
Field('can_read', 'list:string',