本文整理匯總了Python中tornado.util.ObjectDict.type方法的典型用法代碼示例。如果您正苦於以下問題:Python ObjectDict.type方法的具體用法?Python ObjectDict.type怎麽用?Python ObjectDict.type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tornado.util.ObjectDict
的用法示例。
在下文中一共展示了ObjectDict.type方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _form_upload_post
# 需要導入模塊: from tornado.util import ObjectDict [as 別名]
# 或者: from tornado.util.ObjectDict import type [as 別名]
def _form_upload_post(self, send_status):
"""Process the request and create new Lattice resource.
:param send_status: callback method to signal completion
"""
data = self.application.data
ctx = yield self._create_upload_context()
content_type = self.handler.request.headers["Content-Type"]
if not content_type.startswith("multipart/form-data;"):
send_status(415)
return
ctx.lattice.particle_type = self.handler.get_argument("particle_type", "")
if len(ctx.lattice.particle_type) == 0:
ctx.errors.particle_type = "Particle Type is required"
else:
for p in ctx.particle_types:
if p["type"] == ctx.lattice.particle_type:
particle_type = ObjectDict(p)
break
else:
ctx.errors.particle_type = "Particle Type '{}' is invalid" \
.format(ctx.lattice.particle_type)
ctx.lattice.name = self.handler.get_argument("name", "")
if len(ctx.lattice.name) == 0:
ctx.errors.name = "Name is required"
ctx.lattice.branch = self.handler.get_argument("branch", "")
if len(ctx.lattice.branch) == 0:
ctx.errors.branch = "Branch is required"
if self.handler.get_argument("autoversion", "off") == "on":
ctx.lattice_autoversion = True
else:
ctx.lattice_autoversion = False
ctx.lattice.version = self.handler.get_argument("version", "")
if not ctx.lattice_autoversion:
if len(ctx.lattice.version) == 0:
ctx.errors.version = "Version is required"
else:
try:
ctx.lattice.version = int(ctx.lattice.version)
except ValueError:
ctx.lattice.version = self._INITIAL_VERSION
ctx.errors.version = "Version must be an integer"
if ctx.lattice.version <= 0:
ctx.errors.version = "Version must be greater than zero"
ctx.lattice.description = self.handler.get_argument("description", "")
ctx.lattice.status_type = self.handler.get_argument("status_type", "")
ctx.lattice.created_by = self.handler.current_user
ctx.lattice.created_date = datetime.now()
ctx.lattice._id = ObjectId()
request_files = self.handler.request.files
if "lattice_file" not in request_files:
ctx.errors.lattice_file = "Lattice File is required"
elif len(request_files["lattice_file"]) == 0:
ctx.errors.lattice_file = "Lattice File is required"
if ctx.errors:
send_status(400, ctx)
return
# check for another lattice with name, branch and version
if ctx.lattice_autoversion:
lattice = yield data.find_lattice_by_name(ctx.lattice.name,
ctx.lattice.branch)
else:
lattice = yield data.find_lattice_by_name(ctx.lattice.name,
ctx.lattice.branch, ctx.lattice.version)
if ctx.lattice_autoversion:
if lattice:
ctx.lattice.version = lattice.version + 1
else:
ctx.lattice.version = self._INITIAL_VERSION
else:
if lattice:
ctx.errors.version = "Version already exists"
if ctx.errors:
send_status(400, ctx)
return
lattice_file = request_files["lattice_file"][0]
try:
lattice = read_lattice(StringIO(lattice_file.body))
except Exception as e:
LOGGER.warning("Error reading lattice: %s", e)
#.........這裏部分代碼省略.........