[tuxdroid-svn] r5961 - software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/execut
Status: Beta
Brought to you by:
ks156
From: jerome <c2m...@c2...> - 2009-12-09 11:46:59
|
Author: jerome Date: 2009-12-09 12:46:45 +0100 (Wed, 09 Dec 2009) New Revision: 5961 Modified: software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py Log: * Added server utils functions. Modified: software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py =================================================================== --- software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py 2009-12-09 11:45:45 UTC (rev 5960) +++ software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py 2009-12-09 11:46:45 UTC (rev 5961) @@ -338,4 +338,54 @@ toPrettyString = staticmethod(toPrettyString) - phoneNumberToTTS = staticmethod(phoneNumberToTTS) + phoneNumberToTTS = staticmethod(phoneNumberToTTS) + + + +class TuxDroidServerUtils(object): + ''' + Provide Tux Droid server utils functions. + ''' + + def getServerPort(self): + ''' + Return the current server port. + ''' + if os.name == "nt": + return 270 + else: + if os.geteuid() == 0: + return 270 + else: + return 54321 + + + def sendRequest(self, host, port, request): + ''' + Send a request to tuxhttpserver. + ''' + import socket + import httplib + + old_timeout = socket.getdefaulttimeout() + socket.setdefaulttimeout(2.) + hp = "%s:%d" % (host, port) + h = httplib.HTTP(hp) + try: + h.connect() + except: + socket.setdefaulttimeout(old_timeout) + return 1 + h.putrequest("GET", request) + h.endheaders() + errcode, errmsg, headers = h.getreply() + if errcode != 200: + socket.setdefaulttimeout(old_timeout) + return 1 + else: + socket.setdefaulttimeout(old_timeout) + return 0 + + + getServerPort = staticmethod(getServerPort) + sendRequest = staticmethod(sendRequest) |