示例#1
0
    def __init__(
        self, 
        Init = None,
        Session = None,
        reactor = None,
    ):
        """Initializes a Factory for serving a service
        that starts with a given initial mode.
        Passes any and all other arguments to
        the HTTPFactory initilizer."""

        if Init is not None:
            self.Init = Init
        if Session is not None:
            self.Session = Session
        if reactor is None:
            from twisted.internet import reactor
        self.reactor = reactor

        # path_service
        #  v  /session -> session_service
        # file_service
        #  v  
        # client_service

        self.client_service = ClientService() # hosts the client HTML page

        self.file_service = self.FileService() # hosts static content
        self.file_service.next_service = self.client_service # all file service misses load the client page

        # populate file service file mapping
        for name in os.listdir(module_path(__file__, 'content')):
            self.file_service.contents['.sh/' + name] = module_path(
                __file__,
                'content',
                name
            )

        self.session_service = self.SessionService(self) # hosts the polling XML request page

        self.path_service = PathService()
        self.path_service[self.session_url] = self.session_service # session service is hosted on /session
        self.path_service.next_service = self.file_service
        self.path_service.service = self.client_service

        self.service = self.path_service
示例#2
0
    def __init__(self, authenticate = True, *arguments, **keywords):

        BaseFactory.__init__(self, *arguments, **keywords)

        self.file_service.contents['.pysh/' + '@.css'] = module_path(
            __file__,
            'content',
            '@.css'
        )

        self.host = self.Host('.adhoc')
        self.path_service['.adhoc'] = self.host
        self.client_service = self.ClientService()
        self.file_service.next_service = self.client_service

        # require basic HTTP authentication against the unix
        #  password repository for the user that runs
        #  pyshd.
        if authenticate:
            self.service = AuthShadowSelfService(self.service)
示例#3
0
文件: ssl.py 项目: kriskowal/planes
    def __init__(self, certificateFile = None, keyFile = None):
        """Creates a ServerContextFactory using the specified
        certificate and key.  With no arguments, the factory
        creates contexts based on a 'server.pem' file which
        should contain both the certificate and key.   With
        one file name specified, the factory generates contexts
        based on that file, which should also contain both the
        certificate and key.  With two files specified, the
        factory generates contexts with separate certificate
        and key files, respectively."""

        if certificateFile is None:
            import __main__
            from planes.python.module_path import module_path
            certificateFile = module_path(__main__.__file__, 'server.pem')

        if keyFile is None:
            keyFile = certificateFile

        self.certificateFile = certificateFile
        self.keyFile = keyFile
示例#4
0
文件: modes.py 项目: kriskowal/planes
                self.globals['_'] = result
                self.globals['__'].append(result)

        except Exception, exception:
            pass

        if exception is not None:
            # print the exception
            self.message(tags.hr().xml)
            self.message(html_repr(exception).xml)
            self.message(tags.hr().xml)

        self.update()

Init.commands.load(
    module_path(__file__, 'commands.py'),
    module_path(__file__, '..', 'sh', 'general_commands.py'),
)

class StdoutRedirector(object):
    """
    Captures stdout from instantiation until close() is called.
    This is not really thread safe! It should be fine as long as
    we stay single threadded.
    """

    def __init__(self):
        import sys
        self.stdout = sys.stdout    # Save old stdout for later
        sys.stdout  = self          # Redirect future calls to write()
        self.data   = ''