class Item:
"""
@description:
- This is an example of a model class that has parameters in its constructor
- and the fields in the swagger spec are derived from the parameters to __init__.
+ This is an example of a model class that has parameters in its
+ constructor and the fields in the swagger spec are derived from
+ the parameters to __init__.
@notes:
- In this case we would have property1, name as required parameters and property3 as optional parameter.
+ In this case we would have property1, name as required parameters
+ and property3 as optional parameter.
@property property3: Item description
@ptype property3: L{PropertySubclass}
@ptype property4: C{list} of L{PropertySubclass}
"""
- def __init__(self, property1, property2=None, property3=None, property4=None):
+ def __init__(self,
+ property1,
+ property2=None,
+ property3=None,
+ property4=None):
self.property1 = property1
self.property2 = property2
self.property3 = property3
pass
def prepare(self):
- if not (self.request.method == "GET" or self.request.method == "DELETE"):
- if self.request.headers.get("Content-Type") is not None:
- if self.request.headers["Content-Type"].startswith(DEFAULT_REPRESENTATION):
+ if self.request.method != "GET" and self.request.method != "DELETE":
+ self.json_args = None
+ content_type = self.request.headers.get("Content-Type")
+ if content_type is not None:
+ if content_type.startswith(DEFAULT_REPRESENTATION):
try:
self.json_args = json.loads(self.request.body)
except (ValueError, KeyError, TypeError) as error:
raise HTTPError(HTTP_BAD_REQUEST,
"Bad Json format [{}]".
format(error))
- else:
- self.json_args = None
def finish_request(self, json_object):
self.write(json.dumps(json_object))
@notes:
get a item,
- This will be added to the Implementation Notes.It lets you put very long text in your api.
+ This will be added to the Implementation Notes.
+ It lets you put very long text in your api.
"""
self.finish_request(items[arg].format_http())
@description: delete a item
@notes:
delete a item in items
-
- This will be added to the Implementation Notes.It lets you put very long text in your api.
"""
del items[arg]
self.finish_request("success")
"""
@return 200: case is created
"""
- print("ProjectHandler.post: %s -- %s -- %s" % (arg1, arg2, self.request.full_url()))
- fs = open("/home/swagger/tornado-rest-swagger/%s/%s" % (arg1, arg2), "wb")
+ fs = open("/home/%s/%s" % (arg1, arg2), "wb")
fs.write(self.request.body)
self.write("success")
res.append(value.format_http())
elif value.property2 == property2:
res.append(value.format_http())
- elif items.has_key(property1):
+ elif property1 in items:
if items.get(property1).property2 == property2:
res.append(items.get(property1).format_http())