Explorar el Código

Make the flask app a python package

Joe Ceresini hace 7 años
padre
commit
4614a24c28
Se han modificado 2 ficheros con 61 adiciones y 0 borrados
  1. 50 0
      python/pytestapp/pytestapp/__init__.py
  2. 11 0
      python/pytestapp/setup.py

+ 50 - 0
python/pytestapp/pytestapp/__init__.py

@@ -0,0 +1,50 @@
+from flask import Flask,request
+import json
+
+app = Flask(__name__)
+
[email protected]("/contains_all_chars_a", methods=['POST'])
+def api_contains_all_chars_a():
+	response={'error': None}
+
+	try:
+		data = request.data
+		response['result'] = contains_all_chars(data)
+	except Exception,e:
+		response['error'] = "Error: %s" % e.message
+		response['result'] = None
+
+	return json.dumps(response)
+
+
[email protected]("/contains_all_chars_b", methods=['POST'])
+def api_contains_all_chars_b():
+	response={'error': None}
+
+	try:
+		data = request.data
+		response['result'] = contains_all_chars_iter(data)
+	except Exception,e:
+		response['error'] = "Error: %s" % e.message
+		response['result'] = None
+
+	return json.dumps(response)
+
+
+# Python sets have an issubset function
+def contains_all_chars(input):
+	wanted_chars=set("abcdefghijklmnopqrstuvwxyz")
+
+	return wanted_chars.issubset(input)
+
+# The above is actually faster, but doesn't show any skills whatsoever
+# This doesn't either...
+def contains_all_chars_iter(input):
+	wanted_chars=set("abcdefghijklmnopqrstuvwxyz")
+
+	for c in input:
+		if c in wanted_chars:
+			wanted_chars.remove(c)
+			if len(wanted_chars) == 0:
+				return True
+	return False

+ 11 - 0
python/pytestapp/setup.py

@@ -0,0 +1,11 @@
+from setuptools import setup
+
+setup(
+    name='pytestapp',
+    packages=['pytestapp'],
+    version='0.0.1',
+    description='Test API using Flask',
+    author='Joe Ceresini',
+    author_email='[email protected]',
+    install_requires=['flask'],
+)