6 Commits 6deaa35aab ... c9581fd03f

Autor SHA1 Mensaje Fecha
  Joe Ceresini c9581fd03f Adding a sample systemd unit file, not the recommended way to run this though hace 7 años
  Joe Ceresini 3accd98e27 This was supposed to be a rename hace 7 años
  Joe Ceresini 4614a24c28 Make the flask app a python package hace 7 años
  Joe Ceresini 973c478088 Add actual logic for python example hace 7 años
  Joe Ceresini bf66cabe29 Reorganizing hace 7 años
  Joe Ceresini e174dfe1b7 Don't need that extra newline creeping into the body hace 7 años

+ 1 - 1
contains_all_chars.sh

@@ -14,7 +14,7 @@ http_response() {
 	for h in "${headers[@]}"; do
 		echo $h
 	done
-	echo -n -e "\n\n"
+	echo -n -e "\n"
 }
 
 send_response() {

+ 0 - 10
python/api.py

@@ -1,10 +0,0 @@
-from flask import Flask,request
-import json
-
-app = Flask(__name__)
-
[email protected]("/contains_all_chars", methods=['POST'])
-def contains_all_chars():
-	# Just testing, essentially an echo server at this point
-	return json.dumps(request.get_json())
-

+ 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'],
+)

+ 13 - 0
python/systemd_pytestapp.service

@@ -0,0 +1,13 @@
+[Unit]
+Description=pytestapp
+After=network.target
+
+[Service]
+User=[runuser]
+Group=[rungroup]
+ExecStart=/bin/bash -c "source [path/to/virtualenv]/bin/activate ; export FLASK_APP=pytestapp ; flask run --host=0.0.0.0"
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
+