Jason R. Coombs avatar Jason R. Coombs committed f55cddb

Adding a relay server

Comments (0)

Files changed (1)

jaraco/home/relay.py

+import json
+
+import cherrypy
+
+from . import thermostat
+
+"""
+A relay for publically-exposed interfaces.
+"""
+
+class Site:
+	@cherrypy.expose
+	def temp(self):
+		cherrypy.response.headers['Content-Type'] = 'application/json'
+		return json.dumps(thermostat.request('/tstat/temp'))
+
+	@classmethod
+	def setup_application(cls, root):
+		config = {
+			'global': {
+				'tools.encode.on': True, 'tools.encode.encoding': 'utf-8',
+				'tools.decode.on': True,
+				'tools.trailing_slash.on': True,
+			},
+		}
+
+		return cherrypy.tree.mount(cls(), root, config)
+
+	@classmethod
+	def factory(cls):
+		"The entry point for when the ISAPIDLL is triggered"
+		try:
+			import isapi_wsgi
+			return isapi_wsgi.ISAPISimpleHandler(cls.setup_application('/home'))
+		except:
+			traceback.print_exc()
+
+__ExtensionFactory__ = Site.factory
+
+def handle_isapi():
+	"Install or remove the extension to the virtual directory"
+	import isapi.install
+	params = isapi.install.ISAPIParameters()
+	# Setup the virtual directories - this is a list of directories our
+	# extension uses - in this case only 1.
+	# Each extension has a "script map" - this is the mapping of ISAPI
+	# extensions.
+	sm = [
+		isapi.install.ScriptMapParams(Extension="*", Flags=0)
+	]
+	vd = isapi.install.VirtualDirParameters(
+		Server="Default Web Site",
+		Name="/home",
+		Description = "Media Index",
+		ScriptMaps = sm,
+		ScriptMapUpdate = "end",
+		)
+	params.VirtualDirs = [vd]
+	isapi.install.HandleCommandLine(params)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.