summaryrefslogtreecommitdiff
path: root/macaroonbakery/_utils
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2018-08-20 17:53:46 +0100
committerColin Watson <cjwatson@debian.org>2018-08-20 17:54:31 +0100
commitf3d0400ea57884c6bd7f1d66352d3e44ad20e286 (patch)
tree9e826ffbdb7cb51825b67bd35a33de79ccb97356 /macaroonbakery/_utils
parentae33a39d857b367e216f1e80530c09087b108d16 (diff)
parent2105a515d749b74eef9a6bb6af008aa6a842e313 (diff)
Update upstream source from tag 'upstream/1.1.4'
Update to upstream version '1.1.4' with Debian dir 42ca954c317c7fd65bffdc0e0e6803556dccdf2f
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