Changeset 39

Show
Ignore:
Timestamp:
07/19/07 19:51:20 (1 year ago)
Author:
edsuom
Message:

Giving up on ill-conceived attempt to load arbitrary services

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/twisted-goodies/trunk/MANIFEST.in

    r2 r39  
    1 misc/* 
     1graft misc 
  • projects/twisted-goodies/trunk/misc/etc_simpleserver_server.conf

    r38 r39  
    11# SimpleServer Configuration File 
    22 
     3# User and group 
     4user = simpleserver 
     5group = simpleserver 
     6 
    37# Services provided 
    4 services = HTTP POP3 
     8services = HTTP, POP3 
    59 
    610# Passwords file for authenticated access 
  • projects/twisted-goodies/trunk/postsetup.py

    r12 r39  
    11""" 
    22Post setup operations 
     3 
     4Copyright (C) 2006-2007 by Edwin A. Suominen, http://www.eepatents.com 
     5 
     6This program is free software; you can redistribute it and/or modify it under 
     7the terms of the GNU General Public License as published by the Free Software 
     8Foundation; either version 2 of the License, or (at your option) any later 
     9version. 
     10 
     11This program is distributed in the hope that it will be useful, but WITHOUT ANY 
     12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
     13PARTICULAR PURPOSE.  See the file COPYING for more details. 
     14 
     15You should have received a copy of the GNU General Public License along with 
     16this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 
     17Street, Fifth Floor, Boston, MA 02110-1301, USA 
     18 
    319""" 
    420 
     
    2743     
    2844    def prepareDirectory(self, dirParts): 
    29         for k in xrange(len(dirParts)-1): 
     45        for k in xrange(len(dirParts)): 
    3046            thisDir = os.path.join(*dirParts[:k+1]) 
    3147            if not os.path.exists(thisDir): 
  • projects/twisted-goodies/trunk/setup.py

    r20 r39  
    2525 
    2626### Imports and support 
    27 import ez_setup 
     27import ez_setup, postsetup 
    2828ez_setup.use_setuptools() 
    2929from setuptools import setup, find_packages 
     
    9494### Finally, run the setup 
    9595setup(name=NAME, **kw) 
    96  
     96postsetup.run(NAME, 'simpleserver', 'simpleserver') 
  • projects/twisted-goodies/trunk/twisted_goodies/simpleserver/service.py

    r38 r39  
    11 
    22import pwd, grp, os, os.path, imp 
    3 import configobj 
     3import configobj, pkg_resources 
    44from twisted.internet import ssl, defer 
     5from twisted.cred import checkers 
    56from twisted.application import internet, service 
    67 
     
    6061        package path and return a function named 'factory' within that module. 
    6162        """ 
     63        def getModuleInfo(resourceName): 
     64            path = pkg_resources.resource_filename(__name__, resourceName) 
     65            if os.path.isdir(path): 
     66                pkg = imp.load_module(name, None, '', ('', '', 5)) 
     67                path = os.path.join(path, '__init__.py') 
     68            fd = open(path) 
     69            return fd, '', ('.py', 'U', 1)     
     70         
    6271        name = name.lower() 
    63         myPath = os.path.dirname(__file__) 
    64         fp, pathname, description = imp.find_module(name, myPath) 
    65         try: 
    66             module = imp.load_module(name, fp, pathname, description) 
    67         except: 
    68             return 
    69         return getattr(module, 'factory', None) 
     72        if pkg_resources.resource_exists(__name__, name): 
     73            info = getModuleInfo(name) 
     74        else: 
     75            info = getModuleInfo(name + '.py') 
     76        print info 
     77        module = imp.load_module(name, *info) 
     78        print name, dir(module) 
     79        result = getattr(module, 'factory', None) 
     80        if info[0] is not None: 
     81            info[0].close() 
     82        return result 
    7083     
    7184    def _serviceGenerator(self): 
     
    7992            if not callable(factoryFunction): 
    8093                continue 
     94            serviceConfig = self.config[key] 
     95            print key, serviceConfig 
    8196            factory = factoryFunction(self, serviceConfig) 
    82             serviceConfig = self.config[key] 
    8397            for portName in ('tcp', 'ssl'): 
    8498                if portName not in serviceConfig: 
    8599                    continue 
    86                 port = serviceConfig[portName] 
     100                port = int(serviceConfig[portName]) 
    87101                if portName == 'tcp': 
    88102                    serviceObject = internet.TCPServer(port, factory) 
     
    93107                            self.config['certificate']) 
    94108                    serviceObject = internet.SSLServer(port, factory, ctx) 
    95                 serviceObject.setName( 
    96                     "%s-%s" % tuple([x.upper() for x in (key, portName)])) 
     109                serviceName = "%s-%s" % \ 
     110                              tuple([x.upper() for x in (key, portName)]) 
     111                print serviceName 
     112                serviceObject.setName(serviceName) 
    97113                yield serviceObject 
    98114