Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
logging.handlers.HTTPHandler Class Reference

List of all members.

Public Member Functions

def __init__
def mapLogRecord
def emit

Public Attributes

 host
 url
 method
 secure
 credentials

Detailed Description

A class which sends records to a Web server, using either GET or
POST semantics.

Definition at line 986 of file handlers.py.


Constructor & Destructor Documentation

def logging.handlers.HTTPHandler.__init__ (   self,
  host,
  url,
  method = "GET",
  secure = False,
  credentials = None 
)
Initialize the instance with the host, the request URL, and the method
("GET" or "POST")

Definition at line 991 of file handlers.py.

00991 
00992     def __init__(self, host, url, method="GET", secure=False, credentials=None):
00993         """
00994         Initialize the instance with the host, the request URL, and the method
00995         ("GET" or "POST")
00996         """
00997         logging.Handler.__init__(self)
00998         method = method.upper()
00999         if method not in ["GET", "POST"]:
01000             raise ValueError("method must be GET or POST")
01001         self.host = host
01002         self.url = url
01003         self.method = method
01004         self.secure = secure
01005         self.credentials = credentials

Here is the caller graph for this function:


Member Function Documentation

def logging.handlers.HTTPHandler.emit (   self,
  record 
)
Emit a record.

Send the record to the Web server as a percent-encoded dictionary

Definition at line 1014 of file handlers.py.

01014 
01015     def emit(self, record):
01016         """
01017         Emit a record.
01018 
01019         Send the record to the Web server as a percent-encoded dictionary
01020         """
01021         try:
01022             import http.client, urllib.parse
01023             host = self.host
01024             if self.secure:
01025                 h = http.client.HTTPSConnection(host)
01026             else:
01027                 h = http.client.HTTPConnection(host)
01028             url = self.url
01029             data = urllib.parse.urlencode(self.mapLogRecord(record))
01030             if self.method == "GET":
01031                 if (url.find('?') >= 0):
01032                     sep = '&'
01033                 else:
01034                     sep = '?'
01035                 url = url + "%c%s" % (sep, data)
01036             h.putrequest(self.method, url)
01037             # support multiple hosts on one IP address...
01038             # need to strip optional :port from host, if present
01039             i = host.find(":")
01040             if i >= 0:
01041                 host = host[:i]
01042             h.putheader("Host", host)
01043             if self.method == "POST":
01044                 h.putheader("Content-type",
01045                             "application/x-www-form-urlencoded")
01046                 h.putheader("Content-length", str(len(data)))
01047             if self.credentials:
01048                 import base64
01049                 s = ('u%s:%s' % self.credentials).encode('utf-8')
01050                 s = 'Basic ' + base64.b64encode(s).strip()
01051                 h.putheader('Authorization', s)
01052             h.endheaders(data if self.method == "POST" else None)
01053             h.getresponse()    #can't do anything with the result
01054         except (KeyboardInterrupt, SystemExit):
01055             raise
01056         except:
01057             self.handleError(record)

Here is the call graph for this function:

def logging.handlers.HTTPHandler.mapLogRecord (   self,
  record 
)
Default implementation of mapping the log record into a dict
that is sent as the CGI data. Overwrite in your class.
Contributed by Franz Glasner.

Definition at line 1006 of file handlers.py.

01006 
01007     def mapLogRecord(self, record):
01008         """
01009         Default implementation of mapping the log record into a dict
01010         that is sent as the CGI data. Overwrite in your class.
01011         Contributed by Franz Glasner.
01012         """
01013         return record.__dict__

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1004 of file handlers.py.

Definition at line 1000 of file handlers.py.

Definition at line 1002 of file handlers.py.

Definition at line 1003 of file handlers.py.

Definition at line 1001 of file handlers.py.


The documentation for this class was generated from the following file: