author | Denis Laxalde <denis.laxalde@logilab.fr> |
Sat, 16 Jan 2016 13:48:51 +0100 | |
changeset 11057 | 0b59724cb3f2 |
parent 11052 | 058bb3dc685f |
child 11058 | 23eb30449fe5 |
--- a/MANIFEST.in Mon Jan 04 18:40:30 2016 +0100 +++ b/MANIFEST.in Sat Jan 16 13:48:51 2016 +0100 @@ -19,33 +19,33 @@ recursive-include doc/images *.png *.svg include doc/conf.py -recursive-include misc *.py *.png *.display +recursive-include cubicweb/misc *.py *.png *.display -include web/views/*.pt -recursive-include web/data external_resources *.js *.css *.py *.png *.gif *.ico *.ttf *.svg *.woff *.eot -recursive-include web/wdoc *.rst *.png *.xml ChangeLog* -recursive-include devtools/data *.js *.css *.sh +include cubicweb/web/views/*.pt +recursive-include cubicweb/web/data external_resources *.js *.css *.py *.png *.gif *.ico *.ttf *.svg *.woff *.eot +recursive-include cubicweb/web/wdoc *.rst *.png *.xml ChangeLog* +recursive-include cubicweb/devtools/data *.js *.css *.sh -recursive-include i18n *.pot *.po -recursive-include schemas *.py *.sql +recursive-include cubicweb/i18n *.pot *.po +recursive-include cubicweb/schemas *.py *.sql -recursive-include test/data bootstrap_cubes *.py *.sql -recursive-include entities/test/data bootstrap_cubes *.py -recursive-include sobjects/test/data bootstrap_cubes *.py -recursive-include hooks/test/data bootstrap_cubes *.py -recursive-include server/test/data bootstrap_cubes *.py source* *.conf.in *.ldif -recursive-include devtools/test/data bootstrap_cubes *.py *.txt *.js *.po.ref -recursive-include web/test/data bootstrap_cubes pouet.css *.py -recursive-include etwist/test/data *.py +recursive-include cubicweb/test/data bootstrap_cubes *.py *.sql +recursive-include cubicweb/entities/test/data bootstrap_cubes *.py +recursive-include cubicweb/sobjects/test/data bootstrap_cubes *.py +recursive-include cubicweb/hooks/test/data bootstrap_cubes *.py +recursive-include cubicweb/server/test/data bootstrap_cubes *.py source* *.conf.in *.ldif +recursive-include cubicweb/devtools/test/data bootstrap_cubes *.py *.txt *.js *.po.ref +recursive-include cubicweb/web/test/data bootstrap_cubes pouet.css *.py +recursive-include cubicweb/etwist/test/data *.py -recursive-include web/test/jstests *.js *.html *.css *.json -recursive-include web/test/windmill *.py +recursive-include cubicweb/web/test/jstests *.js *.html *.css *.json +recursive-include cubicweb/web/test/windmill *.py -recursive-include skeleton *.py *.css *.js *.po compat *.in *.tmpl rules +recursive-include cubicweb/skeleton *.py *.css *.js *.po compat *.in *.tmpl rules prune doc/book/en/.static prune doc/book/fr/.static prune doc/html/_sources/ -prune misc/cwfs +prune cubicweb/misc/cwfs prune doc/js_api global-exclude *.pyc
--- a/__init__.py Mon Jan 04 18:40:30 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,265 +0,0 @@ -# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. -# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr -# -# This file is part of CubicWeb. -# -# CubicWeb is free software: you can redistribute it and/or modify it under the -# terms of the GNU Lesser General Public License as published by the Free -# Software Foundation, either version 2.1 of the License, or (at your option) -# any later version. -# -# CubicWeb is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -# details. -# -# You should have received a copy of the GNU Lesser General Public License along -# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. -"""CubicWeb is a generic framework to quickly build applications which describes -relations between entitites. -""" -__docformat__ = "restructuredtext en" - -# ignore the pygments UserWarnings -import warnings -import zlib -warnings.filterwarnings('ignore', category=UserWarning, - message='.*was already imported', - module='.*pygments') - - -from six import PY2, binary_type, text_type -from six.moves import builtins - -CW_SOFTWARE_ROOT = __path__[0] - -import sys, os, logging -from io import BytesIO - -from six.moves import cPickle as pickle - -from logilab.common.deprecation import deprecated -from logilab.common.logging_ext import set_log_methods -from yams.constraints import BASE_CONVERTERS, BASE_CHECKERS - -# pre python 2.7.2 safety -logging.basicConfig() - -from cubicweb.__pkginfo__ import version as __version__ - - -set_log_methods(sys.modules[__name__], logging.getLogger('cubicweb')) - -# make all exceptions accessible from the package -from cubicweb._exceptions import * -from logilab.common.registry import ObjectNotFound, NoSelectableObject, RegistryNotFound - - -# '_' is available to mark internationalized string but should not be used to -# do the actual translation -_ = text_type -if not hasattr(builtins, '_'): - builtins._ = deprecated("[3.22] Use 'from cubicweb import _'")(_) - - -# convert eid to the right type, raise ValueError if it's not a valid eid -@deprecated('[3.17] typed_eid() was removed. replace it with int() when needed.') -def typed_eid(eid): - return int(eid) - -#def log_thread(f, w, a): -# print f.f_code.co_filename, f.f_code.co_name -#import threading -#threading.settrace(log_thread) - -class Binary(BytesIO): - """class to hold binary data. Use BytesIO to prevent use of unicode data""" - _allowed_types = (binary_type, bytearray, buffer if PY2 else memoryview) - - def __init__(self, buf=b''): - assert isinstance(buf, self._allowed_types), \ - "Binary objects must use bytes/buffer objects, not %s" % buf.__class__ - super(Binary, self).__init__(buf) - - def write(self, data): - assert isinstance(data, self._allowed_types), \ - "Binary objects must use bytes/buffer objects, not %s" % data.__class__ - super(Binary, self).write(data) - - def to_file(self, fobj): - """write a binary to disk - - the writing is performed in a safe way for files stored on - Windows SMB shares - """ - pos = self.tell() - self.seek(0) - if sys.platform == 'win32': - while True: - # the 16kB chunksize comes from the shutil module - # in stdlib - chunk = self.read(16*1024) - if not chunk: - break - fobj.write(chunk) - else: - fobj.write(self.read()) - self.seek(pos) - - @staticmethod - def from_file(filename): - """read a file and returns its contents in a Binary - - the reading is performed in a safe way for files stored on - Windows SMB shares - """ - binary = Binary() - with open(filename, 'rb') as fobj: - if sys.platform == 'win32': - while True: - # the 16kB chunksize comes from the shutil module - # in stdlib - chunk = fobj.read(16*1024) - if not chunk: - break - binary.write(chunk) - else: - binary.write(fobj.read()) - binary.seek(0) - return binary - - def __eq__(self, other): - if not isinstance(other, Binary): - return False - return self.getvalue() == other.getvalue() - - - # Binary helpers to store/fetch python objects - - @classmethod - def zpickle(cls, obj): - """ return a Binary containing a gzipped pickle of obj """ - retval = cls() - retval.write(zlib.compress(pickle.dumps(obj, protocol=2))) - return retval - - def unzpickle(self): - """ decompress and loads the stream before returning it """ - return pickle.loads(zlib.decompress(self.getvalue())) - - -def check_password(eschema, value): - return isinstance(value, (binary_type, Binary)) -BASE_CHECKERS['Password'] = check_password - -def str_or_binary(value): - if isinstance(value, Binary): - return value - return binary_type(value) -BASE_CONVERTERS['Password'] = str_or_binary - - -# use this dictionary to rename entity types while keeping bw compat -ETYPE_NAME_MAP = {} - -# XXX cubic web cube migration map. See if it's worth keeping this mecanism -# to help in cube renaming -CW_MIGRATION_MAP = {} - -def neg_role(role): - if role == 'subject': - return 'object' - return 'subject' - -def role(obj): - try: - return obj.role - except AttributeError: - return neg_role(obj.target) - -def target(obj): - try: - return obj.target - except AttributeError: - return neg_role(obj.role) - - -class CubicWebEventManager(object): - """simple event / callback manager. - - Typical usage to register a callback:: - - >>> from cubicweb import CW_EVENT_MANAGER - >>> CW_EVENT_MANAGER.bind('after-registry-reload', mycallback) - - Typical usage to emit an event:: - - >>> from cubicweb import CW_EVENT_MANAGER - >>> CW_EVENT_MANAGER.emit('after-registry-reload') - - emit() accepts an additional context parameter that will be passed - to the callback if specified (and only in that case) - """ - def __init__(self): - self.callbacks = {} - - def bind(self, event, callback, *args, **kwargs): - self.callbacks.setdefault(event, []).append( (callback, args, kwargs) ) - - def emit(self, event, context=None): - for callback, args, kwargs in self.callbacks.get(event, ()): - if context is None: - callback(*args, **kwargs) - else: - callback(context, *args, **kwargs) - -CW_EVENT_MANAGER = CubicWebEventManager() - -def onevent(event, *args, **kwargs): - """decorator to ease event / callback binding - - >>> from cubicweb import onevent - >>> @onevent('before-registry-reload') - ... def mycallback(): - ... print 'hello' - ... - >>> - """ - def _decorator(func): - CW_EVENT_MANAGER.bind(event, func, *args, **kwargs) - return func - return _decorator - - -from yams.schema import role_name as rname - -def validation_error(entity, errors, substitutions=None, i18nvalues=None): - """easy way to retrieve a :class:`cubicweb.ValidationError` for an entity or eid. - - You may also have 2-tuple as error keys, :func:`yams.role_name` will be - called automatically for them. - - Messages in errors **should not be translated yet**, though marked for - internationalization. You may give an additional substition dictionary that - will be used for interpolation after the translation. - """ - if substitutions is None: - # set empty dict else translation won't be done for backward - # compatibility reason (see ValidationError.translate method) - substitutions = {} - for key in list(errors): - if isinstance(key, tuple): - errors[rname(*key)] = errors.pop(key) - return ValidationError(getattr(entity, 'eid', entity), errors, - substitutions, i18nvalues) - - -# exceptions ################################################################## - -class ProgrammingError(Exception): #DatabaseError): - """Exception raised for errors that are related to the database's operation - and not necessarily under the control of the programmer, e.g. an unexpected - disconnect occurs, the data source name is not found, a transaction could - not be processed, a memory allocation error occurred during processing, - etc. - """
--- a/__pkginfo__.py Mon Jan 04 18:40:30 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -# pylint: disable=W0622,C0103 -# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. -# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr -# -# This file is part of CubicWeb. -# -# CubicWeb is free software: you can redistribute it and/or modify it under the -# terms of the GNU Lesser General Public License as published by the Free -# Software Foundation, either version 2.1 of the License, or (at your option) -# any later version. -# -# CubicWeb is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -# details. -# -# You should have received a copy of the GNU Lesser General Public License along -# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. -"""cubicweb global packaging information for the cubicweb knowledge management -software -""" - -modname = distname = "cubicweb" - -numversion = (3, 22, 0) -version = '.'.join(str(num) for num in numversion) - -description = "a repository of entities / relations for knowledge management" -author = "Logilab" -author_email = "contact@logilab.fr" -web = 'http://www.cubicweb.org' -license = 'LGPL' - -classifiers = [ - 'Environment :: Web Environment', - 'Framework :: CubicWeb', - 'Programming Language :: Python', - 'Programming Language :: JavaScript', -] - -__depends__ = { - 'six': '>= 1.4.0', - 'logilab-common': '>= 0.63.1', - 'logilab-mtconverter': '>= 0.8.0', - 'rql': '>= 0.34.0', - 'yams': '>= 0.42.0', - #gettext # for xgettext, msgcat, etc... - # web dependencies - 'lxml': '', - # XXX graphviz - # server dependencies - 'logilab-database': '>= 1.15.0', - 'passlib': '', - 'pytz': '', - 'Markdown': '' - } - -__recommends__ = { - 'docutils': '>= 0.6', - 'Pillow': '', # for captcha - 'pycrypto': '', # for crypto extensions - 'fyzz': '>= 0.1.0', # for sparql - 'vobject': '>= 0.6.0', # for ical view - 'rdflib': None, # - 'pyzmq': None, - 'Twisted': '', - #'Products.FCKeditor':'', - #'SimpleTAL':'>= 4.1.6', - } - -import sys -from os import listdir, environ -from os.path import join, isdir -import glob - -scripts = [s for s in glob.glob(join('bin', 'cubicweb-*')) - if not s.endswith('.bat')] -include_dirs = [join('test', 'data'), - join('server', 'test', 'data'), - join('hooks', 'test', 'data'), - join('web', 'test', 'data'), - join('devtools', 'data'), - join('devtools', 'test', 'data'), - 'schemas', 'skeleton'] - - -_server_migration_dir = join('misc', 'migration') -_data_dir = join('web', 'data') -_wdoc_dir = join('web', 'wdoc') -_wdocimages_dir = join(_wdoc_dir, 'images') -_views_dir = join('web', 'views') -_i18n_dir = 'i18n' - -_pyversion = '.'.join(str(num) for num in sys.version_info[0:2]) -if '--home' in sys.argv: - # --home install - pydir = 'python' + _pyversion -else: - pydir = join('python' + _pyversion, 'site-packages') - -# data files that shall be copied into the main package directory -package_data = { - 'cubicweb.web.views':['*.pt'], - } - -try: - # data files that shall be copied outside the main package directory - data_files = [ - # server data - [join('share', 'cubicweb', 'schemas'), - glob.glob(join('schemas', '*.sql'))], - [join('share', 'cubicweb', 'migration'), - [join(_server_migration_dir, filename) - for filename in listdir(_server_migration_dir)]], - # web data - [join('share', 'cubicweb', 'cubes', 'shared', 'data'), - [join(_data_dir, fname) for fname in listdir(_data_dir) - if not isdir(join(_data_dir, fname))]], - [join('share', 'cubicweb', 'cubes', 'shared', 'data', 'images'), - [join(_data_dir, 'images', fname) for fname in listdir(join(_data_dir, 'images'))]], - [join('share', 'cubicweb', 'cubes', 'shared', 'data', 'jquery-treeview'), - [join(_data_dir, 'jquery-treeview', fname) for fname in listdir(join(_data_dir, 'jquery-treeview')) - if not isdir(join(_data_dir, 'jquery-treeview', fname))]], - [join('share', 'cubicweb', 'cubes', 'shared', 'data', 'jquery-treeview', 'images'), - [join(_data_dir, 'jquery-treeview', 'images', fname) - for fname in listdir(join(_data_dir, 'jquery-treeview', 'images'))]], - [join('share', 'cubicweb', 'cubes', 'shared', 'wdoc'), - [join(_wdoc_dir, fname) for fname in listdir(_wdoc_dir) - if not isdir(join(_wdoc_dir, fname))]], - [join('share', 'cubicweb', 'cubes', 'shared', 'wdoc', 'images'), - [join(_wdocimages_dir, fname) for fname in listdir(_wdocimages_dir)]], - [join('share', 'cubicweb', 'cubes', 'shared', 'i18n'), - glob.glob(join(_i18n_dir, '*.po'))], - # skeleton - ] -except OSError: - # we are in an installed directory, don't care about this - pass
--- a/_exceptions.py Mon Jan 04 18:40:30 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,209 +0,0 @@ -# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. -# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr -# -# This file is part of CubicWeb. -# -# CubicWeb is free software: you can redistribute it and/or modify it under the -# terms of the GNU Lesser General Public License as published by the Free -# Software Foundation, either version 2.1 of the License, or (at your option) -# any later version. -# -# CubicWeb is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -# details. -# -# You should have received a copy of the GNU Lesser General Public License along -# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. -"""Exceptions shared by different cubicweb packages.""" - -__docformat__ = "restructuredtext en" - -from warnings import warn - -from six import PY3, text_type - -from logilab.common.decorators import cachedproperty - -from yams import ValidationError - -# abstract exceptions ######################################################### - -class CubicWebException(Exception): - """base class for cubicweb server exception""" - msg = "" - def __unicode__(self): - if self.msg: - if self.args: - return self.msg % tuple(self.args) - else: - return self.msg - else: - return u' '.join(text_type(arg) for arg in self.args) - __str__ = __unicode__ if PY3 else lambda self: self.__unicode__().encode('utf-8') - -class ConfigurationError(CubicWebException): - """a misconfiguration error""" - -class InternalError(CubicWebException): - """base class for exceptions which should not occur""" - -class SecurityError(CubicWebException): - """base class for cubicweb server security exceptions""" - -class RepositoryError(CubicWebException): - """base class for repository exceptions""" - -class SourceException(CubicWebException): - """base class for source exceptions""" - -class CubicWebRuntimeError(CubicWebException): - """base class for runtime exceptions""" - -# repository exceptions ####################################################### - -class ConnectionError(RepositoryError): - """raised when a bad connection id is given or when an attempt to establish - a connection failed - """ - -class AuthenticationError(ConnectionError): - """raised when an attempt to establish a connection failed due to wrong - connection information (login / password or other authentication token) - """ - -class BadConnectionId(ConnectionError): - """raised when a bad connection id is given""" - -class UnknownEid(RepositoryError): - """the eid is not defined in the system tables""" - msg = 'No entity with eid %s in the repository' - -class UniqueTogetherError(RepositoryError): - """raised when a unique_together constraint caused an IntegrityError""" - def __init__(self, session, **kwargs): - self.session = session - assert 'rtypes' in kwargs or 'cstrname' in kwargs - self.kwargs = kwargs - # fill cache while the session is open - self.rtypes - - @cachedproperty - def rtypes(self): - if 'rtypes' in self.kwargs: - return self.kwargs['rtypes'] - cstrname = unicode(self.kwargs['cstrname']) - cstr = self.session.find('CWUniqueTogetherConstraint', name=cstrname).one() - return sorted(rtype.name for rtype in cstr.relations) - - @cachedproperty - def args(self): - warn('[3.18] UniqueTogetherError.args is deprecated, just use ' - 'the .rtypes accessor.', - DeprecationWarning) - # the first argument, etype, is never used and was never garanteed anyway - return None, self.rtypes - - -class ViolatedConstraint(RepositoryError): - def __init__(self, cnx, cstrname): - self.cnx = cnx - self.cstrname = cstrname - - -# security exceptions ######################################################### - -class Unauthorized(SecurityError): - """raised when a user tries to perform an action without sufficient - credentials - """ - msg = 'You are not allowed to perform this operation' - msg1 = 'You are not allowed to perform %s operation on %s' - var = None - - def __str__(self): - try: - if self.args and len(self.args) == 2: - return self.msg1 % self.args - if self.args: - return ' '.join(self.args) - return self.msg - except Exception as ex: - return str(ex) - -class Forbidden(SecurityError): - """raised when a user tries to perform a forbidden action - """ - -# source exceptions ########################################################### - -class EidNotInSource(SourceException): - """trying to access an object with a particular eid from a particular - source has failed - """ - msg = 'No entity with eid %s in %s' - - -# registry exceptions ######################################################### - -# pre 3.15 bw compat -from logilab.common.registry import RegistryException, ObjectNotFound, NoSelectableObject - -class UnknownProperty(RegistryException): - """property found in database but unknown in registry""" - -# query exception ############################################################# - -class QueryError(CubicWebRuntimeError): - """a query try to do something it shouldn't""" - -class NotAnEntity(CubicWebRuntimeError): - """raised when get_entity is called for a column which doesn't contain - a non final entity - """ - -class MultipleResultsError(CubicWebRuntimeError): - """raised when ResultSet.one() is called on a resultset with multiple rows - of multiple columns. - """ - -class NoResultError(CubicWebRuntimeError): - """raised when no result is found but at least one is expected. - """ - -class UndoTransactionException(QueryError): - """Raised when undoing a transaction could not be performed completely. - - Note that : - 1) the partial undo operation might be acceptable - depending upon the final application - - 2) the undo operation can also fail with a `ValidationError` in - cases where the undoing breaks integrity constraints checked - immediately. - - 3) It might be that neither of those exception is raised but a - subsequent `commit` might raise a `ValidationError` in cases - where the undoing breaks integrity constraints checked at - commit time. - - :type txuuix: int - :param txuuid: Unique identifier of the partially undone transaction - - :type errors: list - :param errors: List of errors occurred during undoing - """ - msg = u"The following error(s) occurred while undoing transaction #%d : %s" - - def __init__(self, txuuid, errors): - super(UndoTransactionException, self).__init__(txuuid, errors) - self.txuuid = txuuid - self.errors = errors - -# tools exceptions ############################################################ - -class ExecutionError(Exception): - """server execution control error (already started, not running...)""" - -# pylint: disable=W0611 -from logilab.common.clcommands import BadCommandUsage
--- a/_gcdebug.py Mon Jan 04 18:40:30 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. -# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr -# -# This file is part of CubicWeb. -# -# CubicWeb is free software: you can redistribute it and/or modify it under the -# terms of the GNU Lesser General Public License as published by the Free -# Software Foundation, either version 2.1 of the License, or (at your option) -# any later version. -# -# CubicWeb is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -# details. -# -# You should have received a copy of the GNU Lesser General Public License along -# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. -from __future__ import print_function - -import gc, types, weakref - -from cubicweb.schema import CubicWebRelationSchema, CubicWebEntitySchema -try: - from cubicweb.web.request import _NeedAuthAccessMock -except ImportError: - _NeedAuthAccessMock = None - -listiterator = type(iter([])) - -IGNORE_CLASSES = ( - type, tuple, dict, list, set, frozenset, type(len), - weakref.ref, weakref.WeakKeyDictionary, - listiterator, - property, classmethod, - types.ModuleType, types.FunctionType, types.MethodType, - types.MemberDescriptorType, types.GetSetDescriptorType, - ) -if _NeedAuthAccessMock is not None: - IGNORE_CLASSES = IGNORE_CLASSES + (_NeedAuthAccessMock,) - -def _get_counted_class(obj, classes): - for cls in classes: - if isinstance(obj, cls): - return cls - raise AssertionError() - -def gc_info(countclasses, - ignoreclasses=IGNORE_CLASSES, - viewreferrersclasses=(), showobjs=False, maxlevel=1): - gc.collect() - gc.collect() - counters = {} - ocounters = {} - for obj in gc.get_objects(): - if isinstance(obj, countclasses): - cls = _get_counted_class(obj, countclasses) - try: - counters[cls.__name__] += 1 - except KeyError: - counters[cls.__name__] = 1 - elif not isinstance(obj, ignoreclasses): - try: - key = '%s.%s' % (obj.__class__.__module__, - obj.__class__.__name__) - except AttributeError: - key = str(obj) - try: - ocounters[key] += 1 - except KeyError: - ocounters[key] = 1 - if isinstance(obj, viewreferrersclasses): - print(' ', obj, referrers(obj, showobjs, maxlevel)) - garbage = [repr(obj) for obj in gc.garbage] - return counters, ocounters, garbage - - -def referrers(obj, showobj=False, maxlevel=1): - objreferrers = _referrers(obj, maxlevel) - try: - return sorted(set((type(x), showobj and x or getattr(x, '__name__', '%#x' % id(x))) - for x in objreferrers)) - except TypeError: - s = set() - unhashable = [] - for x in objreferrers: - try: - s.add(x) - except TypeError: - unhashable.append(x) - return sorted(s) + unhashable - -def _referrers(obj, maxlevel, _seen=None, _level=0): - interesting = [] - if _seen is None: - _seen = set() - for x in gc.get_referrers(obj): - if id(x) in _seen: - continue - _seen.add(id(x)) - if isinstance(x, types.FrameType): - continue - if isinstance(x, (CubicWebRelationSchema, CubicWebEntitySchema)): - continue - if isinstance(x, (list, tuple, set, dict, listiterator)): - if _level >= maxlevel: - pass - #interesting.append(x) - else: - interesting += _referrers(x, maxlevel, _seen, _level+1) - else: - interesting.append(x) - return interesting
--- a/appobject.py Mon Jan 04 18:40:30 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. -# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr -# -# This file is part of CubicWeb. -# -# CubicWeb is free software: you can redistribute it and/or modify it under the -# terms of the GNU Lesser General Public License as published by the Free -# Software Foundation, either version 2.1 of the License, or (at your option) -# any later version. -# -# CubicWeb is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -# details. -# -# You should have received a copy of the GNU Lesser General Public License along -# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. -""" - -The `AppObject` class ---------------------- - -The AppObject class is the base class for all dynamically loaded objects -(application objects) accessible through the vregistry. - -We can find a certain number of attributes and methods defined in this class and -common to all the application objects. - -""" -__docformat__ = "restructuredtext en" - -from logging import getLogger - -from logilab.common.deprecation import deprecated, class_renamed -from logilab.common.logging_ext import set_log_methods - -# first line imports for bw compat -from logilab.common.registry import (objectify_predicate, traced_selection, Predicate, - RegistrableObject, yes) - - -objectify_selector = deprecated('[3.15] objectify_selector has been ' - 'renamed to objectify_predicates in ' - 'logilab.common.registry')(objectify_predicate) -traced_selection = deprecated('[3.15] traced_selection has been ' - 'moved to logilab.common.registry')(traced_selection) -Selector = class_renamed('Selector', Predicate, - '[3.15] Selector has been renamed to Predicate ' - 'in logilab.common.registry') - -@deprecated('[3.15] lltrace decorator can now be removed') -def lltrace(func): - return func - -# the base class for all appobjects ############################################ - -class AppObject(RegistrableObject): - """This is the base class for CubicWeb application objects which are - selected in a request context. - - The following attributes should be set on concrete appobject classes: - - At selection time, the following attributes are set on the instance: - - :attr:`_cw` - current request - :attr:`cw_extra_kwargs` - other received arguments - - And also the following, only if `rset` is found in arguments (in which case - rset/row/col will be removed from `cwextra_kwargs`): - - :attr:`cw_rset` - context result set or None - - :attr:`cw_row` - if a result set is set and the context is about a particular cell in the - result set, and not the result set as a whole, specify the row number we - are interested in, else None - - :attr:`cw_col` - if a result set is set and the context is about a particular cell in the - result set, and not the result set as a whole, specify the col number we - are interested in, else None - - - .. Note:: - - * do not inherit directly from this class but from a more specific class - such as `AnyEntity`, `EntityView`, `AnyRsetView`, `Action`... - - """ - __select__ = yes() - - @classmethod - def __registered__(cls, registry): - """called by the registry when the appobject has been registered. - - It must return the object that will be actually registered (this may be - the right hook to create an instance for example). By default the - appobject is returned without any transformation. - """ - pdefs = getattr(cls, 'cw_property_defs', {}) - for propid, pdef in pdefs.items(): - pdef = pdef.copy() # may be shared - pdef['default'] = getattr(cls, propid, pdef['default']) - pdef['sitewide'] = getattr(cls, 'site_wide', pdef.get('sitewide')) - registry.vreg.register_property(cls._cwpropkey(propid), **pdef) - assert callable(cls.__select__), cls - return cls - - def __init__(self, req, **extra): - super(AppObject, self).__init__() - self._cw = req - try: - self.cw_rset = extra.pop('rset') - self.cw_row = extra.pop('row', None) - self.cw_col = extra.pop('col', None) - except KeyError: - pass - self.cw_extra_kwargs = extra - - # persistent class properties ############################################## - # - # optional `cw_property_defs` dict on a class defines available persistent - # properties for this class: - # - # * key: id of the property (the actual CWProperty key is build using - # <registry name>.<obj id>.<property id> - # * value: tuple (property type, vocabfunc, default value, property description) - # possible types are those used by `logilab.common.configuration` - # - # notice that when it exists multiple objects with the same id (adaptation, - # overriding) only the first encountered definition is considered, so those - # objects can't try to have different default values for instance. - # - # you can then access to a property value using self.cw_propval, where self - # is an instance of class - - @classmethod - def _cwpropkey(cls, propid): - """return cw property key for the property of the given id for this - class - """ - return '%s.%s.%s' % (cls.__registry__, cls.__regid__, propid) - - def cw_propval(self, propid): - """return cw property value associated to key - - <cls.__registry__>.<cls.id>.<propid> - """ - return self._cw.property_value(self._cwpropkey(propid)) - - # these are overridden by set_log_methods below - # only defining here to prevent pylint from complaining - info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None - -set_log_methods(AppObject, getLogger('cubicweb.appobject')) - -# defined here to avoid warning on usage on the AppObject class -yes = deprecated('[3.15] yes has been moved to logilab.common.registry')(yes)
--- a/crypto.py Mon Jan 04 18:40:30 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. -# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr -# -# This file is part of CubicWeb. -# -# CubicWeb is free software: you can redistribute it and/or modify it under the -# terms of the GNU Lesser General Public License as published by the Free -# Software Foundation, either version 2.1 of the License, or (at your option) -# any later version. -# -# CubicWeb is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -# details. -# -# You should have received a copy of the GNU Lesser General Public License along -# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. -"""Simple cryptographic routines, based on python-crypto.""" -__docformat__ = "restructuredtext en" - -from base64 import b64encode, b64decode - -from six.moves import cPickle as pickle - -from Crypto.Cipher import Blowfish - - -_CYPHERERS = {} -def _cypherer(seed): - try: - return _CYPHERERS[seed] - except KeyError: - _CYPHERERS[seed] = Blowfish.new(seed, Blowfish.MODE_ECB) - return _CYPHERERS[seed] - - -def encrypt(data, seed): - string = pickle.dumps(data) - string = string + '*' * (8 - len(string) % 8) - string = b64encode(_cypherer(seed).encrypt(string)) - return unicode(string) - - -def decrypt(string, seed): - # pickle ignores trailing characters so we do not need to strip them off - string = _cypherer(seed).decrypt(b64decode(string)) - return pickle.loads(string)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cubicweb/__init__.py Sat Jan 16 13:48:51 2016 +0100 @@ -0,0 +1,265 @@ +# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr +# +# This file is part of CubicWeb. +# +# CubicWeb is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 2.1 of the License, or (at your option) +# any later version. +# +# CubicWeb is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. +"""CubicWeb is a generic framework to quickly build applications which describes +relations between entitites. +""" +__docformat__ = "restructuredtext en" + +# ignore the pygments UserWarnings +import warnings +import zlib +warnings.filterwarnings('ignore', category=UserWarning, + message='.*was already imported', + module='.*pygments') + + +from six import PY2, binary_type, text_type +from six.moves import builtins + +CW_SOFTWARE_ROOT = __path__[0] + +import sys, os, logging +from io import BytesIO + +from six.moves import cPickle as pickle + +from logilab.common.deprecation import deprecated +from logilab.common.logging_ext import set_log_methods +from yams.constraints import BASE_CONVERTERS, BASE_CHECKERS + +# pre python 2.7.2 safety +logging.basicConfig() + +from cubicweb.__pkginfo__ import version as __version__ + + +set_log_methods(sys.modules[__name__], logging.getLogger('cubicweb')) + +# make all exceptions accessible from the package +from cubicweb._exceptions import * +from logilab.common.registry import ObjectNotFound, NoSelectableObject, RegistryNotFound + + +# '_' is available to mark internationalized string but should not be used to +# do the actual translation +_ = text_type +if not hasattr(builtins, '_'): + builtins._ = deprecated("[3.22] Use 'from cubicweb import _'")(_) + + +# convert eid to the right type, raise ValueError if it's not a valid eid +@deprecated('[3.17] typed_eid() was removed. replace it with int() when needed.') +def typed_eid(eid): + return int(eid) + +#def log_thread(f, w, a): +# print f.f_code.co_filename, f.f_code.co_name +#import threading +#threading.settrace(log_thread) + +class Binary(BytesIO): + """class to hold binary data. Use BytesIO to prevent use of unicode data""" + _allowed_types = (binary_type, bytearray, buffer if PY2 else memoryview) + + def __init__(self, buf=b''): + assert isinstance(buf, self._allowed_types), \ + "Binary objects must use bytes/buffer objects, not %s" % buf.__class__ + super(Binary, self).__init__(buf) + + def write(self, data): + assert isinstance(data, self._allowed_types), \ + "Binary objects must use bytes/buffer objects, not %s" % data.__class__ + super(Binary, self).write(data) + + def to_file(self, fobj): + """write a binary to disk + + the writing is performed in a safe way for files stored on + Windows SMB shares + """ + pos = self.tell() + self.seek(0) + if sys.platform == 'win32': + while True: + # the 16kB chunksize comes from the shutil module + # in stdlib + chunk = self.read(16*1024) + if not chunk: + break + fobj.write(chunk) + else: + fobj.write(self.read()) + self.seek(pos) + + @staticmethod + def from_file(filename): + """read a file and returns its contents in a Binary + + the reading is performed in a safe way for files stored on + Windows SMB shares + """ + binary = Binary() + with open(filename, 'rb') as fobj: + if sys.platform == 'win32': + while True: + # the 16kB chunksize comes from the shutil module + # in stdlib + chunk = fobj.read(16*1024) + if not chunk: + break + binary.write(chunk) + else: + binary.write(fobj.read()) + binary.seek(0) + return binary + + def __eq__(self, other): + if not isinstance(other, Binary): + return False + return self.getvalue() == other.getvalue() + + + # Binary helpers to store/fetch python objects + + @classmethod + def zpickle(cls, obj): + """ return a Binary containing a gzipped pickle of obj """ + retval = cls() + retval.write(zlib.compress(pickle.dumps(obj, protocol=2))) + return retval + + def unzpickle(self): + """ decompress and loads the stream before returning it """ + return pickle.loads(zlib.decompress(self.getvalue())) + + +def check_password(eschema, value): + return isinstance(value, (binary_type, Binary)) +BASE_CHECKERS['Password'] = check_password + +def str_or_binary(value): + if isinstance(value, Binary): + return value + return binary_type(value) +BASE_CONVERTERS['Password'] = str_or_binary + + +# use thi