Example #1
0
    def get_filename(self,
                     filename,
                     filesystem=False,
                     convert=False,
                     subpath=''):
        """
        Get the filename according to self.to_path, and if filesystem is False
        then return unicode filename, otherwise return filesystem encoded filename
    
        @param filename: relative filename, it'll be combine with self.to_path
        @param filesystem: if True, then encoding the filename to filesystem
        @param convert: if True, then convert filename with FilenameConverter class
        @param subpath: sub folder in to_path
        """
        from uliweb.utils.common import safe_unicode

        #make sure the filename is unicode
        s = settings.GLOBAL
        if convert:
            _p, _f = os.path.split(filename)
            _filename = os.path.join(_p, self.filename_convert(_f))
        else:
            _filename = filename
        nfile = safe_unicode(_filename, s.HTMLPAGE_ENCODING)

        if subpath:
            paths = [application_path(self.to_path), subpath, nfile]
        else:
            paths = [application_path(self.to_path), nfile]
        f = os.path.normpath(os.path.join(*paths)).replace('\\', '/')

        if filesystem:
            return files.encode_filename(f, to_encoding=s.FILESYSTEM_ENCODING)
        return f
Example #2
0
    def get_filename(self, filename, filesystem=False, convert=False, subpath=''):
        """
        Get the filename according to self.to_path, and if filesystem is False
        then return unicode filename, otherwise return filesystem encoded filename
    
        @param filename: relative filename, it'll be combine with self.to_path
        @param filesystem: if True, then encoding the filename to filesystem
        @param convert: if True, then convert filename with FilenameConverter class
        @param subpath: sub folder in to_path
        """
        from uliweb.utils.common import safe_unicode
        
        #make sure the filename is unicode
        s = settings.GLOBAL
        if convert:
            _p, _f = os.path.split(filename)
            _filename = os.path.join(_p, self.filename_convert(_f))
        else:
            _filename = filename
        nfile = safe_unicode(_filename, s.HTMLPAGE_ENCODING)

        if subpath:
            paths = [application_path(self.to_path), subpath, nfile]
        else:
            paths = [application_path(self.to_path), nfile]
        f = os.path.normpath(os.path.join(*paths)).replace('\\', '/')
    
        if filesystem:
            return files.encode_filename(f, to_encoding=s.FILESYSTEM_ENCODING)
        return f
Example #3
0
    def __init__(self, application, settings):
        from datetime import timedelta
        self.options = dict(settings.get('SESSION_STORAGE', {}))
        self.options['data_dir'] = application_path(self.options['data_dir'])
        if 'url' not in self.options:
            _url = (settings.get_var('ORM/CONNECTION', '') or
            settings.get_var('ORM/CONNECTIONS', {}).get('default', {}).get('CONNECTION', ''))
            if _url:
                self.options['url'] = _url
        
        #process Session options
        self.remember_me_timeout = settings.SESSION.remember_me_timeout
        self.session_storage_type = settings.SESSION.type
        self.timeout = settings.SESSION.timeout
        Session.force = settings.SESSION.force
        
        #process Cookie options
        SessionCookie.default_domain = settings.SESSION_COOKIE.domain
        SessionCookie.default_path = settings.SESSION_COOKIE.path
        SessionCookie.default_secure = settings.SESSION_COOKIE.secure
        SessionCookie.default_cookie_id = settings.SESSION_COOKIE.cookie_id

        if isinstance(settings.SESSION_COOKIE.timeout, int):
            timeout = timedelta(seconds=settings.SESSION_COOKIE.timeout)
        else:
            timeout = settings.SESSION_COOKIE.timeout
        SessionCookie.default_expiry_time = timeout
Example #4
0
def get_cache(**kwargs):
    from uliweb import settings
    from weto.cache import Cache
    from uliweb.utils.common import import_attr, application_path

    serial_cls_path = settings.get_var('CACHE/serial_cls')
    if serial_cls_path:
        serial_cls = import_attr(serial_cls_path)
        if settings.GLOBAL.PICKLE_PROTOCAL_LEVEL is not None:
            serial_cls.protocal_level = settings.GLOBAL.PICKLE_PROTOCAL_LEVEL
    else:
        serial_cls = None

    options = dict(settings.get_var('CACHE_STORAGE', {}))
    options['data_dir'] = application_path(options['data_dir'])
    args = {
        'storage_type': settings.get_var('CACHE/type'),
        'options': options,
        'expiry_time': settings.get_var('CACHE/expiretime'),
        'serial_cls': serial_cls
    }

    args.update(kwargs)
    cache = Cache(**args)
    return cache
Example #5
0
def get_session(key=None):
    options = dict(settings.get('SESSION_STORAGE', {}))
    options['data_dir'] = application_path(options['data_dir'])
    if 'url' not in options:
        _url = (settings.get_var('ORM/CONNECTION', '') or settings.get_var(
            'ORM/CONNECTIONS', {}).get('default', {}).get('CONNECTION', ''))
        if _url:
            options['url'] = _url

    #process Session options
    session_storage_type = settings.SESSION.type
    Session.force = settings.SESSION.force

    serial_cls_path = settings.SESSION.serial_cls
    if serial_cls_path:
        serial_cls = import_attr(serial_cls_path)
    else:
        serial_cls = None

    session = Session(key,
                      storage_type=session_storage_type,
                      options=options,
                      expiry_time=settings.SESSION.timeout,
                      serial_cls=serial_cls)
    return session
Example #6
0
def get_key(keyfile=None):
    """
    Read the key content from secret_file
    """
    keyfile = keyfile or application_path(settings.SECRETKEY.SECRET_FILE)
    with file(keyfile, 'rb') as f:
        return f.read()
Example #7
0
    def __init__(self, application, settings):
        from datetime import timedelta
        self.options = dict(settings.get('SESSION_STORAGE', {}))
        self.options['data_dir'] = application_path(self.options['data_dir'])
        if 'url' not in self.options:
            _url = (settings.get_var('ORM/CONNECTION', '')
                    or settings.get_var('ORM/CONNECTIONS', {}).get(
                        'default', {}).get('CONNECTION', ''))
            if _url:
                self.options['url'] = _url

        #process Session options
        self.remember_me_timeout = settings.SESSION.remember_me_timeout
        self.session_storage_type = settings.SESSION.type
        self.timeout = settings.SESSION.timeout
        Session.force = settings.SESSION.force

        #process Cookie options
        SessionCookie.default_domain = settings.SESSION_COOKIE.domain
        SessionCookie.default_path = settings.SESSION_COOKIE.path
        SessionCookie.default_secure = settings.SESSION_COOKIE.secure
        SessionCookie.default_cookie_id = settings.SESSION_COOKIE.cookie_id

        if isinstance(settings.SESSION_COOKIE.timeout, int):
            timeout = timedelta(seconds=settings.SESSION_COOKIE.timeout)
        else:
            timeout = settings.SESSION_COOKIE.timeout
        SessionCookie.default_expiry_time = timeout
Example #8
0
def get_key(keyfile=None):
    """
    Read the key content from secret_file
    """
    keyfile = keyfile or application_path(settings.SECRETKEY.SECRET_FILE)
    with file(keyfile, 'rb') as f:
        return f.read()
Example #9
0
class Resume(object):

    BASE_STORE_PATH = application_path(settings.TRANSFER.BASEUPLAOD)

    # basePath = os.path.join(application_path(settings.TRANSFER.BASEUPLAOD), request.user.username, resumableIdentifier)

    def __init__(self, **kwargs):
        ''' 记录参数 '''
        self.stdout = ''
        self.stderr = ''
        self.fileQueue = list()

    def start(self):
        """
Example #10
0
 def __init__(self, default_filename_converter_cls=UUIDFilenameConverter):
     for k, v in self.options.items():
         item, default = v
         if k == 'to_path':
             value = application_path(settings.get_var(item, default))
         else:
             value = settings.get_var(item, default)
         setattr(self, k, value)
         
     if self.x_sendfile and not self.x_header_name:
         if self.x_sendfile == 'nginx':
             self.x_header_name = 'X-Accel-Redirect'
         elif self.x_sendfile == 'apache':
             self.x_header_name = 'X-Sendfile'
         else:
             raise Exception, "X_HEADER can't be None, or X_SENDFILE is not supprted"
     if isinstance(self._filename_converter, (str, unicode)):
         self._filename_converter_cls = import_attr(self._filename_converter)
     else:
         self._filename_converter_cls = self._filename_converter or default_filename_converter_cls
Example #11
0
    def __init__(self, default_filename_converter_cls=UUIDFilenameConverter):
        for k, v in self.options.items():
            item, default = v
            if k == 'to_path':
                value = application_path(settings.get_var(item, default))
            else:
                value = settings.get_var(item, default)
            setattr(self, k, value)

        if self.x_sendfile and not self.x_header_name:
            if self.x_sendfile == 'nginx':
                self.x_header_name = 'X-Accel-Redirect'
            elif self.x_sendfile == 'apache':
                self.x_header_name = 'X-Sendfile'
            else:
                raise Exception, "X_HEADER can't be None, or X_SENDFILE is not supprted"
        if isinstance(self._filename_converter, (str, unicode)):
            self._filename_converter_cls = import_attr(
                self._filename_converter)
        else:
            self._filename_converter_cls = self._filename_converter or default_filename_converter_cls
Example #12
0
 def __init__(self,
              fileobj=None,
              fileName=None,
              resumeObj=None,
              identify=None,
              username=None,
              type=1,
              totalChunk=None,
              currentChunk=None):
     self.fileObj = fileobj
     self.resumeObj = resumeObj
     self.identifier = identify
     self.username = username
     self.fileName = fileName
     self.filePath = os.path.join(
         application_path(settings.TRANSFER.BASEUPLAOD), username, identify)
     self.type = type
     self.totalChunk = totalChunk if totalChunk else 0
     self.currentChunk = currentChunk if currentChunk else 0
     if not os.path.exists(self.filePath):
         os.makedirs(self.filePath)
Example #13
0
def get_session(key=None):
    options = dict(settings.get('SESSION_STORAGE', {}))
    options['data_dir'] = application_path(options['data_dir'])
    if 'url' not in options:
        _url = (settings.get_var('ORM/CONNECTION', '') or
        settings.get_var('ORM/CONNECTIONS', {}).get('default', {}).get('CONNECTION', ''))
        if _url:
            options['url'] = _url

    #process Session options
    session_storage_type = settings.SESSION.type
    Session.force = settings.SESSION.force

    serial_cls_path = settings.SESSION.serial_cls
    if serial_cls_path:
        serial_cls = import_attr(serial_cls_path)
    else:
        serial_cls = None

    session = Session(key, storage_type=session_storage_type,
        options=options, expiry_time=settings.SESSION.timeout, serial_cls=serial_cls)
    return session
Example #14
0
def get_cache(**kwargs):
    from uliweb import settings
    from weto.cache import Cache
    from uliweb.utils.common import import_attr, application_path

    serial_cls_path = settings.get_var("CACHE/serial_cls")
    if serial_cls_path:
        serial_cls = import_attr(serial_cls_path)
    else:
        serial_cls = None

    options = dict(settings.get_var("CACHE_STORAGE", {}))
    options["data_dir"] = application_path(options["data_dir"])
    args = {
        "storage_type": settings.get_var("CACHE/type"),
        "options": options,
        "expiry_time": settings.get_var("CACHE/expiretime"),
        "serial_cls": serial_cls,
    }

    args.update(kwargs)
    cache = Cache(**args)
    return cache
Example #15
0
def get_key():
    """
    Read the key content from secret_file
    """
    with file(application_path(settings.SECRETKEY.SECRET_FILE), 'rb') as f:
        return f.read()
Example #16
0
def get_key():
    """
    Read the key content from secret_file
    """
    with file(application_path(settings.SECRETKEY.SECRET_FILE), 'rb') as f:
        return f.read()