本文整理汇总了Python中web.ok函数的典型用法代码示例。如果您正苦于以下问题:Python ok函数的具体用法?Python ok怎么用?Python ok使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ok函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PUT
def PUT(self):
ctx = readPlistFromString(web.data())
status = ctx.get("Status")
UDID = ctx.get("UDID")
g_cmd_queue = MDMDB("./mdm.db")
g_cmd_queue.open()
cmdinfo = g_cmd_queue.getCommandInfo(UDID=UDID)
if not cmdinfo:
g_cmd_queue.close()
return web.ok()
cmd_status = int(cmdinfo["Status"])
print cmd_status
if cmd_status == 0:
plist = getCommandPlist(cmdinfo["Command"], args=cmdinfo["Arguments"])
g_cmd_queue.setCommandStatus(UDID=UDID, status=1)
g_cmd_queue.close()
return plist
elif cmd_status == 1:
print ctx
# TODO:Add code here to check device status.
g_cmd_queue.removeCommand(UDID=UDID)
g_cmd_queue.close()
return web.ok()
else:
return web.unauthorized
示例2: _setReturnCode
def _setReturnCode(self, code):
"""Set the return code
:param: code
:type code: integer or string
returns success: [True|False]
"""
success = False
if code in (200, "200", "ok"):
web.ok()
success = True
elif code in (201, "201", "created"):
web.created()
success = True
elif code in (400, "400", "badrequest"):
web.badrequest()
elif code in (401, "401", "unauthorized"):
web.unauthorized()
elif code in (404, "404", "notfound"):
web.notfound()
elif code in (409, "409", "conflict"):
web.conflict()
elif code in (500, "500", "internalerror"):
web.internalerror()
if success:
logging.debug("[LayMan][_setReturnCode] Code: '%s'" % code)
else:
logging.error("[LayMan][_setReturnCode] Code: '%s'" % code)
return success
示例3: DELETE
def DELETE(self, resource):
"""
Try to delete the supplied resource
"""
if isTestMode(): # check env. if in test mode, import dbconn mock
import Shared
dbConn = Shared.dbMock
else:
dbConn = DataAccessLayer.DataAccessLayer()
if not isValidKey(resource):
logging.info("Item-DELETE: invalid resource key (%s)", resource)
web.badrequest()
return
try:
dbConn.delete(resource)
except AttributeError:
logging.warning("Item-DELETE: unable to delete resource (%s)", resource)
web.notfound()
return
except Exception as e:
logging.error("Item-DELETE: Unexpected exception when deleting: %s", e)
web.badrequest()
return
web.ok()
return
示例4: PUT
def PUT(self, slug):
entry = db.entries.find_one({'slug': slug})
if not entry:
raise web.notfound()
else:
updated_entry = objectify.fromstring(web.data())
db.entries.update({'_id': entry['_id'],},{
'slug': slug,
'title': updated_entry.title.text,
'updated': datetime.datetime.now(),
'author': updated_entry.author.name.text,
'content': updated_entry.content.text,
})
body = xmlify(db.entries.find_one({'slug': slug}), web.home)
web.header(
'Content-Type',
'application/atom+xml;type=entry;charset="utf-8"'
)
web.header(
'Content-Length',
len(body)
)
raise web.ok(body)
示例5: success
def success(self, i):
if i.redirect_url:
url = self.build_url(i.redirect_url, status="ok")
return web.seeother(url)
else:
d = json.dumps({ "status" : "ok" })
return web.ok(d, {"Content-type": "application/json"})
示例6: GET
def GET(self):
type = web.input().get('type', '')
if type == 'atom':
out = render.atomfeed(web.ctx.home)
else:
out = render.rssfeed(web.ctx.home)
raise web.ok(out)
示例7: __call__
def __call__(self, handler):
if web.ctx.path.startswith("/api/") or web.ctx.path.endswith(".json"):
self.add_cors_headers()
if web.ctx.method == "OPTIONS":
raise web.ok("")
else:
return handler()
示例8: POST
def POST(self):
x = web.input()
if x.has_key("id"):
if not s.exists(x['id']):
item = s.get_item(x['id'])
raise web.created()
else:
raise web.ok()
示例9: GET
def GET(self, slug):
media = Media.get(slug)
if media:
web.ok(
{
"Expires": "Thu, 15 Apr 3010 20:00:00 GMT",
"Cache-Control": "max-age=3600,public",
"Content-Type": str(media.mtype),
}
)
a = web.input(a="")["a"]
if a and a.lower() == "download":
media.download += 1
media.put()
return media.bits
else:
return web.notfound()
示例10: POST
def POST(self):
global last_snapshot
i = web.input()
if last_snapshot is not None:
tweeter.tweet_photo(str(datetime.now()), last_snapshot['blob'])
# tweeter.tweet('test')
print i
return web.ok()
示例11: GET
def GET(self, method=None):
# Default is to turn something on
if method == 'on' or not method:
self._d.turn_on()
return web.ok()
if method == 'off':
self._d.turn_off()
return web.ok()
# TODO: Test this so it doesn't clash with the web.input() call in
# __init__()
if method == 'parameter':
query = web.input(
parameter = None,
value = ''
)
if not query.parameter:
raise web.badrequest()
try:
value = self._d.get_parameter(parameter)
except:
raise web.internalerror()
if not value:
raise web.notfound()
return json.dumps(dict(
parameter = parameter,
value = value
))
if method == 'model':
model = self._d.model
if not model:
raise web.notfound()
if method == 'learn':
try:
self._d.learn()
except(td.TDDeviceError), e:
web.internalerror()
return json.dumps(dict(error=str(e)))
return web.ok()
示例12: GET
def GET(self):
if last_snapshot is None:
return web.ok()
else:
web.header('Content-Type', 'image/png') # file type
# web.header('Content-disposition',
# 'attachment; filename=graphotti.png')
return last_snapshot['blob']
示例13: DELETE
def DELETE(self, uuid=None):
if uuid is None:
raise web.badrequest()
# @throws web.notfound
self.handler.delete(uuid)
raise web.ok()
示例14: POST
def POST(self):
variables = web.input()
if (variables.get('username') == configuration.web_user()) & (variables.get('password') == configuration.web_pwd()):
user_session.login = 1
print 'Logged in.'
return web.ok()
else:
user_session.login = 0
return web.unauthorized()
示例15: GET
def GET(self):
web.header('Access-Control-Allow-Origin', '*')
params = web.input()
if 'user' not in params or 'pass' not in params:
return web.badrequest()
if random.choice([True, False]):
return web.ok()
else:
return web.unauthorized()