media/tools/constrained_network_server/cns.py
def ServeConstrained(self, f=None, bandwidth=None, latency=None, loss=None,
                       new_port=False, no_cache=False, **kwargs):
    """Serves the requested file with the requested constraints.

    Subsequent requests for the same constraints from the same IP will share the
    previously created port unless new_port equals True. If no constraints
    are provided the file is served as is.

    Args:
      f: path relative to http root of file to serve.
      bandwidth: maximum allowed bandwidth for the provided port (integer
          in kbit/s).
      latency: time to add to each packet (integer in ms).
      loss: percentage of packets to drop (integer, 0-100).
      new_port: whether to use a new port for this request or not.
      no_cache: Set reponse's cache-control to no-cache.
    """
    if no_cache:
      response = cherrypy.response
      response.headers['Pragma'] = 'no-cache'
      response.headers['Cache-Control'] = 'no-cache'

    # CherryPy is a bit wonky at detecting parameters, so just make them all
    # optional and validate them ourselves.
    if not f:
      raise cherrypy.HTTPError(400, 'Invalid request. File must be specified.')

    # Check existence early to prevent wasted constraint setup.
    self._CheckRequestedFileExist(f)

    # If there are no constraints, just serve the file.
    if bandwidth is None and latency is None and loss is None:
      return self._ServeFile(f)

    constrained_port = self._GetConstrainedPort(
        f, bandwidth=bandwidth, latency=latency, loss=loss, new_port=new_port,
        **kwargs)

    # Build constrained URL using the constrained port and original URL
    # parameters except the network constraints (bandwidth, latency, and loss).
    constrained_url = self._GetServerURL(f, constrained_port,
                                         no_cache=no_cache, **kwargs)

    # Redirect request to the constrained port.
    cherrypy.log('Redirect to %s' % constrained_url)
    cherrypy.lib.cptools.redirect(constrained_url, internal=False)
Serves the requested file with the requested constraints.

    Subsequent requests for the same constraints from the same IP will share the
    previously created port unless new_port equals True. If no constraints
    are provided the file is served as is.

    Args:
      f: path relative to http root of file to serve.
      bandwidth: maximum allowed bandwidth for the provided port (integer
          in kbit/s).
      latency: time to add to each packet (integer in ms).
      loss: percentage of packets to drop (integer, 0-100).
      new_port: whether to use a new port for this request or not.
      no_cache: Set reponse's cache-control to no-cache.
    
Serves the requested file with the requested constraints.
Subsequent requests for the same constraints from the same IP will share the
previously created port unless new_port equals True. If no constraints
are provided the file is served as is.
Serves the requested file with the requested constraints . Subsequent requests for the same constraints from the same IP will share the previously created port unless new_port equals True . If no constraints are provided the file is served as is .
def ServeConstrained(self, f=None, bandwidth=None, latency=None, loss=None,
                       new_port=False, no_cache=False, **kwargs):
    if no_cache:
      response = cherrypy.response
      response.headers['Pragma'] = 'no-cache'
      response.headers['Cache-Control'] = 'no-cache'
    if not f:
      raise cherrypy.HTTPError(400, 'Invalid request. File must be specified.')
    self._CheckRequestedFileExist(f)
    if bandwidth is None and latency is None and loss is None:
      return self._ServeFile(f)
    constrained_port = self._GetConstrainedPort(
        f, bandwidth=bandwidth, latency=latency, loss=loss, new_port=new_port,
        **kwargs)
    constrained_url = self._GetServerURL(f, constrained_port,
                                         no_cache=no_cache, **kwargs)
    cherrypy.log('Redirect to %s' % constrained_url)
    cherrypy.lib.cptools.redirect(constrained_url, internal=False)
def ServeConstrained ( self , f = None , bandwidth = None , latency = None , loss = None , new_port = False , no_cache = False , ** kwargs ) : if no_cache : response = cherrypy . response response . headers [ 'Pragma' ] = 'no-cache' response . headers [ 'Cache-Control' ] = 'no-cache' if not f : raise cherrypy . HTTPError ( 400 , 'Invalid request. File must be specified.' ) self . _CheckRequestedFileExist ( f ) if bandwidth is None and latency is None and loss is None : return self . _ServeFile ( f ) constrained_port = self . _GetConstrainedPort ( f , bandwidth = bandwidth , latency = latency , loss = loss , new_port = new_port , ** kwargs ) constrained_url = self . _GetServerURL ( f , constrained_port , no_cache = no_cache , ** kwargs ) cherrypy . log ( 'Redirect to %s' % constrained_url ) cherrypy . lib . cptools . redirect ( constrained_url , internal = False )
Serves the requested file with the requested constraints.
Serves the requested file with the requested constraints .
"""Serves the requested file with the requested constraints.

    Subsequent requests for the same constraints from the same IP will share the
    previously created port unless new_port equals True. If no constraints
    are provided the file is served as is.

    Args:
      f: path relative to http root of file to serve.
      bandwidth: maximum allowed bandwidth for the provided port (integer
          in kbit/s).
      latency: time to add to each packet (integer in ms).
      loss: percentage of packets to drop (integer, 0-100).
      new_port: whether to use a new port for this request or not.
      no_cache: Set reponse's cache-control to no-cache.
    """ # CherryPy is a bit wonky at detecting parameters, so just make them all # optional and validate them ourselves. # Check existence early to prevent wasted constraint setup. # If there are no constraints, just serve the file. # Build constrained URL using the constrained port and original URL # parameters except the network constraints (bandwidth, latency, and loss). # Redirect request to the constrained port.
self
f
path relative to http root of file to serve.
path relative to http root of file to serve .
bandwidth
maximum allowed bandwidth for the provided port (integer
in kbit/s).
maximum allowed bandwidth for the provided port ( integer in kbit / s ) .
latency
time to add to each packet (integer in ms).
time to add to each packet ( integer in ms ) .
loss
percentage of packets to drop (integer, 0-100).
percentage of packets to drop ( integer 0 - 100 ) .
new_port
whether to use a new port for this request or not.
whether to use a new port for this request or not .
no_cache
Set reponse's cache-control to no-cache.
Set reponse ' s cache - control to no - cache .