本文整理汇总了Python中schema.Schema.load方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.load方法的具体用法?Python Schema.load怎么用?Python Schema.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schema.Schema
的用法示例。
在下文中一共展示了Schema.load方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EventResource
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import load [as 别名]
import falcon
import uuid
import logging
from datetime import datetime
from config import CONFIG
from database import Database, NotFound
from schema import Schema
from serialization import make_private, merge_private, remove_private
from auth import require_auth
from misc_util import load_design_doc, validate_user_list
DB_EVENTS = CONFIG["databases"]["event"]
EVENT_DESIGN_DOC = "event.json"
EVENT_SCHEMA = Schema.load("event")
COMMENT_SCHEMA = Schema.load("comment")
@require_auth
class EventResource(object):
def __init__(self, Db=Database):
self.db = Db()
self.db.create_db(DB_EVENTS, ignore_exists=True)
load_design_doc(EVENT_DESIGN_DOC, DB_EVENTS)
self.logger = logging.getLogger("EventResource")
def on_post(self, req, resp):
jobj = req.context['doc']
username = req.context["user"]
self._validate_doc(jobj, username)
resp.body = self.db.save_doc(DB_EVENTS, jobj)
示例2: UserResource
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import load [as 别名]
import falcon
import uuid
import logging
from config import CONFIG
from database import Database, NotFound
from schema import Schema
from serialization import make_private
from misc_util import load_design_doc
import auth
DB_USER = CONFIG["databases"]["user"]
USER_SEARCH_DESIGN_DOC = "user_search.json"
USER_SCHEMA = Schema.load("user")
class UserResource(object):
def __init__(self, Db=Database):
self.db = Db()
self.db.create_db(DB_USER, ignore_exists=True)
self.logger = logging.getLogger("UserResource")
def on_post(self, req, resp):
user = req.context['doc']
USER_SCHEMA.validate(user)
username = user.pop("username")
self.logger.info("Attemted signup with username %s" % username)
if self.username_exists(username):
self.logger.info("Attemted signup with duplicate username %s" % username)
示例3: require_auth
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import load [as 别名]
import falcon
import scrypt
import uuid
import datetime
import logging
from config import CONFIG
from database import Database
from schema import Schema
from serialization import decode_datetime, make_private
DB_AUTH = CONFIG["databases"]["auth"]
DB_USER = CONFIG["databases"]["user"]
AUTH_SCHEMA = Schema.load("auth")
def require_auth(fun):
database = Database()
logger = logging.getLogger("Auth")
def get_auth_doc_for_token(auth_token):
if auth_token is None:
return None
return database.get_doc(DB_AUTH, auth_token, default=None)
def process_request(req, resp, resource, params):
auth_token = req.get_header("X-Auth-Token")
auth_doc = get_auth_doc_for_token(auth_token)
if auth_doc is None:
logger.warning("Auth token %s is invalid" % auth_token)
raise falcon.HTTPUnauthorized("Invalid auth token",
示例4: FriendGroupResource
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import load [as 别名]
import falcon
import uuid
import logging
from config import CONFIG
from database import Database, NotFound
from schema import Schema
from serialization import make_private, merge_private
from auth import require_auth
from misc_util import load_design_doc
DB_FRIEND_GROUPS = CONFIG["databases"]["friend_group"]
DB_USERS = CONFIG["databases"]["user"]
FRIEND_DESIGN_DOC = "friends.json"
GROUP_SCHEMA = Schema.load("friend_group")
@require_auth
class FriendGroupResource(object):
def __init__(self, Db=Database):
self.db = Db()
self.db.create_db(DB_FRIEND_GROUPS, ignore_exists=True)
load_design_doc(FRIEND_DESIGN_DOC, DB_FRIEND_GROUPS)
self.logger = logging.getLogger("UserResource")
def on_post(self, req, resp):
jobj = req.context['doc']
username = req.context["user"]
self._validate_doc(jobj, username)
resp.body = self.db.save_doc(DB_FRIEND_GROUPS, jobj)