Univention Bugzilla – Attachment 5956 Details for
Bug 35115
UCC-Setup and UCC-Image UMC modules are not using proxy connection
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for correct proxy handling in _get_file_size()
bug35115.patch (text/plain), 1.89 KB, created by
Alexander Kläser
on 2014-06-13 13:05:16 CEST
(
hide
)
Description:
Patch for correct proxy handling in _get_file_size()
Filename:
MIME Type:
Creator:
Alexander Kläser
Created:
2014-06-13 13:05:16 CEST
Size:
1.89 KB
patch
obsolete
>Index: src/images.py >=================================================================== >--- src/images.py (Revision 50894) >+++ src/images.py (Arbeitskopie) >@@ -41,6 +41,7 @@ > import hashlib > import lzma > import httplib >+import urllib2 > import urlparse > import contextlib > import re >@@ -191,20 +192,16 @@ > ucc/image/path via a HTTP HEAD request.''' > > url = '%s/%s' % (UCC_BASE_URL, filename) >- parts = urlparse.urlparse(url) >- if parts.scheme == 'http': >- connection = httplib.HTTPConnection(parts.hostname) >- elif parts.scheme == 'https': >- connection = httplib.HTTPSConnection(parts.hostname) >- else: >- raise httplib.error(_('Uknown protocol %s.') % parts.scheme) >+ request = urllib2.Request(url) >+ request.get_method = lambda : 'HEAD' >+ try: >+ response = urllib2.urlopen(request) >+ except urllib2.HTTPError as exc: >+ # raise an httplib error since this exception type is handled >+ raise httplib.error(_('Could not download file %s: %s') % (url, exc)) > >- connection.request('HEAD', parts.path) >- response = connection.getresponse() >- if response.status >= 400: >- raise httplib.error(_('Could not download file (%s - %s): %s') % (response.status, httplib.responses.get(response.status, _('Unknown error')), url)) >- headers = dict(response.getheaders()) >- size = int(headers.get('content-length', '0')) >+ info = response.info() >+ size = int(info.getheader('content-length', '0')) > return size > > >@@ -216,6 +213,16 @@ > return proxies > > >+# inspired from from u.m.c.modules.appcenter.util >+def _install_opener(): >+ proxies = _get_proxies() >+ if proxies: >+ proxy = urllib2.ProxyHandler(proxies) >+ opener = urllib2.build_opener(proxy) >+ urllib2.install_opener(opener) >+_install_opener() >+ >+ > def _download_url(url, filepath, progress=_dummy_progress): > '''Download specified URL to the given location on the hard disk. > Optionally with a callback function that receives the parameters (bytes_downloaded, bytes_total).'''
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 35115
: 5956