当前位置: 首页>>代码示例>>Python>>正文


Python FileSystemCache.set方法代码示例

本文整理汇总了Python中werkzeug.contrib.cache.FileSystemCache.set方法的典型用法代码示例。如果您正苦于以下问题:Python FileSystemCache.set方法的具体用法?Python FileSystemCache.set怎么用?Python FileSystemCache.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.contrib.cache.FileSystemCache的用法示例。


在下文中一共展示了FileSystemCache.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FileSystemSessionInterface

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
class FileSystemSessionInterface(SessionInterface):
    """Uses the :class:`werkzeug.contrib.cache.FileSystemCache` as a session
    backend.

    :param cache_dir: the directory where session files are stored.
    :param threshold: the maximum number of items the session stores before it
                      starts deleting some.
    :param mode: the file mode wanted for the session files, default 0600
    :param key_prefix: A prefix that is added to FileSystemCache store keys.
    """

    session_class = FileSystemSession

    def __init__(self, cache_dir, threshold, mode, key_prefix):
        from werkzeug.contrib.cache import FileSystemCache
        self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode)
        self.key_prefix = key_prefix

    def _generate_sid(self):
        return str(uuid4())

    def open_session(self, app, request):
        sid = request.cookies.get(app.session_cookie_name)
        if not sid:
            sid = self._generate_sid()
            return self.session_class(sid=sid)
        data = self.cache.get(self.key_prefix + sid)
        if data is not None:
            return self.session_class(data, sid=sid)
        return self.session_class(sid=sid)
    
    def save_session(self, app, session, response):
        domain = self.get_cookie_domain(app)
        path = self.get_cookie_path(app)
        if not session:
            if session.modified:
                self.cache.delete(self.key_prefix + session.sid)
                response.delete_cookie(app.session_cookie_name,
                                       domain=domain, path=path)
            return

        # Modification case.  There are upsides and downsides to
        # emitting a set-cookie header each request.  The behavior
        # is controlled by the :meth:`should_set_cookie` method
        # which performs a quick check to figure out if the cookie
        # should be set or not.  This is controlled by the
        # SESSION_REFRESH_EACH_REQUEST config flag as well as
        # the permanent flag on the session itself.
        # if not self.should_set_cookie(app, session):
        #    return

        httponly = self.get_cookie_httponly(app)
        secure = self.get_cookie_secure(app)
        expires = self.get_expiration_time(app, session)
        data = dict(session)
        self.cache.set(self.key_prefix + session.sid, data,
                         int(app.permanent_session_lifetime.total_seconds()))
        response.set_cookie(app.session_cookie_name, session.sid,
                            expires=expires, httponly=httponly,
                            domain=domain, path=path, secure=secure)
开发者ID:x20080406,项目名称:bteditor,代码行数:62,代码来源:sessions.py

示例2: number_gen

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
def number_gen(first_part, start_num, end_num, semester, dept, subjects):
    driver = webdriver.Firefox()  # Firefox used for testing. Change it to PhantomJS
    driver.implicitly_wait(30)
    base_url = "http://result.pondiuni.edu.in/candidate.asp"
    url = base_url
    driver.get(base_url)
    # os.mkdir(str(first_part))
    os.chdir("results")
    os.chdir(str(first_part))
    cache = FileSystemCache('.cachedir', threshold=100000)
    for number in range(start_num, end_num + 1):
        current_num = "%04d" % number
        numb = first_part + str(current_num)
        driver.find_element_by_id("txtregno").clear()
        driver.find_element_by_id("txtregno").send_keys(numb)
        Select(driver.find_element_by_id("cmbdegree")).select_by_visible_text(dept)
        Select(driver.find_element_by_id("cmbexamno")).select_by_visible_text(semester)
        driver.find_element_by_id("button1").click()

        # copying the content
        page_source = cache.get(url)
        page_source = driver.page_source
        cache.set(url, page_source, timeout=60 * 60 * 24 * 7)  # week in seconds
        root = html.document_fromstring(page_source)
        Cleaner(kill_tags=['noscript'], style=True)(root)  # lxml >= 2.3.1

        # pasting to file
        filename = str(numb) + ".txt"
        fp = open(filename, 'w')
        fp.write((root.text_content()).encode('utf-8'))
        fp.close()
        driver.back()
    driver.close()
    return analyze(subjects)
开发者ID:yoga30696,项目名称:Automation-of-result-analysis,代码行数:36,代码来源:server.py

示例3: test_filesystemcache_clear

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
def test_filesystemcache_clear():
    """
    test if FileSystemCache.clear works
    """
    tmp_dir = tempfile.mkdtemp()
    cache = FileSystemCache(cache_dir=tmp_dir)
    cache.set("foo", "bar")
    cache_files = os.listdir(tmp_dir)
    assert len(cache_files) == 1
    cache.clear()
    cache_files = os.listdir(tmp_dir)
    assert len(cache_files) == 0
    shutil.rmtree(tmp_dir)
开发者ID:EnTeQuAk,项目名称:werkzeug,代码行数:15,代码来源:test_cache.py

示例4: test_filesystemcache_prune

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
def test_filesystemcache_prune():
    """
    test if FileSystemCache._prune works and keeps the cache entry count
    below the given threshold.
    """
    THRESHOLD = 13
    tmp_dir = tempfile.mkdtemp()
    cache = FileSystemCache(cache_dir=tmp_dir, threshold=THRESHOLD)
    for i in range(2 * THRESHOLD):
        cache.set(str(i), i)
    cache_files = os.listdir(tmp_dir)
    shutil.rmtree(tmp_dir)
    assert len(cache_files) <= THRESHOLD
开发者ID:EnTeQuAk,项目名称:werkzeug,代码行数:15,代码来源:test_cache.py

示例5: test_filesystemcache_set_get

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
def test_filesystemcache_set_get():
    """
    test if FileSystemCache.set/get works
    """
    tmp_dir = tempfile.mkdtemp()
    try:
        cache = FileSystemCache(cache_dir=tmp_dir)
        for i in range(3):
            cache.set(str(i), i * i)
        for i in range(3):
            result = cache.get(str(i))
            assert result == i * i
    finally:
        shutil.rmtree(tmp_dir)
开发者ID:EnTeQuAk,项目名称:werkzeug,代码行数:16,代码来源:test_cache.py

示例6: BaseProvider

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
class BaseProvider(object):

    __metaclass__ = ABCMeta

    def __init__(self, cache_dir=None, default_timeout=60 * 60 * 24,
                 api_key=None):
        # store it in cache for 1 day. using file system cache because
        # memcached is too mainstream. :)
        self.cache = FileSystemCache(cache_dir=cache_dir or '/tmp/__arcoiro__',
                                     default_timeout=default_timeout)
        self._api_key = api_key

    @abstractproperty
    def name(self):
        pass

    @abstractproperty
    def url(self):
        pass

    @abstractmethod
    def get_urls_from_tag(self, tag):
        pass

    @property
    def display_name(self):
        return self.name

    @property
    def api_key(self):
        if self._api_key is not None:
            return self._api_key
        config_key = '%s_API_KEY' % self.name.upper()
        key = current_app.config.get(config_key)
        if key is None:
            raise RuntimeError('%s not defined!' % config_key)
        return key

    def get_cached_urls_from_tag(self, tag):
        cache_key = '%s:%s' % (self.name, tag)
        urls = self.cache.get(cache_key)
        if urls is not None:
            return urls
        urls = self.get_urls_from_tag(tag)
        if urls is None:
            return None
        self.cache.set(cache_key, urls)
        return urls
开发者ID:rafaelmartins,项目名称:arcoiro,代码行数:50,代码来源:__init__.py

示例7: parse

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
def parse(url):
    cache = FileSystemCache('.cachedir', threshold=100000)

    # get page
    page_source = cache.get(url)
    if page_source is None:
        # use firefox to get page with javascript generated content
        with closing(Firefox()) as browser:
            browser.get(url)
            page_source = browser.page_source
            cache.set(url, page_source, timeout=60*60*24*7) # week in seconds

    # extract text
    root = html.document_fromstring(page_source)
    # remove flash, images, <script>,<style>, etc
    Cleaner(kill_tags=['noscript'], style=True)(root) # lxml >= 2.3.1
    return root.text_content() # extract text
开发者ID:phektus,项目名称:HN-Summarizer,代码行数:19,代码来源:content_parser.py

示例8: getSpaceInfo

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
def getSpaceInfo(spaceId):
    global spaceCache
    if spaceCache is None:
        mkdir_p(DURACLOUD_SPACE_CACHE_DIR)
        spaceCache = FileSystemCache(DURACLOUD_SPACE_CACHE_DIR, threshold=50, default_timeout=(24*3600), mode=384)

    # check spaceCache, otherwise fetch info from DuraCloud
    result = spaceCache.get(spaceId)
    if result is None:
        url = DURACLOUD_URL+ "/duradmin/download/contentItem"
        auth = HTTPBasicAuth(DURACLOUD_USERNAME, DURACLOUD_PASSWORD)
        payload = {'spaceId': spaceId, 'contentId': 'info.json'}
        try:
            response = requests.get(url, params=payload, auth=auth)
            result = response.json()
            spaceCache.set(spaceId, result)
        except RequestException as e:
            print e
            raise
    return result
开发者ID:gregjan,项目名称:durastream,代码行数:22,代码来源:durastream.py

示例9: WechatCache

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
class WechatCache(object):
    """基于文件的缓存

    """

    def __init__(self, cache_dir='cache', default_timeout=300):
        """初始化

        cache_dir是缓存目录
        """
        self.cache = FileSystemCache(cache_dir, default_timeout=default_timeout)

    def clear(self):
        """清空缓存
        """
        return self.cache.clear()

    def get(self, key):
        """获取缓存

        获取键值key的缓存值
        如果没有对应缓存,返回None
        """
        return self.cache.get(key)

    def add(self, key, value, timeout=None):
        """增加缓存

        如果键值key对应的缓存不存在,那么增加值value到键值key,过期时间timeout,默认300秒
        否则返回False(即不能覆盖设置缓存)
        """
        return self.cache.add(key, value, timeout)

    def set(self, key, value, timeout=None):
        """设置缓存

        设置键值key的缓存为value,过期时间300秒
        """
        return self.cache.set(key, value, timeout)

    def delete(self, key):
        """删除缓存

        删除键值key存储的缓存
        """
        return self.cache.delete(key)
开发者ID:dingshanliang,项目名称:WechatSogou,代码行数:48,代码来源:filecache.py

示例10: FileSystemSessionInterface

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
class FileSystemSessionInterface(SessionInterface):
    """Uses the :class:`werkzeug.contrib.cache.FileSystemCache` as a session
    backend.

    .. versionadded:: 0.2
        The `use_signer` parameter was added.

    :param cache_dir: the directory where session files are stored.
    :param threshold: the maximum number of items the session stores before it
                      starts deleting some.
    :param mode: the file mode wanted for the session files, default 0600
    :param key_prefix: A prefix that is added to FileSystemCache store keys.
    :param use_signer: Whether to sign the session id cookie or not.
    :param permanent: Whether to use permanent session or not.
    """

    session_class = FileSystemSession

    def __init__(self, cache_dir, threshold, mode, key_prefix,
                 use_signer=False, permanent=True):
        from werkzeug.contrib.cache import FileSystemCache
        self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode)
        self.key_prefix = key_prefix
        self.use_signer = use_signer
        self.permanent = permanent

    def open_session(self, app, request):
        sid = request.cookies.get(app.session_cookie_name)
        if not sid:
            sid = self._generate_sid()
            return self.session_class(sid=sid, permanent=self.permanent)
        if self.use_signer:
            signer = self._get_signer(app)
            if signer is None:
                return None
            try:
                sid = signer.unsign(sid)
            except BadSignature:
                sid = self._generate_sid()
                return self.session_class(sid=sid, permanent=self.permanent)

        data = self.cache.get(self.key_prefix + sid)
        if data is not None:
            return self.session_class(data, sid=sid)
        return self.session_class(sid=sid, permanent=self.permanent)

    def save_session(self, app, session, response):
        domain = self.get_cookie_domain(app)
        path = self.get_cookie_path(app)
        if not session:
            if session.modified:
                self.cache.delete(self.key_prefix + session.sid)
                response.delete_cookie(app.session_cookie_name,
                                       domain=domain, path=path)
            return

        httponly = self.get_cookie_httponly(app)
        secure = self.get_cookie_secure(app)
        expires = self.get_expiration_time(app, session)
        data = dict(session)
        self.cache.set(self.key_prefix + session.sid, data,
                       total_seconds(app.permanent_session_lifetime))
        if self.use_signer:
            session_id = self._get_signer(app).sign(session.sid)
        else:
            session_id = session.sid
        response.set_cookie(app.session_cookie_name, session_id,
                            expires=expires, httponly=httponly,
                            domain=domain, path=path, secure=secure)
开发者ID:deeb230,项目名称:nzbhydra,代码行数:71,代码来源:sessions.py

示例11: FileSystemCache

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
from selenium.webdriver     import Firefox         # pip install selenium
from werkzeug.contrib.cache import FileSystemCache # pip install werkzeug

cache = FileSystemCache('.cachedir', threshold=100000)

url = sys.argv[1] if len(sys.argv) > 1 else "http://www.schibsted.cl/testqa/"


# get page
page_source = cache.get(url)
if page_source is None:
    # use firefox to get page with javascript generated content
    with closing(Firefox()) as browser:
        browser.get(url)
        page_source = browser.page_source
    cache.set(url, page_source, timeout=60*60*24*7) # week in seconds


# extract text
root = html.document_fromstring(page_source)
# remove flash, images, <script>,<style>, etc
Cleaner(kill_tags=['noscript'], style=True)(root) # lxml >= 2.3.1
webtext = root.text_content() # extract text
f = open("C:/schibsted/data/Test.txt", "w");
print f
value = (webtext)
myString = str(value)
f.write(myString)
f.close()

开发者ID:oscarfunk,项目名称:schibsted,代码行数:31,代码来源:util.py

示例12: Cache

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
class Cache(object):
    """
    This class is used to control the cache objects.

    If TESTING is True it will use NullCache.
    """

    def __init__(self, app=None):
        self.cache = None

        if app is not None:
            self.init_app(app)
        else:
            self.app = None

    def init_app(self, app):
        "This is used to initialize cache with your app object"

        app.config.setdefault('CACHE_DEFAULT_TIMEOUT', 300)
        app.config.setdefault('CACHE_THRESHOLD', 500)
        app.config.setdefault('CACHE_KEY_PREFIX', None)
        app.config.setdefault('CACHE_MEMCACHED_SERVERS', None)
        app.config.setdefault('CACHE_DIR', None)
        app.config.setdefault('CACHE_TYPE', 'NullCache')

        self.app = app

        self._set_cache()

    def _set_cache(self):
        if self.app.config['TESTING']:
            self.cache = NullCache()
        else:
            if self.app.config['CACHE_TYPE'] == 'Null':
                self.cache = NullCache()
            elif self.app.config['CACHE_TYPE'] == 'Simple':
                self.cache = SimpleCache(
                    threshold=self.app.config['CACHE_THRESHOLD'],
                    default_timeout=self.app.config['CACHE_DEFAULT_TIMEOUT'])
            elif self.app.config['CACHE_TYPE'] == 'Memcached':
                self.cache = MemcachedCache(
                    self.app.config['CACHE_MEMCACHED_SERVERS'],
                    default_timeout=self.app.config['CACHE_DEFAULT_TIMEOUT'],
                    key_prefix=self.app.config['CACHE_KEY_PREFIX'])
            elif self.app.config['CACHE_TYPE'] == 'GAE':
                self.cache = GAEMemcachedCache(
                    default_timeout=self.app.config['CACHE_DEFAULT_TIMEOUT'],
                    key_prefix=self.app.config['CACHE_KEY_PREFIX'])
            elif self.app.config['CACHE_TYPE'] == 'FileSystem':
                self.cache = FileSystemCache(
                    self.app.config['CACHE_DIR'],
                    threshold=self.app.config['CACHE_THRESHOLD'],
                    default_timeout=self.app.config['CACHE_DEFAULT_TIMEOUT'])

    def get(self, *args, **kwargs):
        "Proxy function for internal cache object."
        return self.cache.get(*args, **kwargs)

    def set(self, *args, **kwargs):
        "Proxy function for internal cache object."
        self.cache.set(*args, **kwargs)

    def add(self, *args, **kwargs):
        "Proxy function for internal cache object."
        self.cache.add(*args, **kwargs)

    def delete(self, *args, **kwargs):
        "Proxy function for internal cache object."
        self.cache.delete(*args, **kwargs)

    def cached(self, timeout=None, key_prefix='view/%s', unless=None):
        """
        Decorator. Use this to cache a function. By default the cache key
        is `view/request.path`. You are able to use this decorator with any
        function by changing the `key_prefix`. If the token `%s` is located
        within the `key_prefix` then it will replace that with `request.path`

        Example::

            # An example view function
            @cache.cached(timeout=50)
            def big_foo():
                return big_bar_calc()

            # An example misc function to cache.
            @cache.cached(key_prefix='MyCachedList')
            def get_list():
                return [random.randrange(0, 1) for i in range(50000)]

        .. code-block:: pycon

            >>> my_list = get_list()

        :param timeout: Default None. If set to an integer, will cache for that
                        amount of time.
        :param key_prefix: Default 'view/%(request.path)s'. Beginning key to .
                           use for the cache key.
        :param unless: Default None. Cache will *always* execute the caching
                       facilities unless this callable is true.
                       This will bypass the caching entirely.
#.........这里部分代码省略.........
开发者ID:dag,项目名称:flask-cache,代码行数:103,代码来源:cache.py

示例13: Cache

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
class Cache(object):
    """Base class for TimeGate caches."""

    def __init__(self, path, tolerance, expiration, max_values, run_tests=True,
                 max_file_size=0):
        """Constructor method.

        :param path: The path of the cache database file.
        :param tolerance: The tolerance, in seconds to which a TimeMap is
        considered young enough to be used as is.
        :param expiration: How long, in seconds, the cache entries are stored
        every get will be a CACHE MISS.
        :param max_values: The maximum number of TimeMaps stored in cache
        before some are deleted
        :param run_tests: (Optional) Tests the cache at initialization.
        :param max_file_size: (Optional) The maximum size (in Bytes) for a
        TimeMap cache value. When max_file_size=0, there is no limit to
        a cache value. When max_file_size=X > 0, the cache will not
        store TimeMap that require more than X Bytes on disk.
        """
        # Parameters Check
        if tolerance <= 0 or expiration <= 0 or max_values <= 0:
            raise CacheError("Cannot create cache: all parameters must be > 0")

        self.tolerance = relativedelta(seconds=tolerance)
        self.path = path.rstrip('/')
        self.max_file_size = max(max_file_size, 0)
        self.CHECK_SIZE = self.max_file_size > 0
        self.max_values = max_values
        self.backend = FileSystemCache(path,
                                       threshold=self.max_values,
                                       default_timeout=expiration)

        # Testing cache
        if run_tests:
            try:
                key = '1'
                val = 1
                self.backend.set(key, val)
                assert (not self.CHECK_SIZE) or self._check_size(key) > 0
                assert self.backend.get(key) == val
                os.remove(self.path + '/' + md5(key).hexdigest())
            except Exception as e:
                raise CacheError("Error testing cache: %s" % e)

        logging.debug(
            "Cache created. max_files = %d. Expiration = %d. "
            "max_file_size = %d" % (
                self.max_values, expiration, self.max_file_size))

    def get_until(self, uri_r, date):
        """Returns the TimeMap (memento,datetime)-list for the requested
        Memento. The TimeMap is guaranteed to span at least until the 'date'
        parameter, within the tolerance.

        :param uri_r: The URI-R of the resource as a string.
        :param date: The target date. It is the accept-datetime for TimeGate
        requests, and the current date. The cache will return all
        Mementos prior to this date (within cache.tolerance parameter)
        :return: [(memento_uri_string, datetime_obj),...] list if it is
        in cache and if it is within the cache tolerance for *date*,
        None otherwise.
        """
        # Query the backend for stored cache values to that memento
        key = uri_r
        try:
            val = self.backend.get(key)
        except Exception as e:
            logging.error("Exception loading cache content: %s" % e)
            return None

        if val:
            # There is a value in the cache
            timestamp, timemap = val
            logging.info("Cached value exists for %s" % uri_r)
            if date > timestamp + self.tolerance:
                logging.info("Cache MISS: value outdated for %s" % uri_r)
                timemap = None
            else:
                logging.info("Cache HIT: found value for %s" % uri_r)
        else:
            # Cache MISS: No value
            logging.info("Cache MISS: No cached value for %s" % uri_r)
            timemap = None

        return timemap

    def get_all(self, uri_r):
        """Request the whole TimeMap for that uri.

        :param uri_r: the URI-R of the resource.
        :return: [(memento_uri_string, datetime_obj),...] list if it is in
        cache and if it is within the cache tolerance, None otherwise.
        """
        return self.get_until(uri_r, timegate_utils.now())

    def refresh(self, uri_r, getter, *args, **kwargs):
        """Refreshes the cached TimeMap for a specific resource and returns it.

        :param uri_r: The original resource URI to refresh the TimeMap
#.........这里部分代码省略.........
开发者ID:machawk1,项目名称:timegate,代码行数:103,代码来源:cache.py

示例14: FileSystemSessionInterface

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
class FileSystemSessionInterface(SessionInterface):
    """Uses the :class:`werkzeug.contrib.cache.FileSystemCache` as a session
    backend.

    .. versionadded:: 0.2
        The `use_signer` parameter was added.

    :param cache_dir: the directory where session files are stored.
    :param threshold: the maximum number of items the session stores before it
                      starts deleting some.
    :param mode: the file mode wanted for the session files, default 0600
    :param key_prefix: A prefix that is added to FileSystemCache store keys.
    :param use_signer: Whether to sign the session id cookie or not.
    """

    session_class = FileSystemSession

    def __init__(self, cache_dir, threshold, mode, key_prefix,
                 use_signer=False):
        from werkzeug.contrib.cache import FileSystemCache
        self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode) #FileSystemCache是从上句导入的,threshold代表最多纪录条数
        self.key_prefix = key_prefix
        self.use_signer = use_signer

    def open_session(self, app, request):
        sid = request.cookies.get(app.session_cookie_name)
        if not sid:
            sid = self._generate_sid()
            return self.session_class(sid=sid)
        if self.use_signer:
            signer = self._get_signer(app)
            if signer is None:
                return None
            try:
                sid = signer.unsign(sid)
            except BadSignature:
                sid = None

        data = self.cache.get(self.key_prefix + sid)    #这是根据session_id获取session值
        if data is not None:
            return self.session_class(data, sid=sid)
        return self.session_class(sid=sid)
    
    def save_session(self, app, session, response):
        domain = self.get_cookie_domain(app)
        path = self.get_cookie_path(app)
        if not session:     #验证过了,就是判断session是否为空(空字典)
            if session.modified:
                self.cache.delete(self.key_prefix + session.sid)
                response.delete_cookie(app.session_cookie_name,
                                       domain=domain, path=path)
            return

        # Modification case.  There are upsides and downsides to
        # emitting a set-cookie header each request.  The behavior
        # is controlled by the :meth:`should_set_cookie` method
        # which performs a quick check to figure out if the cookie
        # should be set or not.  This is controlled by the
        # SESSION_REFRESH_EACH_REQUEST config flag as well as
        # the permanent flag on the session itself.
        #if not self.should_set_cookie(app, session):
        #    return

        httponly = self.get_cookie_httponly(app)
        secure = self.get_cookie_secure(app)
        expires = self.get_expiration_time(app, session)
        #data = dict(session)
        #self.cache.set(self.key_prefix + session.sid, data,
        #                 int(app.permanent_session_lifetime.total_seconds()))
        if self.use_signer: #签名加密
            session_id = self._get_signer(app).sign(session.sid)
        else:
            session_id = session.sid
        response.set_cookie(app.session_cookie_name, session_id,
                            expires=expires, httponly=httponly,
                            domain=domain, path=path, secure=secure)

    
    def save_session_without_response(self, app, session):

        #httponly = self.get_cookie_httponly(app)
        #secure = self.get_cookie_secure(app)
        #expires = self.get_expiration_time(app, session)
        data = dict(session)
        self.cache.set(self.key_prefix + session.sid, data,    
                     int(app.permanent_session_lifetime.total_seconds()))

    def judge_attack(self, app, request):   #判断两次间隔的访问是否大于三秒
        sid = request.cookies.get(app.session_cookie_name)
        if not sid:
            return False
        current_time = time.time()
        try:
            last_time = self.cache.get(self.key_prefix + sid)['time']    #这是根据session_id获取session值
        except:
            return False
        if current_time-last_time < 3:
            return True
        return False
开发者ID:runner56,项目名称:flask_tzquery,代码行数:101,代码来源:sessions.py

示例15: exit

# 需要导入模块: from werkzeug.contrib.cache import FileSystemCache [as 别名]
# 或者: from werkzeug.contrib.cache.FileSystemCache import set [as 别名]
    Feedliste ist eine Datei mit einem URL zu einem ATOM-Feed pro Zeile.
    Grenzwert ist die maximale Entfernung von Partyteilnehmern in Sekunden
    unter der Annahme, dass die Lichtgeschwindigkeit 1 m/s beträgt.
""")
        exit(1)

    current_events = {}
    with open(filename, 'r') as feeds:
        progress = ProgressBar(maxval=len(feeds.readlines()))

    with open(filename, 'r') as feeds:
        for line in feeds:
            feed_url = line.strip()
            cached_content = feed_cache.get(feed_url)
            if not cached_content:
                request = get(feed_url)
                events = getEvents(StringIO(request.text.encode('utf-8')))
                feed_cache.set(feed_url, request.text.encode('utf-8'))
            else:
                events = getEvents(StringIO(cached_content))
            current_events = updateEvents(current_events, events)
            progress.update(progress.currval+1)

    clustering = HierarchicalClustering(current_events.values(), timelikeInterval)
    clusters = clustering.getlevel(threshold)

    for cluster in clusters:
        if len(cluster) > 2:
            partyPrint(cluster, threshold)
开发者ID:erlehmann,项目名称:partycluster,代码行数:31,代码来源:partycluster.py


注:本文中的werkzeug.contrib.cache.FileSystemCache.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。