Example #1
0
    def __init__(self,
                 module='Main',
                 ip='127.0.0.1',
                 port=None,
                 socket_file=None,
                 pid_file=None,
                 pcgi_file=None,
                 resolver=None,
                 logger_object=None):

        self.ip = ip
        asyncore.dispatcher.__init__(self)
        self.count = counter()
        if not logger_object:
            logger_object = logger.file_logger(sys.stdout)
        if resolver:
            self.logger = logger.resolving_logger(resolver, logger_object)
        else:
            self.logger = logger.unresolving_logger(logger_object)

        # get configuration
        self.module = module
        self.port = port
        self.pid_file = pid_file
        self.socket_file = socket_file
        if pcgi_file is not None:
            self.read_info(pcgi_file)

        # write pid file
        try:
            f = open(self.pid_file, 'w')
            f.write(str(os.getpid()))
            f.close()
        except IOError:
            self.log_info("Cannot write PID file.", 'error')

        # setup sockets
        if self.port:
            self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
            self.set_reuse_addr()
            self.bind((self.ip, self.port))
            self.log_info('PCGI Server started at %s\n'
                          '\tInet socket port: %s' %
                          (time.ctime(time.time()), self.port))
        else:
            try:
                os.unlink(self.socket_file)
            except os.error:
                pass
            self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM)
            self.set_reuse_addr()
            self.bind(self.socket_file)
            try:
                os.chmod(self.socket_file, 0777)
            except os.error:
                pass
            self.log_info('PCGI Server started at %s\n'
                          '\tUnix socket: %s' %
                          (time.ctime(time.time()), self.socket_file))
        self.listen(256)
Example #2
0
    def __init__(self, module, uri_base=None, env=None):
        """Creates a zope_handler

        module -- string, the name of the module to publish
        uri_base -- string, the base uri of the published module
                    defaults to '/<module name>' if not given.
        env -- dictionary, environment variables to be overridden.
                    Replaces standard variables with supplied ones.
        """

        self.module_name = module
        self.env_override = env or {}
        self.hits = counter.counter()
        # if uri_base is unspecified, assume it
        # starts with the published module name
        #
        if uri_base is None:
            uri_base = '/%s' % module
        elif uri_base == '':
            uri_base = '/'
        else:
            if uri_base[0] != '/':
                uri_base = '/' + uri_base
            if uri_base[-1] == '/':
                uri_base = uri_base[:-1]
        self.uri_base = uri_base
        uri_regex = '%s.*' % self.uri_base
        self.uri_regex = re.compile(uri_regex)
Example #3
0
    def __init__(self, module, uri_base=None, env=None):
        """Creates a zope_handler

        module -- string, the name of the module to publish
        uri_base -- string, the base uri of the published module
                    defaults to '/<module name>' if not given.
        env -- dictionary, environment variables to be overridden.
                    Replaces standard variables with supplied ones.
        """

        self.module_name = module
        self.env_override = env or {}
        self.hits = counter.counter()
        # if uri_base is unspecified, assume it
        # starts with the published module name
        #
        if uri_base is None:
            uri_base = '/%s' % module
        elif uri_base == '':
            uri_base = '/'
        else:
            if uri_base[0] != '/':
                uri_base = '/' + uri_base
            if uri_base[-1] == '/':
                uri_base = uri_base[:-1]
        self.uri_base = uri_base
        uri_regex = '%s.*' % self.uri_base
        self.uri_regex = re.compile(uri_regex)
Example #4
0
    def __init__(self,
                 module='Main',
                 ip='127.0.0.1',
                 port=None,
                 socket_file=None,
                 resolver=None,
                 logger_object=None):

        self.ip = ip
        self.count = counter()
        asyncore.dispatcher.__init__(self)
        if not logger_object:
            logger_object = logger.file_logger(sys.stdout)
        if resolver:
            self.logger = logger.resolving_logger(resolver, logger_object)
        else:
            self.logger = logger.unresolving_logger(logger_object)

        # get configuration
        self.module = module
        self.port = port
        self.socket_file = socket_file

        # setup sockets
        if self.port:
            self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
            self.set_reuse_addr()
            self.bind((self.ip, self.port))
        else:
            try:
                os.unlink(self.socket_file)
            except os.error:
                pass
            self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM)
            self.set_reuse_addr()
            self.bind(self.socket_file)
            try:
                os.chmod(self.socket_file, 0o777)
            except os.error:
                pass
        self.listen(256)
        self.log_info('FastCGI Server (V%s) started at %s\n'
                      '\tIP          : %s\n'
                      '\tPort        : %s\n'
                      '\tSocket path : %s\n'
                      % ('1.0', time.ctime(time.time()), self.ip,
                         self.port, self.socket_file))
Example #5
0
    def __init__(self,
                 module='Main',
                 ip='127.0.0.1',
                 port=None,
                 socket_file=None,
                 resolver=None,
                 logger_object=None):

        self.ip = ip
        self.count = counter()
        asyncore.dispatcher.__init__(self)
        if not logger_object:
            logger_object = logger.file_logger(sys.stdout)
        if resolver:
            self.logger = logger.resolving_logger(resolver, logger_object)
        else:
            self.logger = logger.unresolving_logger(logger_object)

        # get configuration
        self.module = module
        self.port = port
        self.socket_file = socket_file

        # setup sockets
        if self.port:
            self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
            self.set_reuse_addr()
            self.bind((self.ip, self.port))
        else:
            try:
                os.unlink(self.socket_file)
            except os.error:
                pass
            self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM)
            self.set_reuse_addr()
            self.bind(self.socket_file)
            try:
                os.chmod(self.socket_file, 0o777)
            except os.error:
                pass
        self.listen(256)
        self.log_info('FastCGI Server (V%s) started at %s\n'
                      '\tIP          : %s\n'
                      '\tPort        : %s\n'
                      '\tSocket path : %s\n'
                      % ('1.0', time.ctime(time.time()), self.ip,
                         self.port, self.socket_file))