Commit 54031cdd authored by Amos Latteier's avatar Amos Latteier

Fixed tabs and improved PCGI file parsing.

parent 7965f847
...@@ -205,30 +205,29 @@ class PCGIChannel(asynchat.async_chat): ...@@ -205,30 +205,29 @@ class PCGIChannel(asynchat.async_chat):
method=self.env['REQUEST_METHOD'] method=self.env['REQUEST_METHOD']
else: else:
method="GET" method="GET"
if self.addr: if self.addr:
self.server.logger.log ( self.server.logger.log (
self.addr[0], self.addr[0],
'%d - - [%s] "%s %s" %d' % ( '%d - - [%s] "%s %s" %d' % (
self.addr[1], self.addr[1],
time.strftime ( time.strftime (
'%d/%b/%Y:%H:%M:%S ', '%d/%b/%Y:%H:%M:%S ',
time.gmtime(time.time()) time.gmtime(time.time())
) + tz_for_log, ) + tz_for_log,
method, path, bytes method, path, bytes
) )
) )
else: else:
self.server.logger.log ( self.server.logger.log (
'127.0.0.1', '127.0.0.1',
'- - [%s] "%s %s" %d' % ( '- - [%s] "%s %s" %d' % (
time.strftime ( time.strftime (
'%d/%b/%Y:%H:%M:%S ', '%d/%b/%Y:%H:%M:%S ',
time.gmtime(time.time()) time.gmtime(time.time())
) + tz_for_log, ) + tz_for_log,
method, path, bytes method, path, bytes
) )
) )
def push(self, producer, send=1): def push(self, producer, send=1):
# this is thread-safe when send is false # this is thread-safe when send is false
...@@ -237,9 +236,8 @@ class PCGIChannel(asynchat.async_chat): ...@@ -237,9 +236,8 @@ class PCGIChannel(asynchat.async_chat):
self.producer_fifo.push(producer) self.producer_fifo.push(producer)
if send: self.initiate_send() if send: self.initiate_send()
def __repr__(self):
def __repr__(self): return "<PCGIChannel at %x>" % id(self)
return "<PCGIChannel at %x>" % id(self)
class PCGIServer(asyncore.dispatcher): class PCGIServer(asyncore.dispatcher):
"""Accepts PCGI requests and hands them off to the PCGIChannel for """Accepts PCGI requests and hands them off to the PCGIChannel for
...@@ -277,12 +275,11 @@ class PCGIServer(asyncore.dispatcher): ...@@ -277,12 +275,11 @@ class PCGIServer(asyncore.dispatcher):
self.logger = logger.unresolving_logger (logger_object) self.logger = logger.unresolving_logger (logger_object)
# get configuration # get configuration
if pcgi_file is None: self.module=module
self.module=module self.port=port
self.port=port self.pid_file=pid_file
self.pid_file=pid_file self.socket_file=socket_file
self.socket_file=socket_file if pcgi_file is not None:
else:
self.read_info(pcgi_file) self.read_info(pcgi_file)
# write pid file # write pid file
...@@ -317,16 +314,18 @@ class PCGIServer(asyncore.dispatcher): ...@@ -317,16 +314,18 @@ class PCGIServer(asyncore.dispatcher):
lines=open(info_file).readlines() lines=open(info_file).readlines()
directives={} directives={}
for line in lines: for line in lines:
line=string.strip(line)
if not len(line) or line[0]=='#': if not len(line) or line[0]=='#':
continue continue
k,v=string.split(line,'=',1) k,v=string.split(line,'=',1)
directives[string.strip(k)]=string.strip(v) directives[string.strip(k)]=string.strip(v)
self.pid_file=directives['PCGI_PID_FILE'] self.pid_file=directives.get('PCGI_PID_FILE',None)
self.socket_file=directives.get('PCGI_SOCKET_FILE',None) self.socket_file=directives.get('PCGI_SOCKET_FILE',None)
self.port=directives.get('PCGI_PORT',None) if directives.has_key('PCGI_PORT'):
self.port=string.atoi(directives['PCGI_PORT'])
if directives.has_key('PCGI_MODULE'): if directives.has_key('PCGI_MODULE'):
self.module=directives['PCGI_MODULE'] self.module=directives['PCGI_MODULE']
else: elif directives.has_key('PCGI_MODULE_PATH'):
path=directives['PCGI_MODULE_PATH'] path=directives['PCGI_MODULE_PATH']
path,module=os.path.split(path) path,module=os.path.split(path)
module,ext=os.path.splitext(module) module,ext=os.path.splitext(module)
......
...@@ -205,30 +205,29 @@ class PCGIChannel(asynchat.async_chat): ...@@ -205,30 +205,29 @@ class PCGIChannel(asynchat.async_chat):
method=self.env['REQUEST_METHOD'] method=self.env['REQUEST_METHOD']
else: else:
method="GET" method="GET"
if self.addr: if self.addr:
self.server.logger.log ( self.server.logger.log (
self.addr[0], self.addr[0],
'%d - - [%s] "%s %s" %d' % ( '%d - - [%s] "%s %s" %d' % (
self.addr[1], self.addr[1],
time.strftime ( time.strftime (
'%d/%b/%Y:%H:%M:%S ', '%d/%b/%Y:%H:%M:%S ',
time.gmtime(time.time()) time.gmtime(time.time())
) + tz_for_log, ) + tz_for_log,
method, path, bytes method, path, bytes
) )
) )
else: else:
self.server.logger.log ( self.server.logger.log (
'127.0.0.1', '127.0.0.1',
'- - [%s] "%s %s" %d' % ( '- - [%s] "%s %s" %d' % (
time.strftime ( time.strftime (
'%d/%b/%Y:%H:%M:%S ', '%d/%b/%Y:%H:%M:%S ',
time.gmtime(time.time()) time.gmtime(time.time())
) + tz_for_log, ) + tz_for_log,
method, path, bytes method, path, bytes
) )
) )
def push(self, producer, send=1): def push(self, producer, send=1):
# this is thread-safe when send is false # this is thread-safe when send is false
...@@ -237,9 +236,8 @@ class PCGIChannel(asynchat.async_chat): ...@@ -237,9 +236,8 @@ class PCGIChannel(asynchat.async_chat):
self.producer_fifo.push(producer) self.producer_fifo.push(producer)
if send: self.initiate_send() if send: self.initiate_send()
def __repr__(self):
def __repr__(self): return "<PCGIChannel at %x>" % id(self)
return "<PCGIChannel at %x>" % id(self)
class PCGIServer(asyncore.dispatcher): class PCGIServer(asyncore.dispatcher):
"""Accepts PCGI requests and hands them off to the PCGIChannel for """Accepts PCGI requests and hands them off to the PCGIChannel for
...@@ -277,12 +275,11 @@ class PCGIServer(asyncore.dispatcher): ...@@ -277,12 +275,11 @@ class PCGIServer(asyncore.dispatcher):
self.logger = logger.unresolving_logger (logger_object) self.logger = logger.unresolving_logger (logger_object)
# get configuration # get configuration
if pcgi_file is None: self.module=module
self.module=module self.port=port
self.port=port self.pid_file=pid_file
self.pid_file=pid_file self.socket_file=socket_file
self.socket_file=socket_file if pcgi_file is not None:
else:
self.read_info(pcgi_file) self.read_info(pcgi_file)
# write pid file # write pid file
...@@ -317,16 +314,18 @@ class PCGIServer(asyncore.dispatcher): ...@@ -317,16 +314,18 @@ class PCGIServer(asyncore.dispatcher):
lines=open(info_file).readlines() lines=open(info_file).readlines()
directives={} directives={}
for line in lines: for line in lines:
line=string.strip(line)
if not len(line) or line[0]=='#': if not len(line) or line[0]=='#':
continue continue
k,v=string.split(line,'=',1) k,v=string.split(line,'=',1)
directives[string.strip(k)]=string.strip(v) directives[string.strip(k)]=string.strip(v)
self.pid_file=directives['PCGI_PID_FILE'] self.pid_file=directives.get('PCGI_PID_FILE',None)
self.socket_file=directives.get('PCGI_SOCKET_FILE',None) self.socket_file=directives.get('PCGI_SOCKET_FILE',None)
self.port=directives.get('PCGI_PORT',None) if directives.has_key('PCGI_PORT'):
self.port=string.atoi(directives['PCGI_PORT'])
if directives.has_key('PCGI_MODULE'): if directives.has_key('PCGI_MODULE'):
self.module=directives['PCGI_MODULE'] self.module=directives['PCGI_MODULE']
else: elif directives.has_key('PCGI_MODULE_PATH'):
path=directives['PCGI_MODULE_PATH'] path=directives['PCGI_MODULE_PATH']
path,module=os.path.split(path) path,module=os.path.split(path)
module,ext=os.path.splitext(module) module,ext=os.path.splitext(module)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment