Esempio n. 1
0
 def __init__(self, timeout=300, **kwargs):
     self.storage_url = project.setting('cache', 'storage_url')
     try:
         self.engine = StorageEngineMemcache(self.storage_url).get_engine()
     except StorageEngineError:
         raise
     super(Memcache, self).__init__(timeout, **kwargs)
Esempio n. 2
0
 def __init__(self, application, request, status_code, message=None,
              format_exc=[]):
     super(ErrorPage, self).__init__(application, request)
     self.set_status(status_code)
     self.status_message = message
     self.format_exc = format_exc
     self.is_debug = project.setting('application', 'debug', True)
     self._headers.update(utils.no_cache_headers())
Esempio n. 3
0
def _get_log_path():
    path = project.setting('profile', 'profile_log_path')
    if not path:
        prj_path = project.project_directory()
        path = os.path.join(prj_path, 'data')
    path = os.path.join(path, 'profile')
    if not os.path.exists(path):
        os.makedirs(path)
    logging.debug('Profile store path: %s' % path)
    return path
Esempio n. 4
0
    def profile(self):
        if not hasattr(self, '_profile_cache'):
            profile_module_string = project.setting('auth', 'profile_class', None)
            if profile_module_string:
                try:
                    module_name, sep, class_name = profile_module_string.rpartition('.')
                except ValueError:
                    raise UserProfileNotAvailable("'%s' seems not valid."
                          " " % profile_module_string)

                try:
                    __import__(module_name)
                    module = sys.modules[module_name]
                    cls = module.__dict__[class_name]
                except ImportError, KeyError:
                    raise UserProfileNotAvailable("Cannot import %s. "
                          " " % profile_module_string)
            else:
                cls = UserProfileDatastore
            self._profile_cache = cls.get_by_key_name("profileof%s" % self.username)
Esempio n. 5
0
def profile(log_name=None):
    n = log_name
    is_debug = project.setting('application', 'debug', False)
    def prof(func, *args, **kwargs):
        if HOSTING_TYPE == 'google_appengine':
            return func(*args, **kwargs)

        if not n:
            log_name  = _make_profile_name(func)
        else:
            log_name = n
        logfile = os.path.join(PROFILE_LOG_PATH, log_name)
        (base, ext) = os.path.splitext(logfile)
        if not ext:
            ext = '.cprof'
        base = "%s-%s" % (base, time.strftime("%Y%m%dT%H%M%S", time.gmtime()))
        full_log_file = base + ext
        _locals = locals()
        cProfile.runctx("func(*args, **kwargs)", globals(), _locals,
                        full_log_file)
        if is_debug:
            pstats.Stats(full_log_file).strip_dirs().sort_stats('time').print_stats(20)
        return
    return decorator(prof)
Esempio n. 6
0
__all__ = ['profile']


def _get_log_path():
    path = project.setting('profile', 'profile_log_path')
    if not path:
        prj_path = project.project_directory()
        path = os.path.join(prj_path, 'data')
    path = os.path.join(path, 'profile')
    if not os.path.exists(path):
        os.makedirs(path)
    logging.debug('Profile store path: %s' % path)
    return path


HOSTING_TYPE = project.setting('application', 'serve_type')


if HOSTING_TYPE == 'wsgi':
    logging.info("Application running on google appengine. Profile "
                 "function disabled")
    PROFILE_LOG_PATH = None
else:
    PROFILE_LOG_PATH = _get_log_path()


def _make_profile_name(func):
    cls = None
    if hasattr(func, 'im_func'):
        cls = func.im_class
        func = func.im_func
Esempio n. 7
0
 def __init__(self):
     if not project.setting('extensions', 'whirly.extensions.session'):
         raise Exception("Auth extension need session support. ")
     super(NoDB, self).__init__('auth')
Esempio n. 8
0
 def set_password(self, raw_password):
     algo = project.setting('auth', 'password_algorithm_type', 'sha1')
     salt = get_hexdigest(algo, str(random.random()), str(random.random()))[:5]
     hsh = get_hexdigest(algo, salt, raw_password)
     self['password'] = u'%s$%s$%s' % (algo, salt, hsh)
Esempio n. 9
0
import hashlib

from pymongo import GEO2D
from pymongo.objectid import ObjectId
from mongokit import Connection, Document

from whirly import project
from whirly.extensions.base import Extension
from whirly.extensions.authbase.userbase import SESSION_AUTH_KEY
from whirly.extensions.authbase.userbase import AbstractUserHelper
from whirly.extensions.authbase.userbase import local_user, get_hexdigest
from whirly.extensions.authbase.permissionbase import AbstractPermissionHelper
from whirly.extensions.authbase.groupbase import AbstractGroupHelper

conn = Connection()
_db_url = project.setting('database', 'database_url')
_auth_db = re.match('mongodb://([\S|\.]+?)?(?::(\d+))?/(\S+)', _db_url).group(3)
zidb = conn[_auth_db]
user_collection = zidb['whirly_auth_user']
group_collection = zidb['whirly_auth_group']
permission_collection = zidb['whirly_auth_permission']


__all__ = ['User', 'Group', 'Permission', 'Auth']


class Permission(Document):
    structure = {
        'name': unicode,
        'description': unicode,
    }
Esempio n. 10
0
 def __init__(self):
     self.username = ''
     self.is_active = project.setting('auth', 'enable_anonymous_user', True)
Esempio n. 11
0

import sys

from whirly.extensions.authbase.userbase import UserProfile, AnonymousUser
from whirly.extensions.authbase.decorators import with_permission
from whirly.extensions.authbase.permissionbase import InUsers, IsSuperUser
from whirly.extensions.authbase.permissionbase import IsStaff, Authenticated
from whirly.extensions.authbase.permissionbase import InGroup, FromIP
from whirly.extensions.authbase.permissionbase import BetweenTimes, HasPermission
from whirly.extensions.authbase.permissionbase import All, Any
from whirly.extensions.authbase.permissionbase import PermissionChecker
from whirly import project


serve_type = project.setting("application", "serve_type", "tornado")
if serve_type == "wsgi":
    from gaema.auth import OpenIdMixin
    from gaema.auth import OAuthMixin
    from gaema.auth import TwitterMixin
    from gaema.auth import FriendFeedMixin
    from gaema.auth import GoogleMixin
    from gaema.auth import FacebookMixin
    from gaema.webapp_auth import WebappAuth, RequestRedirect, HttpException
else:
    from tornado.auth import OpenIdMixin
    from tornado.auth import OAuthMixin
    from tornado.auth import TwitterMixin
    from tornado.auth import FriendFeedMixin
    from tornado.auth import GoogleMixin
    from tornado.auth import FacebookMixin
Esempio n. 12
0
 def __init__(self, timeout=None, with_query_args=False):
     self.timeout = timeout or project.setting('cache', 'default_timeout', 300)
     self.anonymous_only = project.setting('cache', 'anonymous_only', False)
     self.with_query_args = with_query_args
Esempio n. 13
0
# under the License.


import sys
import logging
import inspect
import functools

from whirly import project
from whirly import utils


__all__ = ['whirly_cache', 'WC', 'cache', 'nocache']


default_timeout = project.setting('cache', 'default_timeout', 300)


def _get_cache_class():
    _cache_settings = project.extension_settings('cache')

    _cache_module_string = _cache_settings['extension'][0]
    _cls = _cache_settings['extension'][1]

    __import__(_cache_module_string)
    cache_module = sys.modules[_cache_module_string]
    return cache_module.__dict__[_cls]


whirly_cache = WC = _get_cache_class()(default_timeout)()