def output(jack_class, output_type): if output_type is 'test': return jack_class if output_type != 'xml': raise ValueError( 'Incorrect output type received. Available types: xml') if output_type is 'xml': print('Main -- outputting xml\n\n') return XMLConverter.convert_class(jack_class)
def do_GET(self): try: dprint(__name__, 2, "http request header:\n{0}", self.headers) dprint(__name__, 2, "http request path:\n{0}", self.path) if self.headers['Host'] == Settings.getHostToIntercept() and \ self.headers['User-Agent'].startswith("iTunes-AppleTV"): # recieve simple logging messages from the ATV if self.path.endswith("&atvlogger"): msg = self.path.replace("%20", " ") msg = msg.replace("<", "<") msg = msg.replace(">", ">") msg = msg.replace("&fs;", "/") msg = msg[1:len(msg) - 10] dprint('ATVLogger', 0, msg) return # serve "application.js" to aTV # disregard the path - it is different for different iOS versions if self.path.endswith("application.js"): dprint(__name__, 1, "serving application.js") f = open(sys.path[0] + sep + "assets" + sep + "application.js") self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve all other .js files to aTV if self.path.endswith(".js"): dprint( __name__, 1, "serving " + sys.path[0] + sep + "assets" + self.path.replace('/', sep)) f = open(sys.path[0] + sep + "assets" + self.path.replace('/', sep)) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve all .xml files to aTV including "plexconnect.xml" or "plexconnect_oldmenu.xml" if self.path.endswith(".xml"): dprint( __name__, 1, "serving " + sys.path[0] + sep + "assets" + self.path.replace('/', sep)) f = open(sys.path[0] + sep + "assets" + self.path.replace('/', sep)) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.jpg" - thumbnails for old-style mainpage if self.path.endswith(".jpg"): dprint(__name__, 1, "serving *.jpg: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/jpeg') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.png" - only png's support transparent colors if self.path.endswith(".png"): dprint(__name__, 1, "serving *.png: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/png') self.end_headers() self.wfile.write(f.read()) f.close() return # path could be a search string if self.path.find('search') > -1: dprint( __name__, 1, "Search Query=" + "/search?type=2&query=" + self.path[8:] + "&PlexConnect=Search") XML = XMLConverter.XML_PMS2aTV( self.client_address, "/search?type=4&query=" + self.path[8:] + "&PlexConnect=Search") self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(XML) return # get everything else from XMLConverter - formerly limited to trailing "/" and &PlexConnect Cmds if True: dprint(__name__, 1, "serving .xml: " + self.path) XML = XMLConverter.XML_PMS2aTV(self.client_address, self.path) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(XML) return """ # unexpected request self.send_error(403,"Access denied: %s" % self.path) """ else: self.send_error( 403, "Not Serving Client %s" % self.client_address[0]) except IOError: self.send_error(404, "File Not Found: %s" % self.path)
#Protocol = "HTTP/1.0" # todo: IP, port try: server = HTTPServer(('', 80), MyHandler) server.timeout = 1 sa = server.socket.getsockname() except Exception, e: dprint(__name__, 0, "Failed to connect to port 80 (http): {0}", e) sys.exit(1) dprint(__name__, 0, "***") dprint(__name__, 0, "WebServer: Serving HTTP on {0} port {1}.", sa[0], sa[1]) dprint(__name__, 0, "***") XMLConverter.setParams(param) cfg = ATVSettings.CATVSettings() XMLConverter.setATVSettings(cfg) try: while True: # check command try: # check command cmd = cmdQueue.get_nowait() if cmd == 'shutdown': break except Queue.Empty: pass
def do_GET(self): global g_param try: dprint(__name__, 2, "http request header:\n{0}", self.headers) dprint(__name__, 2, "http request path:\n{0}", self.path) # check for PMS address PMSaddress = '' pms_end = self.path.find(')') if self.path.startswith('/PMS(') and pms_end > -1: PMSaddress = urllib.unquote_plus(self.path[5:pms_end]) self.path = self.path[pms_end + 1:] # break up path, separate PlexConnect options options = {} while True: cmd_start = self.path.find('&PlexConnect') cmd_end = self.path.find('&', cmd_start + 1) if cmd_start == -1: break if cmd_end > -1: cmd = self.path[cmd_start + 1:cmd_end] self.path = self.path[:cmd_start] + self.path[cmd_end:] else: cmd = self.path[cmd_start + 1:] self.path = self.path[:cmd_start] parts = cmd.split('=', 1) if len(parts) == 1: options[parts[0]] = '' else: options[parts[0]] = urllib.unquote(parts[1]) # break up path, separate additional arguments # clean path needed for filetype decoding... has to be merged back when forwarded. parts = self.path.split('?', 1) if len(parts) == 1: args = '' else: self.path = parts[0] args = '?' + parts[1] # get aTV language setting options['aTVLanguage'] = Localize.pickLanguage( self.headers.get('Accept-Language', 'en')) # add client address - to be used in case UDID is unknown options['aTVAddress'] = self.client_address[0] # get aTV hard-/software parameters options['aTVFirmwareVersion'] = self.headers.get( 'X-Apple-TV-Version', '5.1') options['aTVScreenResolution'] = self.headers.get( 'X-Apple-TV-Resolution', '720') dprint(__name__, 2, "pms address:\n{0}", PMSaddress) dprint(__name__, 2, "cleaned path:\n{0}", self.path) dprint(__name__, 2, "PlexConnect options:\n{0}", options) dprint(__name__, 2, "additional arguments:\n{0}", args) if 'User-Agent' in self.headers and \ 'AppleTV' in self.headers['User-Agent']: # recieve simple logging messages from the ATV if 'PlexConnectATVLogLevel' in options: dprint('ATVLogger', int(options['PlexConnectATVLogLevel']), options['PlexConnectLog']) self.send_response(200) self.send_header('Content-type', 'text/plain') self.end_headers() return # serve "*.cer" - Serve up certificate file to atv if self.path.endswith(".cer"): dprint(__name__, 1, "serving *.cer: " + self.path) if g_param['CSettings'].getSetting('certfile').startswith( '.'): # relative to current path cfg_certfile = sys.path[0] + sep + g_param[ 'CSettings'].getSetting('certfile') else: # absolute path cfg_certfile = g_param['CSettings'].getSetting( 'certfile') cfg_certfile = path.splitext(cfg_certfile)[0] + '.cer' try: f = open(cfg_certfile, "rb") except: dprint(__name__, 0, "Failed to access certificate: {0}", cfg_certfile) return self.send_response(200) self.send_header('Content-type', 'text/xml') self.end_headers() self.wfile.write(f.read()) f.close() return # serve .js files to aTV # application, main: ignore path, send /assets/js/application.js # otherwise: path should be '/js', send /assets/js/*.js dirname = path.dirname(self.path) basename = path.basename(self.path) if basename in ("application.js", "main.js", "javascript-packed.js") or \ basename.endswith(".js") and dirname == '/js': if basename in ("main.js", "javascript-packed.js"): basename = "application.js" dprint(__name__, 1, "serving /js/{0}", basename) JS = JSConverter(basename, options) self.send_response(200) self.send_header('Content-type', 'text/javascript') self.end_headers() self.wfile.write(JS) return # serve "*.jpg" - thumbnails for old-style mainpage if self.path.endswith(".jpg"): dprint(__name__, 1, "serving *.jpg: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/jpeg') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.png" - only png's support transparent colors if self.path.endswith(".png"): dprint(__name__, 1, "serving *.png: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/png') self.end_headers() self.wfile.write(f.read()) f.close() return # get everything else from XMLConverter - formerly limited to trailing "/" and &PlexConnect Cmds if True: dprint(__name__, 1, "serving .xml: " + self.path) XML = XMLConverter.XML_PMS2aTV(PMSaddress, self.path + args, options) self.send_response(200) self.send_header('Content-type', 'text/xml') self.end_headers() self.wfile.write(XML) return else: """ # unexpected request self.send_error(403,"Access denied: %s" % self.path) """ self.send_error( 403, "Not Serving Client %s" % self.client_address[0]) except IOError: self.send_error(404, "File Not Found: %s" % self.path)
def do_GET(self): try: dprint(__name__, 2, "http request header:\n{0}", self.headers) dprint(__name__, 2, "http request path:\n{0}", self.path) # brake up path, separate PlexConnect options options = {} while True: cmd_start = self.path.find('&PlexConnect') cmd_end = self.path.find('&', cmd_start + 1) if cmd_start == -1: break if cmd_end > -1: cmd = self.path[cmd_start + 1:cmd_end] self.path = self.path[:cmd_start] + self.path[cmd_end:] else: cmd = self.path[cmd_start + 1:] self.path = self.path[:cmd_start] parts = cmd.split('=', 1) if len(parts) == 1: options[parts[0]] = '' else: options[parts[0]] = urllib.unquote(parts[1]) # get aTV language setting options['aTVLanguages'] = self.headers.get('Accept-Language', 'en') dprint(__name__, 2, "cleaned path:\n{0}", self.path) dprint(__name__, 2, "request options:\n{0}", options) if 'User-Agent' in self.headers and \ 'AppleTV' in self.headers['User-Agent']: # recieve simple logging messages from the ATV if 'PlexConnectLog' in options: dprint('ATVLogger', 0, options['PlexConnectLog']) self.send_response(200) self.send_header('Content-type', 'text/plain') self.end_headers() return # serve "application.js" to aTV # disregard the path - it is different for different iOS versions if self.path.endswith("application.js"): dprint(__name__, 1, "serving application.js") f = open(sys.path[0] + sep + "assets" + sep + "js" + sep + "application.js") self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve all other .js files to aTV if self.path.endswith(".js"): dprint( __name__, 1, "serving " + sys.path[0] + sep + "assets" + self.path.replace('/', sep)) f = open(sys.path[0] + sep + "assets" + self.path.replace('/', sep)) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.jpg" - thumbnails for old-style mainpage if self.path.endswith(".jpg"): dprint(__name__, 1, "serving *.jpg: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/jpeg') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.png" - only png's support transparent colors if self.path.endswith(".png"): dprint(__name__, 1, "serving *.png: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/png') self.end_headers() self.wfile.write(f.read()) f.close() return # get everything else from XMLConverter - formerly limited to trailing "/" and &PlexConnect Cmds if True: dprint(__name__, 1, "serving .xml: " + self.path) XML = XMLConverter.XML_PMS2aTV(self.client_address, self.path, options) self.send_response(200) self.send_header('Content-type', 'text/xml') self.end_headers() self.wfile.write(XML) return """ # unexpected request self.send_error(403,"Access denied: %s" % self.path) """ else: self.send_error( 403, "Not Serving Client %s" % self.client_address[0]) except IOError: self.send_error(404, "File Not Found: %s" % self.path)
cfg_IP_WebServer, cfg_Port_SSL, e) server.shutdown() sys.exit(1) socketinfo = server.socket.getsockname() socketinfo_ssl = server_ssl.socket.getsockname() dprint(__name__, 0, "***") dprint(__name__, 0, "WebServer: Serving HTTP on {0} port {1}.", socketinfo[0], socketinfo[1]) dprint(__name__, 0, "WebServer: Serving HTTPS on {0} port {1}.", socketinfo_ssl[0], socketinfo_ssl[1]) dprint(__name__, 0, "***") setParams(param) XMLConverter.setParams(param) cfg = ATVSettings.CATVSettings() XMLConverter.setATVSettings(cfg) XMLConverter.discoverPMS() try: while True: # check command if cmdPipe.poll(): cmd = cmdPipe.recv() if cmd == 'shutdown': break # do something important time.sleep(1)
MyHandler) server.timeout = 1 except Exception, e: dprint(__name__, 0, "Failed to connect to HTTP on {0} port {1}: {2}", cfg_IP_WebServer, cfg_Port_WebServer, e) sys.exit(1) socketinfo = server.socket.getsockname() dprint(__name__, 0, "***") dprint(__name__, 0, "WebServer: Serving HTTP on {0} port {1}.", socketinfo[0], socketinfo[1]) dprint(__name__, 0, "***") setParams(param) XMLConverter.setParams(param) cfg = NMTSettings.CNMTSettings() XMLConverter.setNMTSettings(cfg) try: while True: # check command if cmdPipe.poll(): cmd = cmdPipe.recv() if cmd == 'shutdown': break # do your work (with timeout) server.handle_request() except KeyboardInterrupt:
(cfg_IP_WebServer, int(cfg_Port_WebServer)), MyHandler) server.timeout = 1 except Exception, e: dprint(__name__, 0, "Failed to connect to HTTP on {0} port {1}: {2}", cfg_IP_WebServer, cfg_Port_WebServer, e) sys.exit(1) socketinfo = server.socket.getsockname() dprint(__name__, 0, "***") dprint(__name__, 0, "WebServer: Serving HTTP on {0} port {1}.", socketinfo[0], socketinfo[1]) dprint(__name__, 0, "***") setParams(param) XMLConverter.setParams(param) XMLConverter.setATVSettings(param['CATVSettings']) try: while True: # check command if cmdPipe.poll(): cmd = cmdPipe.recv() if cmd == 'shutdown': break # do your work (with timeout) server.handle_request() except KeyboardInterrupt: signal.signal(signal.SIGINT, signal.SIG_IGN) # we heard you!
def do_GET(self): try: dprint(__name__, 2, "http request header:\n{0}", self.headers) dprint(__name__, 2, "http request path:\n{0}", self.path) # break up path, separate options if '?' in self.path: (self.path, options) = self.path.split('?') elif '&' in self.path: (self.path, options) = self.path.split('&', 1) else: options = '' if len(options) > 0: options = dict(urlparse.parse_qsl(options)) for key in options: options[key] = unquote_plus(options[key]) else: options = {} dprint(__name__, 2, "cleaned path:\n{0}", self.path) dprint(__name__, 2, "request args:\n{0}", options) if self.headers['Host'] == g_param['HostToIntercept'] and \ self.headers['User-Agent'].startswith("iTunes-AppleTV"): # recieve simple logging messages from the ATV if 'PlexLog' in options: # self.path.endswith("&atvlogger"): msg = options['PlexLog'] msg = msg.replace("%20", " ") msg = msg.replace("<", "<") msg = msg.replace(">", ">") msg = msg.replace("&fs;", "/") msg = msg.replace("&qo;", '"') dprint('ATVLogger', 0, msg) self.send_response(200) self.send_header('Content-type', 'text/plain') self.end_headers() return # serve "application.js" to aTV # disregard the path - it is different for different iOS versions if self.path.endswith("application.js"): dprint(__name__, 1, "serving application.js") f = open(sys.path[0] + sep + "assets" + sep + "application.js") self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve all other .js files to aTV if self.path.endswith(".js"): dprint( __name__, 1, "serving " + sys.path[0] + sep + "assets" + self.path.replace('/', sep)) f = open(sys.path[0] + sep + "assets" + self.path.replace('/', sep)) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve all .xml files to aTV including "plexconnect.xml" or "plexconnect_oldmenu.xml" if self.path.endswith(".xml"): dprint( __name__, 1, "serving " + sys.path[0] + sep + "assets" + self.path.replace('/', sep)) f = open(sys.path[0] + sep + "assets" + self.path.replace('/', sep)) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.jpg" - thumbnails for old-style mainpage if self.path.endswith(".jpg"): dprint(__name__, 1, "serving *.jpg: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/jpeg') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.png" - only png's support transparent colors if self.path.endswith(".png"): dprint(__name__, 1, "serving *.png: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/png') self.end_headers() self.wfile.write(f.read()) f.close() return # path could be a search string if self.path.find('search') > -1: dprint( __name__, 1, "Search Query=" + "/search?type=2&query=" + self.path[8:] + "&PlexConnect=Search") options = {'PlexConnect':'Search', \ 'type':'4', \ 'query':self.path[8:] } XML = XMLConverter.XML_PMS2aTV(self.client_address, "/search", options) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(XML) return # get everything else from XMLConverter - formerly limited to trailing "/" and &PlexConnect Cmds if True: dprint(__name__, 1, "serving .xml: " + self.path) XML = XMLConverter.XML_PMS2aTV(self.client_address, self.path, options) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(XML) return """ # unexpected request self.send_error(403,"Access denied: %s" % self.path) """ else: self.send_error( 403, "Not Serving Client %s" % self.client_address[0]) except IOError: self.send_error(404, "File Not Found: %s" % self.path)
def do_GET(self): global g_param try: dprint(__name__, 2, "http request header:\n{0}", self.headers) dprint(__name__, 2, "http request path:\n{0}", self.path) # check for PMS address PMSaddress = '' pms_end = self.path.find(')') if self.path.startswith('/PMS(') and pms_end > -1: PMSaddress = urllib.unquote_plus(self.path[5:pms_end]) self.path = self.path[pms_end + 1:] # break up path, separate PlexConnect options options = {} while True: cmd_start = self.path.find('&PlexConnect') cmd_end = self.path.find('&', cmd_start + 1) if cmd_start == -1: break if cmd_end > -1: cmd = self.path[cmd_start + 1:cmd_end] self.path = self.path[:cmd_start] + self.path[cmd_end:] else: cmd = self.path[cmd_start + 1:] self.path = self.path[:cmd_start] parts = cmd.split('=', 1) if len(parts) == 1: options[parts[0]] = '' else: options[parts[0]] = urllib.unquote(parts[1]) # break up path, separate additional arguments # clean path needed for filetype decoding... has to be merged back when forwarded. parts = self.path.split('?', 1) if len(parts) == 1: args = '' else: self.path = parts[0] args = '?' + parts[1] # get aTV language setting options['aTVLanguage'] = Localize.pickLanguage( self.headers.get('Accept-Language', 'en')) # add client address - to be used in case UDID is unknown options['aTVAddress'] = self.client_address[0] # get aTV hard-/software parameters options['aTVFirmwareVersion'] = self.headers.get( 'X-Apple-TV-Version', '5.1') options['aTVScreenResolution'] = self.headers.get( 'X-Apple-TV-Resolution', '720') dprint(__name__, 2, "pms address:\n{0}", PMSaddress) dprint(__name__, 2, "cleaned path:\n{0}", self.path) dprint(__name__, 2, "PlexConnect options:\n{0}", options) dprint(__name__, 2, "additional arguments:\n{0}", args) if 'User-Agent' in self.headers and \ 'AppleTV' in self.headers['User-Agent']: # serve the plex icon if self.headers[ 'Host'] == 'a1.phobos.apple.com' and self.path.endswith( ".png"): # possible icon basename = path.basename(self.path) iconname, ext = basename.split('.') dprint(__name__, 2, "serving icon {0}", iconname) name, rez = iconname.split('@') dprint(__name__, 2, "icon name: {0} at {1}", name, rez) hosticons = { 'www.icloud.com': 'Theater', 'atv.hbogo.com': 'HBOGo', 'atv.qello.com': 'QelloV2', 'appletv.app.hulu.com': 'huluplus', 'appletv.vevo.com': 'VevoV1', 'apps.sho.com': 'Smithsonian_V2', 'watchdisneyjunior.go.com': 'DisneyJR', 'watchdisneychannel.go.com': 'DisneyChannel_V2', 'watchdisneyxd.go.com': 'DisneyXD_V2', 'ssl.weather.com': 'weatherchannel', 'secure.marketwatch.com': 'wsj', 'trailers.apple.com': 'movie-trailers', 'secure.showtimeanytime.com': 'com.showtime.appletv', 'vimeo.com': 'vimeo', 'd6mhwe3a8uvr5.cloudfront.net': 'skynews', 'video.pbs.org': 'PBS_V2', 'neulion-a.akamaihd.net': 'MLS_V3', 'itunesconnect.apple.com': 'iTunesConnect', 'abcnews.go.com': 'ABC_News', 'atvapp.willow.tv': 'Willow', 'player.aetndigital.com': 'Lifetime_V2', 'www.crunchyroll.com': 'CrunchyRollV3', 'watchabc.go.com': 'ABC', 'appletv.redbull.tv': 'RedBullTV', 'neulion-a.akamaihd.net': 'NHL', 'appletv.cnbc.com': 'CNBC', 'appletv.now.nfl.com': 'NFL_Now', 'secure.net.wwe.com': 'WWE', 'api-global.netflix.com': 'netflix', 'player.aetndigital.com': 'AE_V2', 's.yimg.com': 'YahooScreen', 'kids.pbs.org': 'PBS_Kids', 'kortv.com': 'KORTV_V2', 'appletv.crackle.com': 'Crackle', 'd1d0j1u9ayd8uc.cloudfront.net': 'ACC_V2', 's.cdn.turner.com': 'nba', 'player.aetndigital.com': 'History_V2', 'aptve.foxneodigital.com': 'FOX_Now', 'appletv.flickr.com': 'Flickr', 'a248.e.akamai.net': 'ESPNv3', 'mobapi.bloomberg.com': 'Bloomberg_V2', 's.aolcdn.com': 'AOL_On' } if name == hosticons.get(g_param['HostToIntercept']): dprint(__name__, 2, "getting plex icon") f = open( sys.path[0] + sep + "assets" + sep + "thumbnails" + sep + "icon@" + rez + ".png", "rb") self.send_response(200) self.send_header('Content-type', 'image/png') self.end_headers() self.wfile.write(f.read()) f.close() return else: dprint(__name__, 2, "getting app icon") self.send_response(200) self.send_header('Content-type', 'image/png') self.end_headers() self.wfile.write( urllib.urlopen('http://' + self.headers['Host'] + self.path).read()) return elif self.headers['Host'] == 'a1.phobos.apple.com': # something other than an icon was requested self.send_response(200) self.send_header('Content-type', self.headers['Content-type']) self.end_headers() self.wfile.write( urllib.urlopen('http://' + self.headers['Host'] + self.path).read()) return # recieve simple logging messages from the ATV if 'PlexConnectATVLogLevel' in options: dprint('ATVLogger', int(options['PlexConnectATVLogLevel']), options['PlexConnectLog']) self.send_response(200) self.send_header('Content-type', 'text/plain') self.end_headers() return # serve "*.cer" - Serve up certificate file to atv if self.path.endswith(".cer"): dprint(__name__, 1, "serving *.cer: " + self.path) if g_param['CSettings'].getSetting('certfile').startswith( '.'): # relative to current path cfg_certfile = sys.path[0] + sep + g_param[ 'CSettings'].getSetting('certfile') else: # absolute path cfg_certfile = g_param['CSettings'].getSetting( 'certfile') cfg_certfile = path.normpath(cfg_certfile) cfg_certfile = path.splitext(cfg_certfile)[0] + '.cer' try: f = open(cfg_certfile, "rb") except: dprint(__name__, 0, "Failed to access certificate: {0}", cfg_certfile) return self.send_response(200) self.send_header('Content-type', 'text/xml') self.end_headers() self.wfile.write(f.read()) f.close() return # serve .js files to aTV # application, main: ignore path, send /assets/js/application.js # otherwise: path should be '/js', send /assets/js/*.js dirname = path.dirname(self.path) basename = path.basename(self.path) if basename in ("application.js", "main.js", "javascript-packed.js") or \ basename.endswith(".js") and dirname == '/js': if basename in ("main.js", "javascript-packed.js"): basename = "application.js" dprint(__name__, 1, "serving /js/{0}", basename) JS = JSConverter(basename, options) self.send_response(200) self.send_header('Content-type', 'text/javascript') self.end_headers() self.wfile.write(JS) return # serve "*.jpg" - thumbnails for old-style mainpage if self.path.endswith(".jpg"): dprint(__name__, 1, "serving *.jpg: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/jpeg') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.png" - only png's support transparent colors if self.path.endswith(".png"): dprint(__name__, 1, "serving *.png: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/png') self.end_headers() self.wfile.write(f.read()) f.close() return # get everything else from XMLConverter - formerly limited to trailing "/" and &PlexConnect Cmds if True: dprint(__name__, 1, "serving .xml: " + self.path) XML = XMLConverter.XML_PMS2aTV(PMSaddress, self.path + args, options) self.send_response(200) self.send_header('Content-type', 'text/xml') self.end_headers() self.wfile.write(XML) return """ # unexpected request self.send_error(403,"Access denied: %s" % self.path) """ else: self.send_error( 403, "Not Serving Client %s" % self.client_address[0]) except IOError: self.send_error(404, "File Not Found: %s" % self.path)
import os import shutil import sys import XMLConverter import yaml test_case_dir = os.path.abspath(sys.argv[1]) case_dirs = [os.path.join(test_case_dir, x) for x in os.listdir(test_case_dir)] for case_dir in case_dirs: if not (os.path.isdir(case_dir)): continue print(case_dir) for fname in os.listdir(case_dir): if fname != 'desc.xml': continue print(fname) fpath = os.path.join(case_dir, fname) d = XMLConverter.xml_to_dict(fpath) t = yaml.dump(d, default_flow_style=False) fname_new = fname.replace('.xml', '.yml') fpath_new = os.path.join(case_dir, fname_new) with open(fpath_new, 'w') as wf: wf.write(t) os.remove(fpath)
def do_GET(self): try: if self.client_address[0] == Settings.getIP_aTV(): # serve "application.js" to aTV # disregard the path - it is different for different iOS versions if self.path.endswith("application.js"): dprint(__name__, 1, "serving application.js") f = open(curdir + sep + "assets" + sep + "application.js") self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "plexconnect.xml" to aTV if self.path.endswith("plexconnect.xml"): fVer = self.headers['X-Apple-TV-Version'].split( ".", 2) # firmware version number firmVersion = fVer[0] + "." + fVer[1] dprint(__name__, 1, "aTV firmware: " + firmVersion) if eval(firmVersion) >= 5.1: dprint(__name__, 1, "serving plexconnect.xml") f = open(curdir + sep + "assets" + sep + "plexconnect.xml" ) # Version 5.1 or above use top menu bar else: dprint(__name__, 1, "serving plexconnect_oldmenu.xml") f = open( curdir + sep + "assets" + sep + "plexconnect_oldmenu.xml" ) # Versions 5.0.2 or lower don't use top menu bar self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.jpg" - thumbnails for old-style mainpage if self.path.endswith(".jpg"): dprint(__name__, 1, "serving *.jpg: " + self.path) f = open(curdir + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/jpeg') self.end_headers() self.wfile.write(f.read()) f.close() return # serve Plex directory structure - make sure to keep the trailing "/" if self.path.endswith("/"): dprint(__name__, 1, "serving .xml: " + self.path) XML = XMLConverter.XML_PMS2aTV(self.client_address, self.path) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(XML) return # serve Plex media if self.path.endswith("&PlexConnect=Play"): dprint(__name__, 1, "serving media: " + self.path) XML = XMLConverter.XML_PlayVideo( self.client_address, self.path[:-len('&PlexConnect=Play')]) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(XML) return # unexpected request self.send_error(403, "Access denied: %s" % self.path) else: self.send_error( 403, "Not Serving Client %s" % self.client_address[0]) except IOError: self.send_error(404, "File Not Found: %s" % self.path)
def do_GET(self): try: dprint(__name__, 2, "http request header:\n{0}", self.headers) dprint(__name__, 2, "http request path:\n{0}", self.path) # brake up path, separate PlexConnect options options = {} while True: cmd_start = self.path.find('&PlexConnect') cmd_end = self.path.find('&', cmd_start+1) if cmd_start==-1: break if cmd_end>-1: cmd = self.path[cmd_start+1:cmd_end] self.path = self.path[:cmd_start] + self.path[cmd_end:] else: cmd = self.path[cmd_start+1:] self.path = self.path[:cmd_start] parts = cmd.split('=', 1) if len(parts)==1: options[parts[0]] = '' else: options[parts[0]] = parts[1] dprint(__name__, 2, "cleaned path:\n{0}", self.path) dprint(__name__, 2, "request options:\n{0}", options) if self.headers['Host'] == g_param['HostToIntercept'] and \ self.headers['User-Agent'].startswith("iTunes-AppleTV"): # recieve simple logging messages from the ATV if self.path.endswith("&atvlogger"): msg = self.path.replace("%20", " ") msg = msg.replace("<", "<") msg = msg.replace(">", ">") msg = msg.replace("&fs;", "/") msg = msg.replace("&qo;", '"') msg = msg[1:len(msg)-10] dprint('ATVLogger', 0, msg) self.send_response(200) self.send_header('Content-type', 'text/plain') self.end_headers() return # serve "application.js" to aTV # disregard the path - it is different for different iOS versions if self.path.endswith("application.js"): dprint(__name__, 1, "serving application.js") f = open(sys.path[0] + sep + "assets" + sep + "application.js") self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve all other .js files to aTV if self.path.endswith(".js"): dprint(__name__, 1, "serving " + sys.path[0] + sep + "assets" + self.path.replace('/',sep)) f = open(sys.path[0] + sep + "assets" + self.path.replace('/',sep)) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve all .xml files to aTV including "plexconnect.xml" or "plexconnect_oldmenu.xml" if self.path.endswith(".xml"): dprint(__name__,1,"serving "+ sys.path[0] + sep + "assets" + self.path.replace('/',sep)) f = open(sys.path[0] + sep + "assets" + self.path.replace('/',sep)) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.jpg" - thumbnails for old-style mainpage if self.path.endswith(".jpg"): dprint(__name__, 1, "serving *.jpg: "+self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/jpeg') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.png" - only png's support transparent colors if self.path.endswith(".png"): dprint(__name__, 1, "serving *.png: "+self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/png') self.end_headers() self.wfile.write(f.read()) f.close() return # get everything else from XMLConverter - formerly limited to trailing "/" and &PlexConnect Cmds if True: dprint(__name__, 1, "serving .xml: "+self.path) XML = XMLConverter.XML_PMS2aTV(self.client_address, self.path, options) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(XML) return """ # unexpected request self.send_error(403,"Access denied: %s" % self.path) """ else: self.send_error(403,"Not Serving Client %s" % self.client_address[0]) except IOError: self.send_error(404,"File Not Found: %s" % self.path)
def do_GET(self): global g_param try: dprint(__name__, 2, "http request header:\n{0}", self.headers) dprint(__name__, 2, "http request path:\n{0}", self.path) # check for PMS address PMSaddress = '' # Build PMS address from settings. PSR PMSaddress = 'http://' + g_param['CSettings'].getSetting( 'ip_pms') + ':' + g_param['CSettings'].getSetting('port_pms') pms_end = self.path.find(')') if self.path.startswith('/PMS(') and pms_end > -1: PMSaddress = urllib.unquote_plus(self.path[5:pms_end]) self.path = self.path[pms_end + 1:] # break up path, separate PlexNMT options options = {} while True: cmd_start = self.path.find('&PlexNMT') if cmd_start == -1: cmd_start = self.path.find('?PlexNMT') cmd_end = self.path.find('&', cmd_start + 1) if cmd_start == -1: break if cmd_end > -1: cmd = self.path[cmd_start + 1:cmd_end] self.path = self.path[:cmd_start] + self.path[cmd_end:] else: cmd = self.path[cmd_start + 1:] self.path = self.path[:cmd_start] parts = cmd.split('=', 1) if len(parts) == 1: options[parts[0]] = '' else: options[parts[0]] = urllib.unquote(parts[1]) # break up path, separate additional arguments # clean path needed for filetype decoding... has to be merged back when forwarded. parts = self.path.split('?', 1) if len(parts) == 1: args = '' else: self.path = parts[0] args = '?' + parts[1] # get NMT language setting options['NMTLanguage'] = Localize.pickLanguage( self.headers.get('Accept-Language', 'en')) # add client address - to be used in case UDID is unknown options['NMTAddress'] = self.client_address[0] # get aTV hard-/software parameters # options['aTVFirmwareVersion'] = self.headers.get('X-Apple-TV-Version', '5.1') # options['aTVScreenResolution'] = self.headers.get('X-Apple-TV-Resolution', '720') dprint(__name__, 2, "pms address:\n{0}", PMSaddress) dprint(__name__, 2, "cleaned path:\n{0}", self.path) dprint(__name__, 2, "PlexNMT options:\n{0}", options) dprint(__name__, 2, "additional arguments:\n{0}", args) if 'User-Agent' in self.headers: # and \ # 'AppleTV' in self.headers['User-Agent']: # recieve simple logging messages from the NMT if 'PlexConnectNMTLogLevel' in options: dprint('NMTLogger', int(options['PlexConnectNMTLogLevel']), options['PlexNMTLog']) self.send_response(200) self.send_header('Content-type', 'text/plain') self.end_headers() return # serve .js files # application, main: ignore path, send /assets/js/application.js # otherwise: path should be '/js', send /assets/js/*.js dirname = path.dirname(self.path) basename = path.basename(self.path) if basename in ("application.js", "main.js", "javascript-packed.js") or \ basename.endswith(".js") and dirname == '/js': if basename in ("main.js", "javascript-packed.js"): basename = "application.js" dprint(__name__, 1, "serving /js/{0}", basename) JS = JSConverter(basename, options) self.send_response(200) self.send_header('Content-type', 'text/javascript') self.end_headers() self.wfile.write(JS) return # serve "*.ico" - favicon.ico if self.path.endswith(".ico"): dprint(__name__, 1, "serving *.ico: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/ico') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.jpg" - thumbnails for old-style mainpage if self.path.endswith(".jpg"): dprint(__name__, 1, "serving *.jpg: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/jpeg') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.png" - only png's support transparent colors if self.path.endswith(".png"): dprint(__name__, 1, "serving *.png: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'image/png') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.js" - js are all from PlexNMT if self.path.endswith(".js"): dprint(__name__, 1, "serving *.png: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'text/javascript') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.xsl" if self.path.endswith(".xsl"): dprint(__name__, 1, "serving *.xsl: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'text/xml') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "*.html" if self.path.endswith(".html"): dprint(__name__, 1, "serving *.html: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return # serve "/index.html" if self.path == "/": dprint(__name__, 1, "serving /index.html") try: f = open( sys.path[0] + sep + "assets" + sep + "index.html", "rb") self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return except: dprint(__name__, 1, "No index.html; using root of pms") # get everything else from XMLConverter if True: if self.path == "/pms": self.path = "/" dprint(__name__, 1, "serving .xml: " + self.path) HTML = XMLConverter.XML_PMS2NMT(PMSaddress, self.path + args, options) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(HTML) return """ # unexpected request self.send_error(403,"Access denied: %s" % self.path) """ else: self.send_error( 403, "Not Serving Client %s" % self.client_address[0]) except IOError: self.send_error(404, "File Not Found: %s" % self.path)
thread_ssl = Thread(target=server_ssl.serve_forever).start() except Exception, e: dprint(__name__, 0, "Failed to connect to HTTPS on {0} port {1}: {2}", cfg_IP_WebServer, cfg_Port_SSL, e) server.shutdown() sys.exit(1) socketinfo = server.socket.getsockname() socketinfo_ssl = server_ssl.socket.getsockname() dprint(__name__, 0, "***") dprint(__name__, 0, "WebServer: Serving HTTP on {0} port {1}.", socketinfo[0], socketinfo[1]) dprint(__name__, 0, "WebServer: Serving HTTPS on {0} port {1}.", socketinfo_ssl[0], socketinfo_ssl[1]) dprint(__name__, 0, "***") setParams(param) XMLConverter.setParams(param) cfg = ATVSettings.CATVSettings() XMLConverter.setATVSettings(cfg) XMLConverter.discoverPMS() try: while True: # check command if cmdPipe.poll(): cmd = cmdPipe.recv() if cmd=='shutdown': break # do something important time.sleep(1)
def Run(cmdQueue, param): #Protocol = "HTTP/1.0" # todo: IP, port try: server = HTTPServer(('',80), MyHandler) server.timeout = 1 sa = server.socket.getsockname() except Exception, e: dprint(__name__, 0, "Failed to connect to port 80 (http): {0}", e) sys.exit(1) dprint(__name__, 0, "***") dprint(__name__, 0, "WebServer: Serving HTTP on {0} port {1}.", sa[0], sa[1]) dprint(__name__, 0, "***") XMLConverter.setParams(param) try: while True: # check command try: # check command cmd = cmdQueue.get_nowait() if cmd=='shutdown': break except Queue.Empty: pass # do your work (with timeout) server.handle_request()
cfg_Port_WebServer = param['CSettings'].getSetting('port_webserver') try: server = ThreadedHTTPServer((cfg_IP_WebServer,int(cfg_Port_WebServer)), MyHandler) server.timeout = 1 except Exception, e: dprint(__name__, 0, "Failed to connect to HTTP on {0} port {1}: {2}", cfg_IP_WebServer, cfg_Port_WebServer, e) sys.exit(1) socketinfo = server.socket.getsockname() dprint(__name__, 0, "***") dprint(__name__, 0, "WebServer: Serving HTTP on {0} port {1}.", socketinfo[0], socketinfo[1]) dprint(__name__, 0, "***") setParams(param) XMLConverter.setParams(param) XMLConverter.setATVSettings(param['CATVSettings']) try: while True: # check command if cmdPipe.poll(): cmd = cmdPipe.recv() if cmd=='shutdown': break # do your work (with timeout) server.handle_request() except KeyboardInterrupt: signal.signal(signal.SIGINT, signal.SIG_IGN) # we heard you!
cfg_Port_WebServer = param['CSettings'].getSetting('port_webserver') try: server = HTTPServer((cfg_IP_WebServer,int(cfg_Port_WebServer)), MyHandler) server.timeout = 1 except Exception, e: dprint(__name__, 0, "Failed to connect to HTTP on {0} port {1}: {2}", cfg_IP_WebServer, cfg_Port_WebServer, e) sys.exit(1) socketinfo = server.socket.getsockname() dprint(__name__, 0, "***") dprint(__name__, 0, "WebServer: Serving HTTP on {0} port {1}.", socketinfo[0], socketinfo[1]) dprint(__name__, 0, "***") setParams(param) XMLConverter.setParams(param) cfg = ATVSettings.CATVSettings() XMLConverter.setATVSettings(cfg) try: while True: # check command if cmdPipe.poll(): cmd = cmdPipe.recv() if cmd=='shutdown': break # do your work (with timeout) server.handle_request() except KeyboardInterrupt:
def do_GET(self): global g_param try: dprint(__name__, 2, "http request header:\n{0}", self.headers) dprint(__name__, 2, "http request path:\n{0}", self.path) # check for PMS address PMSaddress = '' pms_end = self.path.find(')') if self.path.startswith('/PMS(') and pms_end > -1: PMSaddress = urllib.unquote_plus(self.path[5:pms_end]) self.path = self.path[pms_end + 1:] # break up path, separate PlexConnect options # clean path needed for filetype decoding parts = re.split( r'[?&]', self.path, 1) # should be '?' only, but we do some things different :-) if len(parts) == 1: self.path = parts[0] options = {} query = '' else: self.path = parts[0] # break up query string options = {} query = '' parts = parts[1].split('&') for part in parts: if part.startswith('PlexConnect'): # get options[] opt = part.split('=', 1) if len(opt) == 1: options[opt[0]] = '' else: options[opt[0]] = urllib.unquote(opt[1]) else: # recreate query string (non-PlexConnect) - has to be merged back when forwarded if query == '': query = '?' + part else: query += '&' + part # get aTV language setting options['aTVLanguage'] = Localize.pickLanguage( self.headers.get('Accept-Language', 'en')) query = query.replace("yyltyy", "<").replace("yygtyy", ">") # add client address - to be used in case UDID is unknown if 'X-Forwarded-For' in self.headers: options['aTVAddress'] = self.headers['X-Forwarded-For'].split( ',', 1)[0] else: options['aTVAddress'] = self.client_address[0] # get aTV hard-/software parameters options['aTVFirmwareVersion'] = self.headers.get( 'X-Apple-TV-Version', '5.1') options['aTVScreenResolution'] = self.headers.get( 'X-Apple-TV-Resolution', '720') dprint(__name__, 2, "pms address:\n{0}", PMSaddress) dprint(__name__, 2, "cleaned path:\n{0}", self.path) dprint(__name__, 2, "PlexConnect options:\n{0}", options) dprint(__name__, 2, "additional arguments:\n{0}", query) if 'User-Agent' in self.headers and \ 'AppleTV' in self.headers['User-Agent']: # recieve simple logging messages from the ATV if 'PlexConnectATVLogLevel' in options: dprint('ATVLogger', int(options['PlexConnectATVLogLevel']), options['PlexConnectLog']) self.send_response(200) self.send_header('Content-type', 'text/plain') self.end_headers() return # serve "*.cer" - Serve up certificate file to atv if self.path.endswith(".cer"): dprint(__name__, 1, "serving *.cer: " + self.path) if g_param['CSettings'].getSetting('certfile').startswith( '.'): # relative to current path cfg_certfile = sys.path[0] + sep + g_param[ 'CSettings'].getSetting('certfile') else: # absolute path cfg_certfile = g_param['CSettings'].getSetting( 'certfile') cfg_certfile = path.normpath(cfg_certfile) cfg_certfile = path.splitext(cfg_certfile)[0] + '.cer' try: f = open(cfg_certfile, "rb") except: dprint(__name__, 0, "Failed to access certificate: {0}", cfg_certfile) return self.sendResponse(f.read(), 'text/xml', False) f.close() return # serve .js files to aTV # application, main: ignore path, send /assets/js/application.js # otherwise: path should be '/js', send /assets/js/*.js dirname = path.dirname(self.path) basename = path.basename(self.path) if basename in ("application.js", "main.js", "javascript-packed.js", "bootstrap.js") or \ basename.endswith(".js") and dirname == '/js': if basename in ("main.js", "javascript-packed.js", "bootstrap.js"): basename = "application.js" dprint(__name__, 1, "serving /js/{0}", basename) JS = JSConverter(basename, options) self.sendResponse(JS, 'text/javascript', True) return # proxy phobos.apple.com to support PlexConnect main icon if "a1.phobos.apple.com" in self.headers['Host']: resource = self.headers['Host'] + self.path icon = g_param['CSettings'].getSetting('icon') if basename.startswith(icon): icon_res = basename[len( icon ):] # cut string from settings, keeps @720.png/@1080.png resource = sys.path[0] + '/assets/icons/icon' + icon_res dprint( __name__, 1, "serving " + self.headers['Host'] + self.path + " with " + resource) r = open(resource, "rb") else: r = urllib.urlopen('http://' + resource) self.sendResponse(r.read(), 'image/png', False) r.close() return # serve "*.jpg" - thumbnails for old-style mainpage if self.path.endswith(".jpg"): dprint(__name__, 1, "serving *.jpg: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.sendResponse(f.read(), 'image/jpeg', False) f.close() return # serve "*.png" - only png's support transparent colors if self.path.endswith(".png"): dprint(__name__, 1, "serving *.png: " + self.path) f = open(sys.path[0] + sep + "assets" + self.path, "rb") self.sendResponse(f.read(), 'image/png', False) f.close() return # serve subtitle file - transcoded to aTV subtitle json if 'PlexConnect' in options and \ options['PlexConnect']=='Subtitle': dprint(__name__, 1, "serving subtitle: " + self.path) XML = Subtitle.getSubtitleJSON(PMSaddress, self.path + query, options) self.sendResponse(XML, 'application/json', True) return # get everything else from XMLConverter - formerly limited to trailing "/" and &PlexConnect Cmds if True: dprint(__name__, 1, "serving .xml: " + self.path) XML = XMLConverter.XML_PMS2aTV(PMSaddress, self.path + query, options) self.sendResponse(XML, 'text/xml', True) return """ # unexpected request self.send_error(403,"Access denied: %s" % self.path) """ else: """ Added Up Page for docker helthcheck self.send_error(403,"Not Serving Client %s" % self.client_address[0]) """ dprint(__name__, 1, "serving *.html: " + self.path) f = open(sys.path[0] + sep + "assets/templates/up.html") self.sendResponse(f.read(), 'text/html', False) f.close() except IOError: dprint(__name__, 0, 'File Not Found:\n{0}', traceback.format_exc()) self.send_error(404, "File Not Found: %s" % self.path) except: dprint(__name__, 0, 'Internal Server Error:\n{0}', traceback.format_exc()) self.send_error(500, "Internal Server Error: %s" % self.path)
cfg_Port_WebServer = param['CSettings'].getSetting('port_webserver') try: server = HTTPServer((cfg_IP_WebServer,int(cfg_Port_WebServer)), MyHandler) server.timeout = 1 except Exception, e: dprint(__name__, 0, "Failed to connect to HTTP on {0} port {1}: {2}", cfg_IP_WebServer, cfg_Port_WebServer, e) sys.exit(1) socketinfo = server.socket.getsockname() dprint(__name__, 0, "***") dprint(__name__, 0, "WebServer: Serving HTTP on {0} port {1}.", socketinfo[0], socketinfo[1]) dprint(__name__, 0, "***") setParams(param) XMLConverter.setParams(param) cfg = NMTSettings.CNMTSettings() XMLConverter.setNMTSettings(cfg) try: while True: # check command if cmdPipe.poll(): cmd = cmdPipe.recv() if cmd=='shutdown': break # do your work (with timeout) server.handle_request() except KeyboardInterrupt: