當前位置: 首頁>>代碼示例>>Python>>正文


Python apis.APIValueError方法代碼示例

本文整理匯總了Python中apis.APIValueError方法的典型用法代碼示例。如果您正苦於以下問題:Python apis.APIValueError方法的具體用法?Python apis.APIValueError怎麽用?Python apis.APIValueError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在apis的用法示例。


在下文中一共展示了apis.APIValueError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: authenticate

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def authenticate(*,email,passwd):
	if not email:
		raise APIValueError('email','Invalid email')
	if not passwd:
		raise APIValueError('passwd','Invalid passwd')
	users = await User.findAll('email=?',[email])
	if len(users) == 0:
		raise APIValueError('email','Email not exist.')
	user = users[0]
	# check passwd
	sha1 = hashlib.sha1()
	sha1.update(user.id.encode('utf-8'))
	sha1.update(b':')
	sha1.update(passwd.encode('utf-8'))
	if user.passwd != sha1.hexdigest():
		raise APIValueError('passwd','passwd error')
	# authenticate ok set cookie
	r = web.Response()
	r.set_cookie(COOKIE_NAME,user2cookie(user,86400),max_age=86400,httponly=True)
	user.passwd = '******'
	r.content_type = 'application/json'
	r.body = json.dumps(user,ensure_ascii=False).encode('utf-8')
	return r

# ?? 
開發者ID:syusonn,項目名稱:awesome-python3-webapp,代碼行數:27,代碼來源:handlers.py

示例2: api_register_user

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def api_register_user(*,email,name,passwd):
	if not name or not name.strip():
		raise APIValueError('name')
	if not email or not _RE_EMAIL.match(email):
		raise APIValueError('email')
	if not passwd or not _RE_SHA1.match(passwd):
		raise APIValueError('passwd')
	users = await User.findAll('email=?',[email])
	if len(users) > 0:
		raise APIError('register:failed','email','Email is already in use')
	uid = next_id()
	sha1_passwd = '%s:%s' % (uid,passwd)
	encrypt_passwd = hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest()
	image = 'https://1.gravatar.com/avatar/%s?s=200&r=pg&d=mm'
	user = User(id=uid,name=name.strip(),email=email,passwd=encrypt_passwd,image=image % hashlib.md5(email.encode('utf-8')).hexdigest())
	await user.save()
	# make session cookie
	r = web.Response()
	r.set_cookie(COOKIE_NAME,user2cookie(user,86400),max_age=86400,httponly=True)
	user.passwd = '******'
	r.content_type = 'application/json'
	r.body = json.dumps(user,ensure_ascii=False).encode('utf-8')
	return r 
開發者ID:syusonn,項目名稱:awesome-python3-webapp,代碼行數:25,代碼來源:handlers.py

示例3: api_create_blog

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def api_create_blog(request,*,name,summary,content):
	check_admin(request)
	if not name or not name.strip():
		raise APIValueError('name','name cannot be empty')
	if not  summary or not summary.strip():
		raise APIValueError('summary','summary cannot be empty')
	if not content or not content.strip():
		raise APIValueError('content','content cannot be empty')
	user = request.__user__
	blog = Blog(
		user_id = user.id,
		user_name= user.name,
		user_image = user.image,
		name = name.strip(),
		summary = summary.strip(),
		content = content.strip()
	)
	await blog.save()
	return blog 
開發者ID:syusonn,項目名稱:awesome-python3-webapp,代碼行數:21,代碼來源:handlers.py

示例4: api_register_user

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def api_register_user(*, email, name, password):
    if not name or not name.strip():
        raise APIValueError('name')
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email')
    if not password or not _RE_SHA1.match(password):
        raise APIValueError('password')

    users = yield from User.find_all('email=?', [email])
    if len(users) > 0:
        raise APIError('Register failed', 'email', 'Email is already in use.')

    uid = next_id()
    sha1_password = '{}:{}'.format(uid, password)
    logging.info('register password:{}, sha1_password:{}'.format(password, sha1_password))
    user = User(id=uid, name= name.strip(), email= email, password = hashlib.sha1(sha1_password.encode('utf-8')).hexdigest(), image='http://www.gravatar.com/avatar/{}?d=mm&s=120'.format(hashlib.md5(email.encode('utf-8')).hexdigest()))
    yield from user.save()

    r = web.Response()
    r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    user.password = '*' * 8
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r 
開發者ID:tianzhenyun,項目名稱:python-awesome-web,代碼行數:26,代碼來源:handlers.py

示例5: authenticate

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def authenticate(*, email, password):
    if not email:
        raise APIValueError('email', 'Invalid Email')
    if not password:
        raise APIValueError('password', 'Invalid Password')
    users = yield from User.find_all('email=?', [email])
    if len(users) == 0:
        raise APIValueError('email', 'Email not exist')

    user = users[0]

    #check password
    sha1_password = '{}:{}'.format(user.id, password)
    logging.info('login password:{}, sha1_password:{}'.format(password, sha1_password))
    if user.password != hashlib.sha1(sha1_password.encode('utf-8')).hexdigest():
        raise APIValueError('password', 'Invalid Password.')
    # authenticate ok, set cookie
    r = web.Response()
    r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    user.password = '*' * 8
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r 
開發者ID:tianzhenyun,項目名稱:python-awesome-web,代碼行數:25,代碼來源:handlers.py

示例6: register_uauser

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def register_uauser():
    i = ctx.request.input(name='', email='', password='')
    name = i.name.strip()
    email = i.email.strip().lower()
    password = i.password

    if not name:
        raise APIValueError('name')
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email')
    if not password or not _RE_MD5.match(password):
        raise APIValueError('password')
    user = User.find_first('where email=?', email)
    if user:
        raise APIError('register:failed', 'email', 'Email is already in use.')
    user = User(name=name, email=email, password=password,
                image='http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email).hexdigest())
    user.insert()

    cookie = make_signed_cookie(user.id, user.password, None)
    ctx.response.set_cookie(_COOKIE_NAME, cookie)
    return user 
開發者ID:tzshlyt,項目名稱:python-webapp-blog,代碼行數:24,代碼來源:urls.py

示例7: api_create_blog

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def api_create_blog():
    check_admin()
    i = ctx.request.input(name='', summary='', content='')
    name = i.name.strip()
    summary = i.summary.strip()
    content = i.content.strip()
    if not name:
        raise APIValueError('name', 'name cannot be empty.')
    if not summary:
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content:
        raise APIValueError('content', 'content cannot be empty.')
    user = ctx.request.user
    blog = Blog(user_id=user.id, user_name=user.name,
                name=name, summary=summary, content=content)
    blog.insert()
    return blog 
開發者ID:tzshlyt,項目名稱:python-webapp-blog,代碼行數:19,代碼來源:urls.py

示例8: api_update_blog

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def api_update_blog(blog_id):
    check_admin()
    i = ctx.request.input(name='', summary='', content='')
    name = i.name.strip()
    summary = i.summary.strip()
    content = i.content.strip()
    if not name:
        raise APIValueError('name', 'name cannot be empty.')
    if not summary:
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content:
        raise APIValueError('content', 'content cannot be empty.')
    blog = Blog.get(blog_id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    blog.name = name
    blog.summary = summary
    blog.content = content
    blog.update()
    return blog 
開發者ID:tzshlyt,項目名稱:python-webapp-blog,代碼行數:22,代碼來源:urls.py

示例9: api_create_blog

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def api_create_blog(request, *, name, summary, content):
    check_admin(request) # ??????
    # ??????????
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    # ??????
    blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip())
    yield from blog.save()  # ?????????
    return blog  # ??????


# day12??
# API:???? 
開發者ID:ReedSun,項目名稱:Preeminent,代碼行數:19,代碼來源:handlers.py

示例10: api_create_comment

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def api_create_comment(id, request, *, content):
    user = request.__user__
    # ????
    if user is None:
        raise APIPermissionError('Please signin first.')
    # ??????????
    if not content or not content.strip():
        raise APIValueError('content')
    # ????????
    blog = yield from Blog.find(id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    # ??????
    comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip())
    yield from comment.save()  # ?????????
    return comment  # ????

# day14??
# API????? 
開發者ID:ReedSun,項目名稱:Preeminent,代碼行數:21,代碼來源:handlers.py

示例11: api_update_blog

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def api_update_blog(id, request, *, name, summary, content):
    check_admin(request)  # ??????
    blog = yield from Blog.find(id)  # ?????????????
    # ????????
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    blog.name = name.strip()
    blog.summary = summary.strip()
    blog.content = content.strip()
    yield from blog.update()  # ????
    return blog  # ??????

# day14??
# API:???? 
開發者ID:ReedSun,項目名稱:Preeminent,代碼行數:20,代碼來源:handlers.py

示例12: authenticate

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def authenticate(*, email, passwd):
    if not email:
        raise APIValueError('email', 'Invalid email.')
    if not passwd:
        raise APIValueError('passwd', 'Invalid password.')
    users = yield from User.findAll('email=?', [email])
    if len(users) == 0:
        raise APIValueError('email', 'Email not exist.')
    user = users[0]
    # check passwd:
    sha1 = hashlib.sha1()
    sha1.update(user.id.encode('utf-8'))
    sha1.update(b':')
    sha1.update(passwd.encode('utf-8'))
    if user.passwd != sha1.hexdigest():
        raise APIValueError('passwd', 'Invalid password.')
    # authenticate ok, set cookie:
    r = web.Response()
    r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    user.passwd = '******'
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r 
開發者ID:xsingHu,項目名稱:xs-python-architecture,代碼行數:25,代碼來源:handlers.py

示例13: api_register_user

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def api_register_user(*, email, name, passwd):
    if not name or not name.strip():
        raise APIValueError('name')
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email')
    if not passwd or not _RE_SHA1.match(passwd):
        raise APIValueError('passwd')
    users = yield from User.findAll('email=?', [email])
    if len(users) > 0:
        raise APIError('register:failed', 'email', 'Email is already in use.')
    uid = next_id()
    sha1_passwd = '%s:%s' % (uid, passwd)
    user = User(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(), image='http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest())
    yield from user.save()
    # make session cookie:
    r = web.Response()
    r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    user.passwd = '******'
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r 
開發者ID:xsingHu,項目名稱:xs-python-architecture,代碼行數:23,代碼來源:handlers.py

示例14: authenticate

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def authenticate(*, email, passwd):
	if not email:
		raise APIValueError('email', 'Invalid email.')
	if not passwd:
		raise APIValueError('passwd', 'Invalid password')
	users = await User.findAll('email=?', [email])
	if len(users) == 0:
		raise APIValueError('email', 'Email not exist.')
	user = users[0]
	# check passwd:
	sha1 = hashlib.sha1()
	sha1.update(user.id.encode('utf-8'))
	sha1.update(b':')
	sha1.update(passwd.encode('utf-8'))
	if user.passwd != sha1.hexdigest():
		raise APIValueError('passwd', 'Invalid password.')
	# authenticate ok, set cookie:
	r = web.Response()
	r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
	user.passwd = '******'
	r.content_type = 'application/json'
	r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
	return r 
開發者ID:TsangTen,項目名稱:awesome-webapp,代碼行數:25,代碼來源:handlers.py

示例15: api_create_blog

# 需要導入模塊: import apis [as 別名]
# 或者: from apis import APIValueError [as 別名]
def api_create_blog(request, *, name, summary, content):
	check_admin(request)
	if not name or not name.strip():
		raise APIValueError('name', 'name cannot be empty.')
	if not summary or not summary.strip():
		raise APIValueError('summary', 'summary cannot be empty.')
	if not content or not content.strip():
		raise APIValueError('content', 'content cannot be empty.')
	blog = Blog(
			user_id=request.__user__.id, 
			user_name=request.__user__.name, 
			user_image=request.__user__.image,
			name=name.strip(),
			summary=summary.strip(),
			content=content.strip()
		)
	await blog.save()
	return blog 
開發者ID:TsangTen,項目名稱:awesome-webapp,代碼行數:20,代碼來源:handlers.py


注:本文中的apis.APIValueError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。