telemetry.core.memory_cache_http_server
index
telemetry/core/memory_cache_http_server.py

# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

 
Modules
       
BaseHTTPServer
SimpleHTTPServer
SocketServer
StringIO
gzip
mimetypes
os
sys

 
Classes
       
BaseHTTPServer.HTTPServer(SocketServer.TCPServer)
MemoryCacheHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer)
SimpleHTTPServer.SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler)
MemoryCacheHTTPRequestHandler
SocketServer.ThreadingMixIn
MemoryCacheHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer)
__builtin__.tuple(__builtin__.object)
ByteRange
ResourceAndRange

 
class ByteRange(__builtin__.tuple)
    ByteRange(from_byte, to_byte)
 
 
Method resolution order:
ByteRange
__builtin__.tuple
__builtin__.object

Methods defined here:
__getnewargs__(self)
Return self as a plain tuple.  Used by copy and pickle.
__repr__(self)
Return a nicely formatted representation string
_asdict(self)
Return a new OrderedDict which maps field names to their values
_replace(_self, **kwds)
Return a new ByteRange object replacing specified fields with new values

Class methods defined here:
_make(cls, iterable, new=<built-in method __new__ of type object>, len=<built-in function len>) from __builtin__.type
Make a new ByteRange object from a sequence or iterable

Static methods defined here:
__new__(_cls, from_byte, to_byte)
Create new instance of ByteRange(from_byte, to_byte)

Data descriptors defined here:
from_byte
Alias for field number 0
to_byte
Alias for field number 1

Data and other attributes defined here:
_fields = ('from_byte', 'to_byte')

Methods inherited from __builtin__.tuple:
__add__(...)
x.__add__(y) <==> x+y
__contains__(...)
x.__contains__(y) <==> y in x
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__mul__(...)
x.__mul__(n) <==> x*n
__ne__(...)
x.__ne__(y) <==> x!=y
__rmul__(...)
x.__rmul__(n) <==> n*x
__sizeof__(...)
T.__sizeof__() -- size of T in memory, in bytes
count(...)
T.count(value) -> integer -- return number of occurrences of value
index(...)
T.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.

 
class MemoryCacheHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler)
    
Method resolution order:
MemoryCacheHTTPRequestHandler
SimpleHTTPServer.SimpleHTTPRequestHandler
BaseHTTPServer.BaseHTTPRequestHandler
SocketServer.StreamRequestHandler
SocketServer.BaseRequestHandler

Methods defined here:
GetByteRange(self, total_num_of_bytes)
Parse the header and get the range values specified.
 
Args:
  total_num_of_bytes: Total # of bytes in requested resource,
  used to calculate upper range limit.
Returns:
  A ByteRange namedtuple object with the requested byte-range values.
  If no Range is explicitly requested or there is a failure parsing,
  return None.
  Special case: If range specified is in the format "N-", return N-N.
  If upper range limit is greater than total # of bytes, return upper index.
SendHead(self)
do_GET(self)
Serve a GET request.
do_HEAD(self)
Serve a HEAD request.

Methods inherited from SimpleHTTPServer.SimpleHTTPRequestHandler:
copyfile(self, source, outputfile)
Copy all data between two file objects.
 
The SOURCE argument is a file object open for reading
(or anything with a read() method) and the DESTINATION
argument is a file object open for writing (or
anything with a write() method).
 
The only reason for overriding this would be to change
the block size or perhaps to replace newlines by CRLF
-- note however that this the default server uses this
to copy binary data as well.
guess_type(self, path)
Guess the type of a file.
 
Argument is a PATH (a filename).
 
Return value is a string of the form type/subtype,
usable for a MIME Content-type header.
 
The default implementation looks the file's extension
up in the table self.extensions_map, using application/octet-stream
as a default; however it would be permissible (if
slow) to look inside the data to make a better guess.
list_directory(self, path)
Helper to produce a directory listing (absent index.html).
 
Return value is either a file object, or None (indicating an
error).  In either case, the headers are sent, making the
interface the same as for send_head().
send_head(self)
Common code for GET and HEAD commands.
 
This sends the response code and MIME headers.
 
Return value is either a file object (which has to be copied
to the outputfile by the caller unless the command was HEAD,
and must be closed by the caller under all circumstances), or
None, in which case the caller has nothing further to do.
translate_path(self, path)
Translate a /-separated PATH to the local filename syntax.
 
Components that mean special things to the local file system
(e.g. drive or directory names) are ignored.  (XXX They should
probably be diagnosed.)

Data and other attributes inherited from SimpleHTTPServer.SimpleHTTPRequestHandler:
extensions_map = {'': 'application/octet-stream', '.123': 'application/vnd.lotus-1-2-3', '.3dml': 'text/vnd.in3d.3dml', '.3g2': 'video/3gpp2', '.3gp': 'video/3gpp', '.7z': 'application/x-7z-compressed', '.a': 'application/octet-stream', '.aab': 'application/x-authorware-bin', '.aac': 'audio/x-aac', '.aam': 'application/x-authorware-map', ...}
server_version = 'SimpleHTTP/0.6'

Methods inherited from BaseHTTPServer.BaseHTTPRequestHandler:
address_string(self)
Return the client address formatted for logging.
 
This version looks up the full hostname using gethostbyaddr(),
and tries to find a name that contains at least one dot.
date_time_string(self, timestamp=None)
Return the current date and time formatted for a message header.
end_headers(self)
Send the blank line ending the MIME headers.
handle(self)
Handle multiple requests if necessary.
handle_one_request(self)
Handle a single HTTP request.
 
You normally don't need to override this method; see the class
__doc__ string for information on how to handle specific HTTP
commands such as GET and POST.
log_date_time_string(self)
Return the current time formatted for logging.
log_error(self, format, *args)
Log an error.
 
This is called when a request cannot be fulfilled.  By
default it passes the message on to log_message().
 
Arguments are the same as for log_message().
 
XXX This should go to the separate error log.
log_message(self, format, *args)
Log an arbitrary message.
 
This is used by all other logging functions.  Override
it if you have specific logging wishes.
 
The first argument, FORMAT, is a format string for the
message to be logged.  If the format string contains
any % escapes requiring parameters, they should be
specified as subsequent arguments (it's just like
printf!).
 
The client host and current date/time are prefixed to
every message.
log_request(self, code='-', size='-')
Log an accepted request.
 
This is called by send_response().
parse_request(self)
Parse a request (internal).
 
The request should be stored in self.raw_requestline; the results
are in self.command, self.path, self.request_version and
self.headers.
 
Return True for success, False for failure; on failure, an
error is sent back.
send_error(self, code, message=None)
Send and log an error reply.
 
Arguments are the error code, and a detailed message.
The detailed message defaults to the short entry matching the
response code.
 
This sends an error response (so it must be called before any
output has been generated), logs the error, and finally sends
a piece of HTML explaining the error to the user.
send_header(self, keyword, value)
Send a MIME header.
send_response(self, code, message=None)
Send the response header and log the response code.
 
Also send two standard headers with the server software
version and the current date.
version_string(self)
Return the server software version string.

Data and other attributes inherited from BaseHTTPServer.BaseHTTPRequestHandler:
MessageClass = <class mimetools.Message>
default_request_version = 'HTTP/0.9'
error_content_type = 'text/html'
error_message_format = '<head>\n<title>Error response</title>\n</head>\n<bo...ode explanation: %(code)s = %(explain)s.\n</body>\n'
monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
protocol_version = 'HTTP/1.0'
responses = {100: ('Continue', 'Request received, please continue'), 101: ('Switching Protocols', 'Switching to new protocol; obey Upgrade header'), 200: ('OK', 'Request fulfilled, document follows'), 201: ('Created', 'Document created, URL follows'), 202: ('Accepted', 'Request accepted, processing continues off-line'), 203: ('Non-Authoritative Information', 'Request fulfilled from cache'), 204: ('No Content', 'Request fulfilled, nothing follows'), 205: ('Reset Content', 'Clear input form for further input.'), 206: ('Partial Content', 'Partial content follows.'), 300: ('Multiple Choices', 'Object has several resources -- see URI list'), ...}
sys_version = 'Python/2.7.2'
weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']

Methods inherited from SocketServer.StreamRequestHandler:
finish(self)
setup(self)

Data and other attributes inherited from SocketServer.StreamRequestHandler:
disable_nagle_algorithm = False
rbufsize = -1
timeout = None
wbufsize = 0

Methods inherited from SocketServer.BaseRequestHandler:
__init__(self, request, client_address, server)

 
class MemoryCacheHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer)
    
Method resolution order:
MemoryCacheHTTPServer
SocketServer.ThreadingMixIn
BaseHTTPServer.HTTPServer
SocketServer.TCPServer
SocketServer.BaseServer

Methods defined here:
AddDirectoryToResourceMap(self, directory_path)
Loads all files in directory_path into the in-memory resource map.
AddFileToResourceMap(self, file_path)
Loads file_path into the in-memory resource map.
__init__(self, host_port, handler, paths)

Data and other attributes defined here:
request_queue_size = 128

Methods inherited from SocketServer.ThreadingMixIn:
process_request(self, request, client_address)
Start a new thread to process the request.
process_request_thread(self, request, client_address)
Same as in BaseServer but as a thread.
 
In addition, exception handling is done here.

Data and other attributes inherited from SocketServer.ThreadingMixIn:
daemon_threads = False

Methods inherited from BaseHTTPServer.HTTPServer:
server_bind(self)
Override server_bind to store the server name.

Data and other attributes inherited from BaseHTTPServer.HTTPServer:
allow_reuse_address = 1

Methods inherited from SocketServer.TCPServer:
close_request(self, request)
Called to clean up an individual request.
fileno(self)
Return socket file number.
 
Interface required by select().
get_request(self)
Get the request and client address from the socket.
 
May be overridden.
server_activate(self)
Called by constructor to activate the server.
 
May be overridden.
server_close(self)
Called to clean-up the server.
 
May be overridden.
shutdown_request(self, request)
Called to shutdown and close an individual request.

Data and other attributes inherited from SocketServer.TCPServer:
address_family = 2
socket_type = 1

Methods inherited from SocketServer.BaseServer:
finish_request(self, request, client_address)
Finish one request by instantiating RequestHandlerClass.
handle_error(self, request, client_address)
Handle an error gracefully.  May be overridden.
 
The default is to print a traceback and continue.
handle_request(self)
Handle one request, possibly blocking.
 
Respects self.timeout.
handle_timeout(self)
Called if no new request arrives within self.timeout.
 
Overridden by ForkingMixIn.
serve_forever(self, poll_interval=0.5)
Handle one request at a time until shutdown.
 
Polls for shutdown every poll_interval seconds. Ignores
self.timeout. If you need to do periodic tasks, do them in
another thread.
shutdown(self)
Stops the serve_forever loop.
 
Blocks until the loop has finished. This must be called while
serve_forever() is running in another thread, or it will
deadlock.
verify_request(self, request, client_address)
Verify the request.  May be overridden.
 
Return True if we should proceed with this request.

Data and other attributes inherited from SocketServer.BaseServer:
timeout = None

 
class ResourceAndRange(__builtin__.tuple)
    ResourceAndRange(resource, byte_range)
 
 
Method resolution order:
ResourceAndRange
__builtin__.tuple
__builtin__.object

Methods defined here:
__getnewargs__(self)
Return self as a plain tuple.  Used by copy and pickle.
__repr__(self)
Return a nicely formatted representation string
_asdict(self)
Return a new OrderedDict which maps field names to their values
_replace(_self, **kwds)
Return a new ResourceAndRange object replacing specified fields with new values

Class methods defined here:
_make(cls, iterable, new=<built-in method __new__ of type object>, len=<built-in function len>) from __builtin__.type
Make a new ResourceAndRange object from a sequence or iterable

Static methods defined here:
__new__(_cls, resource, byte_range)
Create new instance of ResourceAndRange(resource, byte_range)

Data descriptors defined here:
byte_range
Alias for field number 1
resource
Alias for field number 0

Data and other attributes defined here:
_fields = ('resource', 'byte_range')

Methods inherited from __builtin__.tuple:
__add__(...)
x.__add__(y) <==> x+y
__contains__(...)
x.__contains__(y) <==> y in x
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__mul__(...)
x.__mul__(n) <==> x*n
__ne__(...)
x.__ne__(y) <==> x!=y
__rmul__(...)
x.__rmul__(n) <==> n*x
__sizeof__(...)
T.__sizeof__() -- size of T in memory, in bytes
count(...)
T.count(value) -> integer -- return number of occurrences of value
index(...)
T.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.

 
Functions
       
Main()