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


Python storage.Storage方法代码示例

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


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

示例1: label_images_task

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def label_images_task(image_urls):
    vision = VisionApi()
    storage = Storage()

    label_images(vision, storage, image_urls) 
开发者ID:GoogleCloudPlatform,项目名称:cloud-vision,代码行数:7,代码来源:main.py

示例2: test_attribute

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def test_attribute(self):
        """ Tests Storage attribute handling """

        s = Storage(a=1)

        self.assertEqual(s.a, 1)
        self.assertEqual(s['a'], 1)
        self.assertEqual(s.b, None)

        s.b = 2
        self.assertEqual(s.a, 1)
        self.assertEqual(s['a'], 1)
        self.assertEqual(s.b, 2)
        self.assertEqual(s['b'], 2)

        s['c'] = 3
        self.assertEqual(s.c, 3)
        self.assertEqual(s['c'], 3)

        s.d = list()
        self.assertTrue(s.d is s['d']) 
开发者ID:StuffShare,项目名称:StuffShare,代码行数:23,代码来源:test_storage.py

示例3: test_store_none

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def test_store_none(self):
        """ Test Storage store-None handling
            s.key = None deletes an item
            s['key'] = None sets the item to None
        """

        s = Storage(a=1)

        self.assertTrue('a' in s)
        self.assertFalse('b' in s)
        s.a = None
        # self.assertFalse('a' in s) # how about this?

        s.a = 1
        self.assertTrue('a' in s)
        s['a'] = None
        self.assertTrue('a' in s)
        self.assertTrue(s.a is None) 
开发者ID:StuffShare,项目名称:StuffShare,代码行数:20,代码来源:test_storage.py

示例4: testCacheOnDisk

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def testCacheOnDisk(self):

        # defaults to mode='http'

        s = Storage({'application': 'admin',
                     'folder': 'applications/admin'})
        cache = CacheOnDisk(s)
        self.assertEqual(cache('a', lambda: 1, 0), 1)
        self.assertEqual(cache('a', lambda: 2, 100), 1)
        cache.clear('b')
        self.assertEqual(cache('a', lambda: 2, 100), 1)
        cache.clear('a')
        self.assertEqual(cache('a', lambda: 2, 100), 2)
        cache.clear()
        self.assertEqual(cache('a', lambda: 3, 100), 3)
        self.assertEqual(cache('a', lambda: 4, 0), 4) 
开发者ID:StuffShare,项目名称:StuffShare,代码行数:18,代码来源:test_cache.py

示例5: testURL

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def testURL(self):
        self.assertEqual(URL('a', 'c', 'f', args='1'), '/a/c/f/1')
        self.assertEqual(URL('a', 'c', 'f', args=('1', '2')), '/a/c/f/1/2')
        self.assertEqual(URL('a', 'c', 'f', args=['1', '2']), '/a/c/f/1/2')
        self.assertEqual(URL('a', 'c', '/f'), '/a/c/f')
        self.assertEqual(URL('a', 'c', 'f.json'), '/a/c/f.json')
        self.assertRaises(SyntaxError, URL, *['a'])
        request = Storage()
        request.application = 'a'
        request.controller = 'c'
        request.function = 'f'
        request.env = {}
        from globals import current
        current.request = request
        must_return = '/a/c/f'
        self.assertEqual(URL('f'), must_return)
        self.assertEqual(URL('c', 'f'), must_return)
        self.assertEqual(URL('a', 'c', 'f'), must_return)
        self.assertEqual(URL('a', 'c', 'f', extension='json'), '/a/c/f.json')
        def weird():
            pass
        self.assertEqual(URL('a', 'c', weird), '/a/c/weird')
        self.assertRaises(SyntaxError, URL, *['a','c', 1]) 
开发者ID:StuffShare,项目名称:StuffShare,代码行数:25,代码来源:test_html.py

示例6: __init__

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def __init__(self, notebook_name, path, mask, format, twoway=False):
        # check auth
        if not Storage().getUserToken():
            raise Exception("Auth error. There is not any oAuthToken.")

        #set path
        if not path:
            raise Exception("Path to sync directories does not select.")

        if not os.path.exists(path):
            raise Exception("Path to sync directories does not exist.")

        self.path = path

        #set mask
        if not mask:
            mask = "*.*"

        self.mask = mask

        #set format
        if not format:
            format = "plain"

        self.format = format

        if format == "markdown":
            self.extension = ".md"
        else:
            self.extension = ".txt"

        self.twoway = twoway

        logger.info('Sync Start')

        #set notebook
        self.notebook_guid,\
        self.notebook_name = self._get_notebook(notebook_name, path)

        # all is Ok
        self.all_set = True 
开发者ID:Xunius,项目名称:txt2evernote,代码行数:43,代码来源:gnsync.py

示例7: EdamException

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def EdamException(func):
        def wrapper(*args, **kwargs):
            try:
                return func(*args, **kwargs)
            except Exception, e:
                logging.error("Error: %s : %s", func.__name__, str(e))

                if not hasattr(e, 'errorCode'):
                    out.failureMessage("Sorry, operation has failed!!!.")
                    tools.exitErr()

                errorCode = int(e.errorCode)

                # auth-token error, re-auth
                if errorCode == 9:
                    storage = Storage()
                    storage.removeUser()
                    GeekNote()
                    return func(*args, **kwargs)

                elif errorCode == 3:
                    out.failureMessage("Sorry, you do not have permissions "
                                       "to do this operation.")

                # Rate limited
                # Patched because otherwise if you get rate limited you still keep
                # hammering the server on scripts
                elif errorCode == 19:
                    print("\nRate Limit Hit: Please wait %s seconds before continuing" %
                          str(e.rateLimitDuration))
                    tools.exitErr()

                else:
                    return False

                tools.exitErr()

        return wrapper 
开发者ID:Xunius,项目名称:txt2evernote,代码行数:40,代码来源:geeknote.py

示例8: getStorage

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def getStorage(self):
        if GeekNote.storage:
            return GeekNote.storage

        GeekNote.storage = Storage()
        return GeekNote.storage 
开发者ID:Xunius,项目名称:txt2evernote,代码行数:8,代码来源:geeknote.py

示例9: __init__

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def __init__(self):
        self.header = {
            'Accept': '*/*',
            'Accept-Encoding': 'gzip,deflate,sdch',
            'Accept-Language': 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
            'Connection': 'keep-alive',
            'Content-Type': 'application/x-www-form-urlencoded',
            'Host': 'music.163.com',
            'Referer': 'http://music.163.com/search/',
            'User-Agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36'  # NOQA
        }
        self.cookies = {'appver': '1.5.2'}
        self.playlist_class_dict = {}
        self.session = requests.Session()
        self.storage = Storage()
        self.session.cookies = LWPCookieJar(self.storage.cookie_path)
        try:
            self.session.cookies.load()
            self.file = file(self.storage.cookie_path, 'r')
            cookie = self.file.read()
            self.file.close()
            pattern = re.compile(r'\d{4}-\d{2}-\d{2}')
            str = pattern.findall(cookie)
            if str:
                if str[0] < time.strftime('%Y-%m-%d',
                                          time.localtime(time.time())):
                    self.storage.database['user'] = {
                        'username': '',
                        'password': '',
                        'user_id': '',
                        'nickname': '',
                    }
                    self.storage.save()
                    os.remove(self.storage.cookie_path)
        except IOError as e:
            log.error(e)
            self.session.cookies.save() 
开发者ID:nyanim,项目名称:nem-downloader,代码行数:40,代码来源:api.py

示例10: load

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def load(self):
        from storage import Storage as S
        from settings import STORAGE_FILE
        self.jsondata = S(STORAGE_FILE).get_or_create()
        del S, STORAGE_FILE
        gcc()
        return self 
开发者ID:gdassori,项目名称:microotp,代码行数:9,代码来源:core.py

示例11: testCacheOnDisk

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def testCacheOnDisk(self):

        # defaults to mode='http'
        s = Storage({'application': 'admin',
                     'folder': 'applications/admin'})
        cache = CacheOnDisk(s)
        self.assertEqual(cache('a', lambda: 1, 0), 1)
        self.assertEqual(cache('a', lambda: 2, 100), 1)
        cache.clear('b')
        self.assertEqual(cache('a', lambda: 2, 100), 1)
        cache.clear('a')
        self.assertEqual(cache('a', lambda: 2, 100), 2)
        cache.clear()
        self.assertEqual(cache('a', lambda: 3, 100), 3)
        self.assertEqual(cache('a', lambda: 4, 0), 4)
        #test singleton behaviour
        cache = CacheOnDisk(s)
        cache.clear()
        self.assertEqual(cache('a', lambda: 3, 100), 3)
        self.assertEqual(cache('a', lambda: 4, 0), 4)
        #test key deletion
        cache('a', None)
        self.assertEqual(cache('a', lambda: 5, 100), 5)
        #test increment
        self.assertEqual(cache.increment('a'), 6)
        self.assertEqual(cache('a', lambda: 1, 100), 6)
        cache.increment('b')
        self.assertEqual(cache('b', lambda: 'x', 100), 1) 
开发者ID:lucadealfaro,项目名称:true_review_web2py,代码行数:30,代码来源:test_cache.py

示例12: testCacheWithPrefix

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def testCacheWithPrefix(self):
        s = Storage({'application': 'admin',
                     'folder': 'applications/admin'})
        cache = Cache(s)
        prefix = cache.with_prefix(cache.ram,'prefix')
        self.assertEqual(prefix('a', lambda: 1, 0), 1)
        self.assertEqual(prefix('a', lambda: 2, 100), 1)
        self.assertEqual(cache.ram('prefixa', lambda: 2, 100), 1) 
开发者ID:lucadealfaro,项目名称:true_review_web2py,代码行数:10,代码来源:test_cache.py

示例13: testDALcache

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def testDALcache(self):
        s = Storage({'application': 'admin',
                     'folder': 'applications/admin'})
        cache = Cache(s)
        db = DAL(check_reserved=['all'])
        db.define_table('t_a', Field('f_a'))
        db.t_a.insert(f_a='test')
        db.commit()
        a = db(db.t_a.id > 0).select(cache=(cache.ram, 60), cacheable=True)
        b = db(db.t_a.id > 0).select(cache=(cache.ram, 60), cacheable=True)
        self.assertEqual(a.as_csv(), b.as_csv())
        c = db(db.t_a.id > 0).select(cache=(cache.disk, 60), cacheable=True)
        d = db(db.t_a.id > 0).select(cache=(cache.disk, 60), cacheable=True)
        self.assertEqual(c.as_csv(), d.as_csv())
        self.assertEqual(a.as_csv(), c.as_csv())
        self.assertEqual(b.as_csv(), d.as_csv())
        e = db(db.t_a.id > 0).select(cache=(cache.disk, 60))
        f = db(db.t_a.id > 0).select(cache=(cache.disk, 60))
        self.assertEqual(e.as_csv(), f.as_csv())
        self.assertEqual(a.as_csv(), f.as_csv())
        g = db(db.t_a.id > 0).select(cache=(cache.ram, 60))
        h = db(db.t_a.id > 0).select(cache=(cache.ram, 60))
        self.assertEqual(g.as_csv(), h.as_csv())
        self.assertEqual(a.as_csv(), h.as_csv())
        db.t_a.drop()
        db.close() 
开发者ID:lucadealfaro,项目名称:true_review_web2py,代码行数:28,代码来源:test_cache.py

示例14: testStaticURL

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def testStaticURL(self):
        # test response.static_version coupled with response.static_version_urls
        self.assertEqual(URL('a', 'c', 'f'), '/a/c/f')
        self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/design.css')
        response = Storage()
        response.static_version = '1.2.3'
        from globals import current
        current.response = response
        self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/design.css')
        response.static_version_urls = True
        self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/_1.2.3/design.css') 
开发者ID:lucadealfaro,项目名称:true_review_web2py,代码行数:13,代码来源:test_html.py

示例15: get_session

# 需要导入模块: import storage [as 别名]
# 或者: from storage import Storage [as 别名]
def get_session(request, other_application='admin'):
    """Checks that user is authorized to access other_application"""
    if request.application == other_application:
        raise KeyError
    try:
        session_id = request.cookies['session_id_' + other_application].value
        session_filename = os.path.join(
            up(request.folder), other_application, 'sessions', session_id)
        if not os.path.exists(session_filename):
            session_filename = generate(session_filename)
        osession = storage.load_storage(session_filename)
    except Exception, e:
        osession = storage.Storage()
    return osession 
开发者ID:lucadealfaro,项目名称:true_review_web2py,代码行数:16,代码来源:fileutils.py


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