-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstring_generator.py
60 lines (51 loc) · 1.54 KB
/
string_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
"""
CherryPy String Generator Service.
This is the example random string generator service, slightly
modified for swagger to not use session support.
"""
import random
import string
import cherrypy
STRING_TO_KEEP = ''
@cherrypy.expose
class StringGeneratorWebService(object):
"""String Generator Class."""
@staticmethod
@cherrypy.tools.json_out()
# pylint: disable=invalid-name
def GET():
"""CherryPy Get Method."""
return {'mystring': STRING_TO_KEEP}
@staticmethod
@cherrypy.tools.json_out()
# pylint: disable=invalid-name
def POST(length=8):
"""CherryPy Post Method."""
global STRING_TO_KEEP
some_string = ''.join(random.sample(string.hexdigits, int(length)))
STRING_TO_KEEP = some_string
return {'mystring': some_string}
@staticmethod
@cherrypy.tools.json_out()
# pylint: disable=invalid-name
def PUT(another_string):
"""CherryPy Put Method."""
global STRING_TO_KEEP
STRING_TO_KEEP = another_string
return {'mystring': another_string}
@staticmethod
@cherrypy.tools.json_out()
# pylint: disable=invalid-name
def DELETE():
"""CherryPy Delete Method."""
global STRING_TO_KEEP
STRING_TO_KEEP = ''
cherrypy.response.status = 204
@staticmethod
@cherrypy.tools.json_out()
# pylint: disable=unused-argument
# pylint: disable=invalid-name
def OPTIONS(another_string=None):
"""CherryPy Options Method."""
cherrypy.response.status = 204