test.py :  » Web-Server » SkunkWEB » skunkweb-3.4.4 » SkunkWeb » Services » remote » 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 Server » SkunkWEB 
SkunkWEB » skunkweb 3.4.4 » SkunkWeb » Services » remote » test.py
#  
#  Copyright (C) 2001 Jacob Smullyan <smulloni@smullyan.org>
#  
#      You may distribute under the terms of either the GNU General
#      Public License or the SkunkWeb License, as specified in the
#      README file.
#   
#! /usr/local/bin/python

# a test script for testing remote components

import socket
import cPickle
import SocketScience
import exceptions
import traceback
import AE.Component
import sys
import types

class RemoteException:
    def __init__(self, exceptionClass, exceptionInstance, args):
        if exceptionClass not in self.__class__.__bases__:
            self.__class__.__bases__+=(exceptionClass,)
        exceptionClass.__init__(self, args)
        self.remoteInstance=exceptionInstance
                
def runInteractive():
    import sys
    try:
        argLen=len(sys.argv)
        if argLen>2:
            host=sys.argv[1]
        else:
            host=raw_input("host: ")
        if argLen>=3:
            port=int(sys.argv[2])
        else:
            port=int(raw_input("port: "))
        if argLen>=4:
            path=sys.argv[3]
        else:
            path=raw_input("path: ")
        path=path.strip()
        if argLen>=5:
            argDict=eval(sys.argv[4])
        else:
            argDict=eval(raw_input("argDict: "))
        print "path is \"%s\"" % path
        if path.endswith('.comp') or path.endswith('.pycomp'):
            compType=AE.Component.DT_REGULAR
        else:
            compType=AE.Component.DT_DATA
        if compType==AE.Component.DT_REGULAR:
            print "regular component"
        else:
            print "data component"
        result=run(host, port, path, argDict, compType=compType)
        print
        print '*'*72
        print 
        print "returned from %s:%d%s: %s" % (host, port, path, str(result))
        print 
        print '*'*72
        print
    except:
        print
        print '!'*72
        print 
        traceback.print_exc()
        print
        print '!' * 72
        print

def run(host,
        port,
        path,
        argDict,
        cache=0,
        compType = AE.Component.DT_DATA,
        srcModTime = None):
    
    unPickled=None
    args = cPickle.dumps((path, argDict, cache, compType, srcModTime))
    msg="%10d%s" %(len(args), args) 
    sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((host, port))
    data=sock.recv(1)
    if data=='\0':
        SocketScience.send_it_all(sock, msg)
        length=int(SocketScience.read_this_many(sock, 10))
        data=SocketScience.read_this_many(sock, length)
        unPickled=cPickle.loads(data)
        if (type(unPickled)==types.TupleType
            and len(unPickled)==3
            and type(unPickled[0])==types.ClassType
            and issubclass(unPickled[0], exceptions.Exception)
            and isinstance(unPickled[1], exceptions.Exception)):       
            raise RemoteException(unPickled[0], unPickled[1], unPickled[2])
    return unPickled

if __name__=='__main__':
    runInteractive()
    print "Done"


www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.