summaryrefslogtreecommitdiff
path: root/macaroonbakery/_utils
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2018-08-20 17:53:45 +0100
committerColin Watson <cjwatson@debian.org>2018-08-20 17:53:45 +0100
commit2105a515d749b74eef9a6bb6af008aa6a842e313 (patch)
treee1f3e72483f3d81c6f00a5c0abddb59a85ae47f2 /macaroonbakery/_utils
parent4379a501141f75557e535f9c2ef3b58ef362259c (diff)
New upstream version 1.1.4
Diffstat (limited to 'macaroonbakery/_utils')
-rw-r--r--macaroonbakery/_utils/__init__.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/macaroonbakery/_utils/__init__.py b/macaroonbakery/_utils/__init__.py
index f2779e0..977cdbe 100644
--- a/macaroonbakery/_utils/__init__.py
+++ b/macaroonbakery/_utils/__init__.py
@@ -2,6 +2,7 @@
# Licensed under the LGPLv3, see LICENCE file for details.
import base64
import binascii
+import ipaddress
import json
import webbrowser
from datetime import datetime
@@ -134,7 +135,9 @@ def cookie(
it must be a naive timestamp in UTC.
'''
u = urlparse(url)
- domain = u.hostname or u.netloc
+ domain = u.hostname
+ if '.' not in domain and not _is_ip_addr(domain):
+ domain += ".local"
port = str(u.port) if u.port is not None else None
secure = u.scheme == 'https'
if expires is not None:
@@ -160,3 +163,18 @@ def cookie(
rest=None,
rfc2109=False,
)
+
+
+def _is_ip_addr(h):
+ if six.PY2:
+ # the python2.7 backport of ipaddr needs a bytestring passed in
+ try:
+ h = h.decode('ascii')
+ except UnicodeDecodeError:
+ # If there are non-ascii chars it's not an address anyway
+ return False
+ try:
+ ipaddress.ip_address(h)
+ except ValueError:
+ return False
+ return True