• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python web.storage函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: work_wrapper

def work_wrapper(w):
    d = web.storage(
        key="/works/" + w["key"],
        title=w["title"],
        edition_count=w["edition_count"]
    )

    if "cover_id" in w:
        d.cover_id = w["cover_id"]
    elif "cover_edition_key" in w:
        book = web.ctx.site.get("/books/" + w["cover_edition_key"])
        cover = book and book.get_cover()
        d.cover_id = cover and cover.id or None
        d.cover_edition_key = w['cover_edition_key']
    else:
        d.cover_id = None

    # special care to handle missing author_key/author_name in the solr record
    w.setdefault('author_key', [])
    w.setdefault('author_name', [])
    
    d.authors = [web.storage(key='/authors/' + k, name=n)
                 for k, n in zip(w['author_key'], w['author_name'])]

    d.first_publish_year = (w['first_publish_year'][0] if 'first_publish_year' in w else None)
    d.ia = w.get('ia', [])
    d.has_fulltext = w.get('has_fulltext', "false")
    return d
开发者ID:ziwar,项目名称:openlibrary,代码行数:28,代码来源:search.py


示例2: create_account_manager

    def create_account_manager(self):
        # Hack to use the accounts stuff from Infogami
        infobase_config.user_root = "/people"

        store = web.storage(store=self.store)
        site = web.storage(store=store, save_many=self.save_many)
        return account.AccountManager(site, config.infobase['secret_key'])
开发者ID:randomecho,项目名称:openlibrary,代码行数:7,代码来源:mock_infobase.py


示例3: get_voter_details_old

def get_voter_details_old(voterid):
    # ignore voterids like "yes" etc.
    if len(voterid) <= 4:
        return

    logger.info("get_voter_details %s", voterid)    
    try:
        b = web.Browser()
        b.open(URL)
        b.select_form(index=0)
        b['ctl00$ContentPlaceHolder1$ddlDistrict'] = ['21']
        b['ctl00$ContentPlaceHolder1$txtEpic'] = voterid
        b.submit()
    except Exception:
        logger.error("failed to request voterid details for %s", voterid, exc_info=True)
        return web.storage()

    soup = b.get_soup()
    table = soup.find("table", {"id": "ctl00_ContentPlaceHolder1_GridView1"})
    if not table:
        return None
    last_row = table.findAll("tr")[-1]
    data = [td.getText() for td in last_row.findAll(("td", "tr"))]
    # skip the first one, which is a button
    data = data[1:]
    cols = "ac_num ac_name part_no sl_no first_name last_name rel_firstname rel_lastname sex age".split()
    d = dict(zip(cols, data))
    d['voterid'] = voterid
    logger.info("voter info %s %s", voterid, d)   
    return web.storage(d)
开发者ID:anandology,项目名称:voternet,代码行数:30,代码来源:voterlib.py


示例4: work_object

def work_object(w): # called by works_by_author
    ia = w.get('ia', [])

    if config.get("single_core_solr"):
        key = w['key']
    else:
        key = '/works/' + w['key']

    obj = dict(
        authors = [web.storage(key='/authors/' + k, name=n) for k, n in zip(w['author_key'], w['author_name'])],
        edition_count = w['edition_count'],
        key = key,
        title = w['title'],
        public_scan = w.get('public_scan_b', bool(ia)),
        lending_edition = w.get('lending_edition_s', ''),
        lending_identifier = w.get('lending_identifier_s', ''),
        overdrive = (w['overdrive_s'].split(';') if 'overdrive_s' in w else []),
        collections = set(w['ia_collection_s'].split(';') if 'ia_collection_s' in w else []),
        url = key + '/' + urlsafe(w['title']),
        cover_edition_key = w.get('cover_edition_key'),
        first_publish_year = (w['first_publish_year'] if 'first_publish_year' in w else None),
        ia = w.get('ia', []),
        cover_i = w.get('cover_i')
    )

    if obj['lending_identifier']:
        doc = web.ctx.site.store.get("ebooks/" + obj['lending_identifier']) or {}
        obj['checked_out'] = doc.get("borrowed") == "true"
    else:
        obj['checked_out'] = False
    
    for f in 'has_fulltext', 'subtitle':
        if w.get(f):
            obj[f] = w[f]
    return web.storage(obj)
开发者ID:bfalling,项目名称:openlibrary,代码行数:35,代码来源:code.py


示例5: do_search

def do_search(param, sort, page=1, rows=100):
    (reply, solr_select, q_list) = run_solr_query(param, rows, page, sort)
    is_bad = False
    if reply.startswith('<html'):
        is_bad = True
    if not is_bad:
        try:
            root = XML(reply)
        except XMLSyntaxError:
            is_bad = True
    if is_bad:
        m = re_pre.search(reply)
        return web.storage(
            facet_counts = None,
            docs = [],
            is_advanced = bool(param.get('q', 'None')),
            num_found = None,
            solr_select = solr_select,
            q_list = q_list,
            error = (web.htmlunquote(m.group(1)) if m else reply),
        )

    docs = root.find('result')
    return web.storage(
        facet_counts = read_facets(root),
        docs = docs,
        is_advanced = bool(param.get('q', 'None')),
        num_found = (int(docs.attrib['numFound']) if docs is not None else None),
        solr_select = solr_select,
        q_list = q_list,
        error = None,
    )
开发者ID:sribanta,项目名称:openlibrary,代码行数:32,代码来源:code.py


示例6: f

        def f():
            web.ctx.disable_permission_check = True

            d = web.storage({"key": key, "type": {"key": "/type/user"}})
            d.update(data)
            self.site.save(key, d, timestamp=timestamp, author=d, comment="Created new account")

            q = make_query(d)
            account_bot = config.get('account_bot')
            account_bot = account_bot and web.storage({"key": account_bot, "type": {"key": "/type/user"}})
            self.site.save_many(q, ip=ip, timestamp=timestamp, author=account_bot, action='register', comment="Setup new account")
            self.site.store.register(key, email, enc_password)
            self.update_user_details(username, verified=True, active=True)

            # Add account doc to store
            olddoc = self.site.store.store.get("account/" + username) or {}
            
            doc = {
                "_key": "account/" + username,
                "_rev": olddoc.get("_rev"),
                "type": "account",
                "registered_on": olddoc['registered_on'],
                "activated_on": timestamp.isoformat(),
                "last_login": timestamp.isoformat(),
            }
            self.site.store.store.put("account/" + username, doc)
开发者ID:internetarchive,项目名称:infogami,代码行数:26,代码来源:account.py


示例7: _old_get_meta_xml

def _old_get_meta_xml(itemid):
    """Returns the contents of meta_xml as JSON.
    """
    itemid = web.safestr(itemid.strip())
    url = 'http://www.archive.org/download/%s/%s_meta.xml' % (itemid, itemid)
    try:
        stats.begin('archive.org', url=url)
        metaxml = urllib2.urlopen(url).read()
        stats.end()
    except IOError:
        logger.error("Failed to download _meta.xml for %s", itemid, exc_info=True)
        stats.end()
        return web.storage()

    # archive.org returns html on internal errors.
    # Checking for valid xml before trying to parse it.
    if not metaxml.strip().startswith("<?xml"):
        return web.storage()

    try:
        defaults = {"collection": [], "external-identifier": []}
        return web.storage(xml2dict(metaxml, **defaults))
    except Exception as e:
        logger.error("Failed to parse metaxml for %s", itemid, exc_info=True)
        return web.storage()
开发者ID:internetarchive,项目名称:openlibrary,代码行数:25,代码来源:ia.py


示例8: work_wrapper

def work_wrapper(w):
    d = web.storage(key="/works/" + w["key"], title=w["title"], edition_count=w["edition_count"])

    if "cover_id" in w:
        d.cover_id = w["cover_id"]
    elif "cover_edition_key" in w:
        book = web.ctx.site.get("/books/" + w["cover_edition_key"])
        cover = book and book.get_cover()
        d.cover_id = cover and cover.id or None
        d.cover_edition_key = w["cover_edition_key"]
    else:
        d.cover_id = None
    d.subject = w.get("subject", [])
    ia_collection = w["ia_collection_s"].split(";") if "ia_collection_s" in w else []
    d.ia_collection = ia_collection
    d.lendinglibrary = "lendinglibrary" in ia_collection
    d.printdisabled = "printdisabled" in ia_collection
    d.lending_edition = w.get("lending_edition_s", "")
    d.overdrive = w["overdrive_s"].split(";")[0] if "overdrive_s" in w else ""

    # special care to handle missing author_key/author_name in the solr record
    w.setdefault("author_key", [])
    w.setdefault("author_name", [])

    d.authors = [web.storage(key="/authors/" + k, name=n) for k, n in zip(w["author_key"], w["author_name"])]

    d.first_publish_year = w["first_publish_year"][0] if "first_publish_year" in w else None
    d.ia = w.get("ia", [])
    d.public_scan = w.get("public_scan_b", bool(d.ia))
    d.has_fulltext = w.get("has_fulltext", "false")
    return d
开发者ID:bowlofeggs,项目名称:openlibrary,代码行数:31,代码来源:search.py


示例9: GET

    def GET(self, page_path):
        try:
            page = get_page_by_path(page_path)
            if not page.is_published and not auth.get_user():
                raise flash.redirect(_(page_access_forbidden_text), "/login")
            load_page_data(page)

            if auth.has_role("admin"):
                json_data = web.storage(
                    page=page_to_json(page),
                    pages=pages_to_json(get_pages_in_tree_order()),
                )
            else:
                json_data = web.storage()

            if "edit" in web.input() and auth.has_role("admin"):
                json_data.update(
                    page_block=block_to_json(
                        get_page_block_by_page_id(page.id)),
                    template_blocks=template_blocks_to_json()
                )
            else:
                load_page_blocks(page.id)

            return render.pages.page(json_data)
        except IndexError:
            raise web.notfound()
开发者ID:w0rm,项目名称:pre-stonegarden-dev,代码行数:27,代码来源:pages.py


示例10: POST

 def POST(self, path):
     i = web.input(_method='post')
     i = web.storage(helpers.unflatten(i))
     i.key = path
     
     _ = web.storage((k, i.pop(k)) for k in i.keys() if k.startswith('_'))
     action = self.get_action(_)
     comment = _.get('_comment', None)
     
     for k, v in i.items():
         i[k] = self.trim(v)
         
     p = web.ctx.site.get(path) or web.ctx.site.new(path, {})
     p.update(i)
     
     if action == 'preview':
         p['comment_'] = comment
         return render.editpage(p, preview=True)
     elif action == 'save':
         try:
             p._save(comment)
             path = web.input(_method='GET', redirect=None).redirect or web.changequery(query={})
             raise web.seeother(path)
         except (ClientException, db.ValidationException), e:            
             add_flash_message('error', str(e))
             p['comment_'] = comment                
             return render.editpage(p)
开发者ID:EdwardBetts,项目名称:infogami,代码行数:27,代码来源:code.py


示例11: get_meta_xml

def get_meta_xml(itemid):
    """Returns the contents of meta_xml as JSON.
    """
    itemid = itemid.strip()
    
    url = 'http://www.archive.org/download/%s/%s_meta.xml' % (itemid, itemid)
    try:
        stats.begin("archive.org", url=url)
        metaxml = urllib2.urlopen(url).read()
        stats.end()
    except IOError:
        stats.end()
        return web.storage()
        
    # archive.org returns html on internal errors. 
    # Checking for valid xml before trying to parse it.
    if not metaxml.strip().startswith("<?xml"):
        return web.storage()
    
    try:
        defaults = {"collection": [], "external-identifier": []}
        return web.storage(xml2dict(metaxml, **defaults))
    except Exception, e:
        print >> web.debug, "Failed to parse metaxml for %s: %s" % (itemid, str(e)) 
        return web.storage()
开发者ID:amoghravish,项目名称:openlibrary,代码行数:25,代码来源:ia.py


示例12: __init__

 def __init__(self):
     init_dbcontext()
     web.cache=web.Storage()
     web.cache.sku_properid_datas=web.storage()
     web.cache.sku_properval_datas=web.storage()
     web.cache.cate_attr_datas=web.storage()
     self.access_token=''
     self.get_token_from_db()
开发者ID:aveenzhou,项目名称:smt_app,代码行数:8,代码来源:get_smt_products.py


示例13: load_extensions

def load_extensions():
    from common import db
    db.init(get_conn())
    web.extensions = web.storage()
    web.extensions.db = db
    web.extensions.ensure_login = ensure_login

    web.app_extensions = web.storage()
开发者ID:onlytiancai,项目名称:webappbox,代码行数:8,代码来源:extension.py


示例14: get_doc

def get_doc(doc): # called from work_search template
    e_ia = doc.find("arr[@name='ia']")
    first_pub = None
    e_first_pub = doc.find("int[@name='first_publish_year']")
    if e_first_pub is not None:
        first_pub = e_first_pub.text
    e_first_edition = doc.find("str[@name='first_edition']")
    first_edition = None
    if e_first_edition is not None:
        first_edition = e_first_edition.text

    work_subtitle = None
    e_subtitle = doc.find("str[@name='subtitle']")
    if e_subtitle is not None:
        work_subtitle = e_subtitle.text

    if doc.find("arr[@name='author_key']") is None:
        assert doc.find("arr[@name='author_name']") is None
        authors = []
    else:
        ak = [e.text for e in doc.find("arr[@name='author_key']")]
        an = [e.text for e in doc.find("arr[@name='author_name']")]
        authors = [web.storage(key=key, name=name, url="/authors/%s/%s" % (key, (urlsafe(name) if name is not None else 'noname'))) for key, name in zip(ak, an)]

    cover = doc.find("str[@name='cover_edition_key']")
    e_public_scan = doc.find("bool[@name='public_scan_b']")
    e_overdrive = doc.find("str[@name='overdrive_s']")
    e_lending_edition = doc.find("str[@name='lending_edition_s']")
    e_collection = doc.find("str[@name='ia_collection_s']")
    collections = set()
    if e_collection is not None:
        collections = set(e_collection.text.split(';'))

    doc = web.storage(
        key = doc.find("str[@name='key']").text,
        title = doc.find("str[@name='title']").text,
        edition_count = int(doc.find("int[@name='edition_count']").text),
        ia = [e.text for e in (e_ia if e_ia is not None else [])],
        has_fulltext = (doc.find("bool[@name='has_fulltext']").text == 'true'),
        public_scan = ((e_public_scan.text == 'true') if e_public_scan is not None else (e_ia is not None)),
        overdrive = (e_overdrive.text.split(';') if e_overdrive is not None else []),
        lending_edition = (e_lending_edition.text if e_lending_edition is not None else None),
        collections = collections,
        authors = authors,
        first_publish_year = first_pub,
        first_edition = first_edition,
        subtitle = work_subtitle,
        cover_edition_key = (cover.text if cover is not None else None),
    )

    doc.url = '/works/' + doc.key + '/' + urlsafe(doc.title)
    
    if not doc.public_scan and doc.lending_edition:
        store_doc = web.ctx.site.store.get("ebooks/books/" + doc.lending_edition) or {}
        doc.checked_out = store_doc.get("borrowed") == "true"
    else:
        doc.checked_out = "false"
    return doc
开发者ID:ashumeow,项目名称:openlibrary,代码行数:58,代码来源:code.py


示例15: get_property

 def get_property(self, type, name):
     if name == 'type':
         return web.storage(name='type', expected_type=web.storage(key='/type/type', kind="regular"), unique=True)
     elif name in ['permission', 'child_permission']:
         return web.storage(name=name, expected_type=web.storage(key='/type/permission', kind="regular"), unique=True)
     else:
         for p in type.get('properties', []):
             if p.get('name') == name:
                 return p
开发者ID:termim,项目名称:infogami,代码行数:9,代码来源:writequery.py


示例16: GET

 def GET(self):
     rows = []
     with open('trend5upradiocount.csv', 'rb') as csvfile:
         spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
         for row in spamreader:
             if row[0]=='trend5':continue
             rows.append(web.storage(trend=row[0],p=row[1],count=row[2]))        
     r = web.storage(rows=rows,query='',count=len(rows)) 
     return render.trend(r)  
开发者ID:catabram,项目名称:forecast,代码行数:9,代码来源:main.py


示例17: get_talk

def get_talk(id):
    try:
        talk = web.ctx.site.store["talks/" + str(id)]
    except KeyError:
        return None

    talk['key'] = 'talks/' + id
    talk['files'] = [web.storage(f) for f in talk.get('files', [])]
    return web.storage(talk)
开发者ID:pythonindia,项目名称:in.pycon.org,代码行数:9,代码来源:code.py


示例18: get_paging

def get_paging(start, max_results, query=False, results_per_page=15,
    window_size=15, max_allowed_results=1000):
    max_allowed_pages = max_allowed_results / results_per_page

    c_page = start / results_per_page + 1
    if not start:
        c_page = 1
    nb_pages = max_results / results_per_page
    if max_results % results_per_page != 0:
        nb_pages += 1

    left_a = right_a = False
    if c_page > 1:
        left_a = (c_page - 2) * results_per_page
    if c_page < nb_pages:
        right_a = start + results_per_page
    if right_a > max_allowed_pages:
        right_a = False

    left = c_page - window_size / 2
    if left < 1:
        left = 1
    right = left + window_size - 1
    max_pages = (nb_pages > max_allowed_pages) and max_allowed_pages or nb_pages
    if right > max_pages:
        left = left - (right - max_pages)
        if left < 1:
            left = 1
        right = max_pages

    pages = []
    for i in range(left, right + 1):
        pages.append(web.storage(
            number=i,
            start=(i - 1) * results_per_page
        ))

    leftmost_a = rightmost_a = False
    if pages and pages[0].number > 1:
        leftmost_a = web.storage(number=1, start=0)
    if pages and pages[-1].number < nb_pages and nb_pages < max_allowed_pages:
        rightmost_a = web.storage(
            number=nb_pages, start=(nb_pages - 1) * results_per_page)

    return web.storage(
        start=start,
        max_results=max_results,
        c_page=c_page,
        nb_pages=nb_pages,
        pages=pages,
        leftmost_a=leftmost_a,
        left_a=left_a,
        right_a=right_a,
        rightmost_a=rightmost_a,
        query_enc=query and urllib.quote(query) or ''
    )
开发者ID:Roverok,项目名称:CloudMining,代码行数:56,代码来源:paging.py


示例19: process

        def process(name, value):
            if value:
                if not isinstance(value, list):
                    value = [value]

                id = id_map.get(name) or web.storage(name=name, label=name, url_format=None)
                for v in value:
                    d[id.name] = web.storage(
                        name=id.name, label=id.label, value=v, url=id.get("url") and id.url.replace("@@@", v)
                    )
开发者ID:RaceList,项目名称:openlibrary,代码行数:10,代码来源:models.py


示例20: read_schema

    def read_schema(self, db):
        rows = db.query("SELECT table_name, column_name,  data_type "
            + " FROM information_schema.columns"
            + " WHERE table_schema = 'public'")

        schema = web.storage()
        for row in rows:
            t = schema.setdefault(row.table_name, web.storage())
            t[row.column_name] = row
        return schema
开发者ID:lukasklein,项目名称:openlibrary,代码行数:10,代码来源:migrate_db.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python web.unauthorized函数代码示例发布时间:2022-05-26
下一篇:
Python web.startData函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap