EntryInfoServer.py :  » RSS » PenguinTV » PenguinTV-4.1.0 » penguintv » ajax » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » RSS » PenguinTV 
PenguinTV » PenguinTV 4.1.0 » penguintv » ajax » EntryInfoServer.py
import os
import logging

import gtk

import utils
import SimpleHTTPServer
import SimpleImageCache

class EntryInfoServer(SimpleHTTPServer.SimpleHTTPRequestHandler):  
  """This class is recreated on every GET call.  So things changed in this
     scope don't stick"""
  
  _image_cache = SimpleImageCache.SimpleImageCache()

  def __init__(self, request, client_address, server):
    self._server = server
    SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self, request, client_address, server)
    
  def do_GET(self):
    p = self.path[1:] #strip leading /
    
    splitted = p.split("/")
    
    key = ""
    command = "update"
    arg = ""
    
    if len(splitted) >= 1:
      key = splitted[0]
    
    if len(splitted) == 0 or key != self.server.get_key():
      self.wfile.write("PenguinTV Unauthorized")
      return
      
    if len(splitted) >= 2:
      command = splitted[1]
    if len(splitted) >= 3:
      arg = splitted[2]
      
    if command == "update":
      if self.server.update_count()==0:
        self.wfile.write("")
      else:
        update = self.server.peek_update()
        self.wfile.write(update)
    elif command == "icon":
      theme = gtk.icon_theme_get_default()
      iconinfo = theme.lookup_icon(arg, 16, gtk.ICON_LOOKUP_NO_SVG)
      if iconinfo is not None:
        image_data = self._image_cache.get_image_from_file(iconinfo.get_filename())
        self.wfile.write(image_data)
      else:
        logging.error("no icon found for: %s" % (arg,))
        self.wfile.write("")
    elif command == "pixmaps":
      image_data = self._image_cache.get_image_from_file(utils.get_image_path(arg))
      self.wfile.write(image_data)
    elif command == "cache":
      #strip out possible ../../../ crap.  I think this is all I need?
      securitize = [s for s in splitted if s not in ("/",".","..")]
      filename = os.path.join(self._server.store_location, *securitize[2:])
      if utils.RUNNING_HILDON:
        #not enough ram to cache it
        f = open(filename, "rb")
        image_data = f.read()
        f.close()
      else:
        image_data = self._image_cache.get_image_from_file(filename)
      self.wfile.write(image_data)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.