Beispiel #1
0
 def _add_request(self, method, url, headers, body, timeout, append=True):
     u = url.lower()
     if not (u.startswith('http://') or u.startswith('https://')):
         raise ValueError("Can only make HTTP or HTTPS requests with HTTPClient.")
     
     parts = urlparse.urlparse(url)
     
     # Build our headers.
     if headers is None:
         headers = {}
     
     if not 'Accept-Encoding' in headers:
         headers['Accept-Encoding'] = 'deflate, gzip'
     
     if not 'Host' in headers:
         headers['Host'] = parts.netloc
     
     if not 'User-Agent' in headers:
         headers['User-Agent'] = USER_AGENT
     
     if body:
         headers['Content-Length'] = len(body)
     
     path = parts.path or '/'
     if parts.query:
         path = '%s?%s' % (path, parts.query)
     if parts.fragment:
         path = '%s#%s' % (path, parts.fragment)
     
     request = [method, url, parts, headers, body, timeout, None, time(),
                 path, 0]
     
     if append:
         self._requests.append(request)
         
         # If we're just starting, start to process.
         if len(self._requests) == 1:
             callback(self._process_request)
     
     return request
Beispiel #2
0
###############################################################################

###############################################################################
# Imports
###############################################################################

from pants import engine, callback
from mud import *
from mud import MUDServer

import log


###############################################################################
# Initialisation
###############################################################################

if __name__ == "__main__":
    # Connect to the storage database.
    store.connect("pantsmud.db")
    
    # Create our servers.
    t = MUDServer()
    t.listen(port=4000)

    # Start storage auto-commit callback.
    callback(store.commit)
 
    # Start the engine.
    engine.start()