LRWPAdapter.py :  » Web-Frameworks » Webware » Webware-1.0.2 » WebKit » Adapters » 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 » Web Frameworks » Webware 
Webware » Webware 1.0.2 » WebKit » Adapters » LRWPAdapter.py
#!/usr/bin/env python

#-----------------------------------------------------------------------------
# Name:        LRWPAdapter.py
#
# Purpose:     LRWP Adapter for the WebKit AppServer and the Xitami Web Server.
#              Adapted from the CGI Adapter for WebKit.
#
# Author:      Jim Madsen
#
# Created:     09/27/02
#-----------------------------------------------------------------------------

# Set Program Parameters

webwareDir = None

LRWPappName = 'testing'

LRWPhost = 'localhost'

LRWPport = 81

#-----------------------------------------------------------------------------

import os, sys
from lrwplib import LRWP
from Adapter import Adapter


if not webwareDir:
  webwareDir = os.path.dirname(os.path.dirname(os.getcwd()))
sys.path.insert(1, webwareDir)
webKitDir = os.path.join(webwareDir, 'WebKit')


class LRWPAdapter(Adapter):

  def __init__(self, webkitdir):
    Adapter.__init__(self, webkitdir)
    if sys.platform == 'win32':
      import msvcrt
      msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
      msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
    # Get Host and Port information for WebKit AppServer
    (self.host, self.port) = open(os.path.join(self._webKitDir, 'adapter.address')).read().split(':')
    self.port = int(self.port)

  def lrwpConnect(self, LRWPappName, LRWPhost, LRWPport):
    try:
      # Make connection to Xitami
      self.lrwp = LRWP(LRWPappName, LRWPhost, LRWPport)
      self.lrwp.connect()
      print ('\r\n Connected to Xitami -- Listening for ' + LRWPappName + '\r\n')
      self.LRWPappName = LRWPappName
    except Exception:
      sys.exit('Could not make proper connection to Xitami')

  def handler(self):
    while 1:
      try:
        # Accept requests
        self.request = self.lrwp.acceptRequest()
        # Read input from request object
        self.myInput = ''
        if self.request.env.has_key('CONTENT_LENGTH'):
          length = int(self.request.env['CONTENT_LENGTH'])
          self.myInput = self.myInput + self.request.inp.read(length)
        # Fix environment variables due to the way Xitami reports them under LRWP
        self.request.env['SCRIPT_NAME'] = ('/' + self.LRWPappName)
        self.request.env['REQUEST_URI'] = ('/' + self.LRWPappName + self.request.env['PATH_INFO'])
        # Transact with the app server
        self.response = self.transactWithAppServer(self.request.env, self.myInput, self.host, self.port)
        # Log page handled to the console
        print self.request.env['REQUEST_URI']
        # Close request to handle another
        self.request.finish()
      # Capture Ctrl-C... Shutdown will occur on next request handled
      except KeyboardInterrupt:
        print '\r\n Closing connection to Xitami \r\n'
        self.lrwp.close()
        sys.exit(' Clean Exit')
      except:
        print 'Error handling requests'

  # Output through request object
  def processResponse(self, data):
    self.request.out.write(data)


def main():
  # Startup LRWP to WebKit interface
  lrwpInterface = LRWPAdapter(webKitDir)
  lrwpInterface.lrwpConnect(LRWPappName, LRWPhost, LRWPport)
  lrwpInterface.handler()


if __name__ == '__main__':
  main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.