[python-urllib2_kerberos: 8/8] Fix logging format for Python 2.6 (#1065576)
Matej Cepl
mcepl at fedoraproject.org
Mon Sep 15 22:02:25 UTC 2014
commit 67290d7a5cf0011a0faa2dde4cb065e82ca7399d
Author: Matěj Cepl <mcepl at redhat.com>
Date: Tue Sep 16 00:01:58 2014 +0200
Fix logging format for Python 2.6 (#1065576)
add-logging.patch | 29 +++++++++++++++++++++++++++++
python-urllib2_kerberos.spec | 5 ++++-
test_trac.py | 13 +++++++++++++
3 files changed, 46 insertions(+), 1 deletions(-)
---
diff --git a/add-logging.patch b/add-logging.patch
new file mode 100644
index 0000000..a951487
--- /dev/null
+++ b/add-logging.patch
@@ -0,0 +1,29 @@
+--- a/urllib2_kerberos.py
++++ b/urllib2_kerberos.py
+@@ -24,7 +24,16 @@ import urllib2 as u2
+
+ import kerberos as k
+
+-log = logging.getLogger("http_kerberos_auth_handler")
++def getLogger():
++ log = logging.getLogger("http_kerberos_auth_handler")
++ handler = logging.StreamHandler()
++ formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
++ handler.setFormatter(formatter)
++ log.addHandler(handler)
++ return log
++
++log = getLogger()
++log.setLevel(logging.DEBUG)
+
+ class AbstractKerberosAuthHandler:
+ """auth handler for urllib2 that does Kerberos HTTP Negotiate Authentication
+@@ -126,6 +135,8 @@ class AbstractKerberosAuthHandler:
+
+ req.add_unredirected_header(self.authz_header, neg_hdr)
+ resp = self.parent.open(req)
++ log.debug('resp = {}'.format(resp))
++ log.debug('resp = type {}'.format(type(resp)))
+
+ if resp.getcode() != 200:
+ self.authenticate_server(resp.info())
diff --git a/python-urllib2_kerberos.spec b/python-urllib2_kerberos.spec
index d5a4815..b4d4c26 100644
--- a/python-urllib2_kerberos.spec
+++ b/python-urllib2_kerberos.spec
@@ -18,6 +18,7 @@ Patch1: allow_client_apps_to_configure_loggers.patch
Patch2: dont-panick-if-we-succeed.patch
# From https://bugzilla.redhat.com/show_bug.cgi?id=578711
Patch3: port-to-python-2.4.patch
+Patch4: add-logging.patch
BuildArch: noarch
BuildRequires: python-setuptools
@@ -37,6 +38,8 @@ urllib2 with kerberos authentication.
%patch3 -p1
%endif
+%patch4 -p1
+
# Remove "#!/usr/bin/python\n"
lib=urllib2_kerberos.py
sed '1{\@^#!/usr/bin/python at d}' $lib > $lib.new && \
@@ -54,7 +57,7 @@ touch -r $lib $lib.new && mv $lib.new $lib
%files
%{python_sitelib}/*
-
+# TODO this should be fix for #1065576, #578711, and #1115513
%changelog
* Thu Jul 03 2014 Matěj Cepl <mcepl at redhat.com> - 0.1.6-13
- Fix logging format for Python 2.6 (#1065576)
diff --git a/test_trac.py b/test_trac.py
new file mode 100644
index 0000000..f5449ed
--- /dev/null
+++ b/test_trac.py
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+import urllib2
+import cookielib
+import urllib2_kerberos
+
+
+cj = cookielib.CookieJar()
+opener = urllib2.build_opener(urllib2.HTTPSHandler(debuglevel=2),
+ urllib2.HTTPRedirectHandler,
+ urllib2.HTTPCookieProcessor(cj),
+ urllib2_kerberos.HTTPKerberosAuthHandler)
+
+response = opener.open('URL of the webpage')
More information about the scm-commits
mailing list