diff options
Diffstat (limited to 'ipapython')
-rw-r--r-- | ipapython/dogtag.py | 6 | ||||
-rw-r--r-- | ipapython/ipautil.py | 18 |
2 files changed, 21 insertions, 3 deletions
diff --git a/ipapython/dogtag.py b/ipapython/dogtag.py index 02f981974..c5317166a 100644 --- a/ipapython/dogtag.py +++ b/ipapython/dogtag.py @@ -20,7 +20,7 @@ from ipalib import api, errors import httplib import xml.dom.minidom -from ipapython import nsslib +from ipapython import nsslib, ipautil import nss.nss as nss from nss.error import NSPRError from ipalib.errors import NetworkError, CertificateOperationError @@ -72,7 +72,7 @@ def https_request(host, port, url, secdir, password, nickname, **kw): """ if isinstance(host, unicode): host = host.encode('utf-8') - uri = 'https://%s:%d%s' % (host, port, url) + uri = 'https://%s%s' % (ipautil.format_netloc(host, port), url) post = urlencode(kw) logging.info('sslget %r', uri) logging.debug('sslget post %r', post) @@ -110,7 +110,7 @@ def http_request(host, port, url, **kw): """ if isinstance(host, unicode): host = host.encode('utf-8') - uri = 'http://%s:%s%s' % (host, port, url) + uri = 'http://%s%s' % (ipautil.format_netloc(host, port), url) post = urlencode(kw) logging.info('request %r', uri) logging.debug('request post %r', post) diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index cfc979edb..dfeaa9e0b 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -151,6 +151,24 @@ class CheckedIPAddress(netaddr.IPAddress): def valid_ip(addr): return netaddr.valid_ipv4(addr) or netaddr.valid_ipv6(addr) +def format_netloc(host, port=None): + """ + Format network location (host:port). + + If the host part is a literal IPv6 address, it must be enclosed in square + brackets (RFC 2732). + """ + host = str(host) + try: + socket.inet_pton(socket.AF_INET6, host) + host = '[%s]' % host + except socket.error: + pass + if port is None: + return host + else: + return '%s:%s' % (host, str(port)) + def realm_to_suffix(realm_name): s = realm_name.split(".") terms = ["dc=" + x.lower() for x in s] |