示例#1
0
文件: backend.py 项目: yuanhao/Whirly
 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)
示例#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())
示例#3
0
文件: profile.py 项目: yuanhao/Whirly
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
示例#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)
示例#5
0
文件: profile.py 项目: yuanhao/Whirly
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)
示例#6
0
文件: profile.py 项目: yuanhao/Whirly
__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
示例#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')
示例#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)
示例#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,
    }
示例#10
0
 def __init__(self):
     self.username = ''
     self.is_active = project.setting('auth', 'enable_anonymous_user', True)
示例#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
示例#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
示例#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)()