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

This commit is contained in:
Michele Comitini
2013-08-03 12:29:15 +02:00
10 changed files with 104 additions and 57 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.6.0-development+timestamp.2013.07.31.11.44.33
Version 2.6.0-development+timestamp.2013.08.01.08.22.32
@@ -34,14 +34,14 @@ def editlanguagefile(path,file):
def file_upload_form(location):
form=FORM(T("upload file:")," ",
INPUT(_type="file",_name="file")," ",T("and rename it:")," ",
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY()),
INPUT(_type="hidden",_name="location",_value=location),
INPUT(_type="hidden",_name="sender",_value=URL('design',args=app)),
INPUT(_type="submit",_value=T("upload")),_action=URL('upload_file'))
return form
def file_create_form(location):
form=FORM(T("create file with filename:")," ",
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY()),
INPUT(_type="hidden",_name="location",_value=location),
INPUT(_type="hidden",_name="sender",_value=URL('design',args=app)))
return form
@@ -35,14 +35,14 @@ def editlanguagefile(path,file):
def file_upload_form(location):
form=FORM(T("upload file:")," ",
INPUT(_type="file",_name="file")," ",T("and rename it:")," ",
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY()),
INPUT(_type="hidden",_name="location",_value=location),
INPUT(_type="hidden",_name="sender",_value=URL('design/'+app)),
INPUT(_type="submit",_value=T("submit")),_action=URL('upload_file'))
return form
def file_create_form(location):
form=FORM(T("create file with filename:")," ",
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY()),
INPUT(_type="hidden",_name="location",_value=location),
INPUT(_type="hidden",_name="sender",_value=URL('design/'+app)),
INPUT(_type="submit",_value=T("submit")),_action=URL('create_file'))
+2 -2
View File
@@ -25,7 +25,7 @@ def file_upload_form(location, anchor=None):
LABEL(T("upload file:")),
INPUT(_type="file",_name="file"),
LABEL(T("and rename it:")),
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY,_class=""),
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY(),_class=""),
DIV(TAG['BUTTON'](T("Upload"),_type="submit",_class="btn"),_class="controls"),
INPUT(_type="hidden",_name="location",_value=location),
INPUT(_type="hidden",_name="token",_value=session.token),
@@ -36,7 +36,7 @@ def file_upload_form(location, anchor=None):
def file_create_form(location, anchor=None, helptext=""):
form=FORM(
LABEL(T("create file with filename:")),
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY,_class=''),
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY(),_class=''),
TAG['SMALL'](helptext,_class="help-block"),
DIV(TAG['BUTTON'](T("Create"),_type="submit",_class="btn"),_class="controls"),
INPUT(_type="hidden",_name="location",_value=location),
+2 -2
View File
@@ -20,7 +20,7 @@ def editlanguagefile(path,file):
def file_upload_form(location):
form=FORM(T("upload file:")," ",
INPUT(_type="file",_name="file")," ",T("and rename it:")," ",
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY()),
INPUT(_type="hidden",_name="location",_value=location),
INPUT(_type="hidden",_name="token",_value=session.token),
INPUT(_type="hidden",_name="sender",_value=URL('design/'+app)),
@@ -28,7 +28,7 @@ def file_upload_form(location):
return form
def file_create_form(location):
form=FORM(T("create file with filename:")," ",
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY()),
INPUT(_type="hidden",_name="location",_value=location),
INPUT(_type="hidden",_name="token",_value=session.token),
INPUT(_type="hidden",_name="sender",_value=URL('design/'+app)),
@@ -1,6 +1,7 @@
### Community Documentation
- [[web2pybrasil http://www.web2pybrasil.com.br popup]]
- [[Roadmap https://trello.com/b/d3aqBbBl/web2py-roadmap]]
- [[web2pybrasil http://www.web2pybrasil.com.br popup]]
- Apostila em português [[Download http://dl.dropbox.com/u/830444/apostila_web2py_basico.pdf popup]] e [[Online http://web2pybrasil.appspot.com/init/plugin_wiki/page/curso-web2py-000 popup]]
- [[Sitio en español http://www.web2py.com.ar popup]]
- [[Documentación en español http://www.web2py.com.ar/examples/default/docs popup]]
@@ -109,7 +109,7 @@ class OAuthAccount(object):
self.session.access_token = None
return None
def __init__(self, g, client_id, client_secret, auth_url, token_url, access_token_url):
def __init__(self, g, client_id, client_secret, auth_url, token_url, access_token_url, socket_timeout=60):
self.globals = g
self.client_id = client_id
self.client_secret = client_secret
@@ -119,6 +119,7 @@ class OAuthAccount(object):
self.auth_url = auth_url
self.token_url = token_url
self.access_token_url = access_token_url
self.socket_timeout = socket_timeout
# consumer init
self.consumer = oauth.Consumer(self.client_id, self.client_secret)
@@ -154,7 +155,7 @@ class OAuthAccount(object):
if not self.accessToken():
# setup the client
client = oauth.Client(self.consumer, None)
client = oauth.Client(self.consumer, None, timeout=self.socket_timeout)
# Get a request token.
# oauth_callback *is REQUIRED* for OAuth1.0a
# putting it in the body seems to work.
+75 -24
View File
@@ -9,6 +9,8 @@
Note: This module is intended as a plugin replacement of pbkdf2.py
by Armin Ronacher.
Git repository:
$ git clone https://github.com/michele-comitini/pbkdf2_ctypes.git
:copyright: Copyright (c) 2013: Michele Comitini <mcm@glisco.it>
:license: LGPLv3
@@ -21,7 +23,62 @@ import hashlib
import platform
import os.path
try: # check that we have proper OpenSSL on the system.
def commoncrypto_hashlib_to_crypto_map_get(hashfunc):
hashlib_to_crypto_map = {hashlib.sha1: 1,
hashlib.sha224: 2,
hashlib.sha256: 3,
hashlib.sha384: 4,
hashlib.sha512: 5}
crypto_hashfunc = hashlib_to_crypto_map.get(hashfunc)
if crypto_hashfunc is None:
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):
"""Common Crypto compatibile wrapper
"""
c_hashfunc = ctypes.c_int(commoncrypto_hashlib_to_crypto_map_get(digest))
return 1 - crypto.CCKeyDerivationPBKDF(2, # hardcoded 2-> PBKDF2
c_pass, c_passlen,
c_salt, c_saltlen,
c_hashfunc,
c_iter,
c_buff,
c_keylen)
def openssl_hashlib_to_crypto_map_get(hashfunc):
hashlib_to_crypto_map = {hashlib.md5: crypto.EVP_md5,
hashlib.sha1: crypto.EVP_sha1,
hashlib.sha256: crypto.EVP_sha256,
hashlib.sha224: crypto.EVP_sha224,
hashlib.sha384: crypto.EVP_sha384,
hashlib.sha512: crypto.EVP_sha512}
crypto_hashfunc = hashlib_to_crypto_map.get(hashfunc)
if crypto_hashfunc is None:
raise ValueError('Unkwnown digest %s' % hashfunc)
crypto_hashfunc.restype = ctypes.c_void_p
return crypto_hashfunc()
def openssl_pbkdf2(c_pass, c_passlen,
c_salt, c_saltlen,
c_iter, digest, c_keylen, c_buff):
"""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':
@@ -30,19 +87,17 @@ try: # check that we have proper OpenSSL on the system.
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
PKCS5_PBKDF2_HMAC = crypto.PKCS5_PBKDF2_HMAC
hashlib_to_crypto_map = {hashlib.md5: crypto.EVP_md5,
hashlib.sha1: crypto.EVP_sha1,
hashlib.sha256: crypto.EVP_sha256,
hashlib.sha224: crypto.EVP_sha224,
hashlib.sha384: crypto.EVP_sha384,
hashlib.sha512: crypto.EVP_sha512}
except OSError, AttributeError:
except (OSError, AttributeError), e:
raise ImportError('Cannot find a compatible OpenSSL installation '
'on your system')
@@ -54,20 +109,11 @@ def pkcs5_pbkdf2_hmac(data, salt, iterations=1000, keylen=24, hashfunc=None):
c_saltlen = ctypes.c_int(len(salt))
c_iter = ctypes.c_int(iterations)
c_keylen = ctypes.c_int(keylen)
if hashfunc:
crypto_hashfunc = hashlib_to_crypto_map.get(hashfunc)
crypto_hashfunc.restype = ctypes.c_void_p
if crypto_hashfunc is None:
raise ValueError('Unknown digest' + str(hashfunc))
c_digest = ctypes.c_void_p(crypto_hashfunc())
else:
crypto.EVP_sha1.restype = ctypes.c_void_p
c_digest = ctypes.c_void_p(crypto.EVP_sha1())
c_buff = ctypes.create_string_buffer('\000' * keylen)
err = PKCS5_PBKDF2_HMAC(c_pass, c_passlen,
err = _pbkdf2_hmac(c_pass, c_passlen,
c_salt, c_saltlen,
c_iter,
c_digest,
hashfunc,
c_keylen,
c_buff)
@@ -85,7 +131,12 @@ def pbkdf2_bin(data, salt, iterations=1000, keylen=24, hashfunc=None):
return pkcs5_pbkdf2_hmac(data, salt, iterations, keylen, hashfunc)
if __name__ == '__main__':
crypto.SSLeay_version.restype = ctypes.c_char_p
print crypto.SSLeay_version(0)
for h in hashlib_to_crypto_map:
try:
crypto.SSLeay_version.restype = ctypes.c_char_p
print crypto.SSLeay_version(0)
except:
print "Not using OpenSSL"
for h in [hashlib.sha1, hashlib.sha224, hashlib.sha256,
hashlib.sha384, hashlib.sha512]:
pkcs5_pbkdf2_hmac('secret' * 11, 'salt', hashfunc=h)
+9 -14
View File
@@ -567,7 +567,7 @@ class ConnectionPool(object):
""" this actually does not make the folder. it has to be there """
self.folder = getattr(THREAD_LOCAL,'folder','')
if (os.path.isabs(self.folder) and
if (os.path.isabs(self.folder) and
isinstance(self, UseDatabaseStoredFile) and
self.folder.startswith(os.getcwd())):
self.folder = os.path.relpath(self.folder, os.getcwd())
@@ -1676,10 +1676,9 @@ class BaseAdapter(ConnectionPool):
sql_o += ' ORDER BY %s' % self.RANDOM()
else:
sql_o += ' ORDER BY %s' % self.expand(orderby)
if limitby:
if orderby_on_limitby and not orderby and tablenames:
sql_o += ' ORDER BY %s' % ', '.join(['%s.%s'%(t,x) for t in tablenames for x in (hasattr(self.db[t],'_primarykey') and self.db[t]._primarykey or [self.db[t]._id.name])])
# oracle does not support limitby
if (limitby and not groupby and tablenames and orderby_on_limitby and not orderby):
sql_o += ' ORDER BY %s' % ', '.join(['%s.%s'%(t,x) for t in tablenames for x in (hasattr(self.db[t],'_primarykey') and self.db[t]._primarykey or [self.db[t]._id.name])])
# oracle does not support limitby
sql = self.select_limitby(sql_s, sql_f, sql_t, sql_w, sql_o, limitby)
if for_update and self.can_select_for_update is True:
sql = sql.rstrip(';') + ' FOR UPDATE;'
@@ -2058,7 +2057,6 @@ class BaseAdapter(ConnectionPool):
def parse(self, rows, fields, colnames, blob_decode=True,
cacheable = False):
self.build_parsemap()
db = self.db
virtualtables = []
new_rows = []
@@ -3174,10 +3172,6 @@ class MSSQLAdapter(BaseAdapter):
if limitby:
(lmin, lmax) = limitby
sql_s += ' TOP %i' % lmax
if 'GROUP BY' in sql_o:
orderfound = sql_o.find('ORDER BY ')
if orderfound >= 0:
sql_o = sql_o[:orderfound]
return 'SELECT %s %s FROM %s%s%s;' % (sql_s, sql_f, sql_t, sql_w, sql_o)
TRUE = 1
@@ -7410,6 +7404,7 @@ class DAL(object):
types = ADAPTERS[self._dbname].types
# copy so multiple DAL() possible
self._adapter.types = copy.copy(types)
self._adapter.build_parsemap()
if bigint_id:
if 'big-id' in types and 'reference' in types:
self._adapter.types['id'] = types['big-id']
@@ -8078,7 +8073,7 @@ def index():
# skip all non-empty lines
for line in ifile:
if not line.strip():
breal
break
else:
raise RuntimeError("Unable to import table that does not exist.\nTry db.import_from_csv_file(..., map_tablenames={'table':'othertable'},ignore_missing_tables=True)")
@@ -8372,7 +8367,7 @@ class Table(object):
self._references = []
for field in self:
fieldname = field.name
field_type = field.type
field_type = field.type
if isinstance(field_type,str) and field_type[:10] == 'reference ':
ref = field_type[10:].strip()
if not ref.strip():
@@ -8380,7 +8375,7 @@ class Table(object):
if '.' in ref:
rtablename, rfieldname = ref.split('.',1)
else:
rtablename, rfieldname = ref, None
rtablename, rfieldname = ref, None
if not rtablename in db:
pr[rtablename] = pr.get(rtablename,[]) + [field]
continue
@@ -8403,7 +8398,7 @@ class Table(object):
field.referent = None
for referee in pr.get(self._tablename,[]):
self._referenced_by.append(referee)
def _filter_fields(self, record, id=False):
return dict([(k, v) for (k, v) in record.iteritems() if k
in self.fields and (self[k].type!='id' or id)])
+6 -7
View File
@@ -73,13 +73,10 @@ import optparse
import types
import Queue
if 'WEB2PY_PATH' in os.environ:
sys.path.append(os.environ['WEB2PY_PATH'])
else:
os.environ['WEB2PY_PATH'] = os.getcwd()
path = os.getcwd()
if not os.environ['WEB2PY_PATH'] in sys.path:
sys.path.append(os.environ['WEB2PY_PATH'])
if 'WEB2PY_PATH' not in os.environ:
os.environ['WEB2PY_PATH'] = path
try:
from gluon.contrib.simplejson import loads, dumps
@@ -90,7 +87,8 @@ IDENTIFIER = "%s#%s" % (socket.gethostname(),os.getpid())
logger = logging.getLogger('web2py.scheduler.%s' % IDENTIFIER)
from gluon import DAL, Field, IS_NOT_EMPTY, IS_IN_SET, IS_NOT_IN_DB, IS_INT_IN_RANGE, IS_DATETIME
from gluon import DAL, Field, IS_NOT_EMPTY, IS_IN_SET, IS_NOT_IN_DB
from gluon import IS_INT_IN_RANGE, IS_DATETIME
from gluon.utils import web2py_uuid
from gluon.storage import Storage
@@ -254,6 +252,7 @@ class MetaScheduler(threading.Thread):
self.have_heartbeat = True # set to False to kill
self.empty_runs = 0
def async(self, task):
"""
starts the background process and returns: