Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
af9d10aa
Commit
af9d10aa
authored
Sep 13, 2010
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logging: enhanced HTTPHandler
parent
1b5646ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
+16
-4
Lib/logging/handlers.py
Lib/logging/handlers.py
+14
-4
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/logging/handlers.py
View file @
af9d10aa
...
@@ -977,7 +977,7 @@ class HTTPHandler(logging.Handler):
...
@@ -977,7 +977,7 @@ class HTTPHandler(logging.Handler):
A class which sends records to a Web server, using either GET or
A class which sends records to a Web server, using either GET or
POST semantics.
POST semantics.
"""
"""
def
__init__
(
self
,
host
,
url
,
method
=
"GET"
):
def
__init__
(
self
,
host
,
url
,
method
=
"GET"
,
secure
=
False
,
credentials
=
None
):
"""
"""
Initialize the instance with the host, the request URL, and the method
Initialize the instance with the host, the request URL, and the method
("GET" or "POST")
("GET" or "POST")
...
@@ -989,12 +989,14 @@ class HTTPHandler(logging.Handler):
...
@@ -989,12 +989,14 @@ class HTTPHandler(logging.Handler):
self
.
host
=
host
self
.
host
=
host
self
.
url
=
url
self
.
url
=
url
self
.
method
=
method
self
.
method
=
method
self
.
secure
=
secure
self
.
credentials
=
credentials
def
mapLogRecord
(
self
,
record
):
def
mapLogRecord
(
self
,
record
):
"""
"""
Default implementation of mapping the log record into a dict
Default implementation of mapping the log record into a dict
that is sent as the CGI data. Overwrite in your class.
that is sent as the CGI data. Overwrite in your class.
Contributed by Franz
Glasner.
Contributed by Franz Glasner.
"""
"""
return
record
.
__dict__
return
record
.
__dict__
...
@@ -1007,7 +1009,10 @@ class HTTPHandler(logging.Handler):
...
@@ -1007,7 +1009,10 @@ class HTTPHandler(logging.Handler):
try
:
try
:
import
http.client
,
urllib
.
parse
import
http.client
,
urllib
.
parse
host
=
self
.
host
host
=
self
.
host
h
=
http
.
client
.
HTTP
(
host
)
if
self
.
secure
:
h
=
http
.
client
.
HTTPSConnection
(
host
)
else
:
h
=
http
.
client
.
HTTPConnection
(
host
)
url
=
self
.
url
url
=
self
.
url
data
=
urllib
.
parse
.
urlencode
(
self
.
mapLogRecord
(
record
))
data
=
urllib
.
parse
.
urlencode
(
self
.
mapLogRecord
(
record
))
if
self
.
method
==
"GET"
:
if
self
.
method
==
"GET"
:
...
@@ -1027,8 +1032,13 @@ class HTTPHandler(logging.Handler):
...
@@ -1027,8 +1032,13 @@ class HTTPHandler(logging.Handler):
h
.
putheader
(
"Content-type"
,
h
.
putheader
(
"Content-type"
,
"application/x-www-form-urlencoded"
)
"application/x-www-form-urlencoded"
)
h
.
putheader
(
"Content-length"
,
str
(
len
(
data
)))
h
.
putheader
(
"Content-length"
,
str
(
len
(
data
)))
if
self
.
credentials
:
import
base64
s
=
(
'u%s:%s'
%
self
.
credentials
).
encode
(
'utf-8'
)
s
=
'Basic '
+
base64
.
b64encode
(
s
).
strip
()
h
.
putheader
(
'Authorization'
,
s
)
h
.
endheaders
(
data
if
self
.
method
==
"POST"
else
None
)
h
.
endheaders
(
data
if
self
.
method
==
"POST"
else
None
)
h
.
getre
ply
()
#can't do anything with the result
h
.
getre
sponse
()
#can't do anything with the result
except
(
KeyboardInterrupt
,
SystemExit
):
except
(
KeyboardInterrupt
,
SystemExit
):
raise
raise
except
:
except
:
...
...
Misc/NEWS
View file @
af9d10aa
...
@@ -40,6 +40,8 @@ Core and Builtins
...
@@ -40,6 +40,8 @@ Core and Builtins
Library
Library
-------
-------
- logging: Enhanced HTTPHandler with secure and credentials initializers.
- Issue #767645: Set os.path.supports_unicode_filenames to True on Mac OS X
- Issue #767645: Set os.path.supports_unicode_filenames to True on Mac OS X
(macpath module).
(macpath module).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment