Skip to content

Commit

Permalink
Merge pull request jellyfin#109 from oddstr13/pr-ipv6-input-brackets-2
Browse files Browse the repository at this point in the history
Remove dependency on `ipaddress` (not stdlib in py2)
  • Loading branch information
mcarlton00 authored Oct 5, 2019
2 parents 0306d7a + f565c0a commit fb6e8f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 6 additions & 7 deletions resources/lib/dialogs/servermanual.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging
import os
import ipaddress
import re

import xbmcgui
import xbmcaddon
Expand All @@ -27,6 +27,9 @@
'Empty': 2
}

# https://stackoverflow.com/a/17871737/1035647
_IPV6_PATTERN = "^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$"
_IPV6_RE = re.compile(_IPV6_PATTERN)
##################################################################################################


Expand Down Expand Up @@ -115,12 +118,8 @@ def _add_editcontrol(self, x, y, height, width):
return control

def _connect_to_server(self, server, port):
try:
addr = ipaddress.ip_address(server.decode('utf-8') if not isinstance(server, type(u'')) else server)
if addr.version == 6:
server = u"[%s]" % (addr.compressed)
except ValueError:
pass
if _IPV6_RE.match(server):
server = "[%s]" % (server)

server_address = "%s:%s" % (server, port) if port else server
self._message("%s %s..." % (_(30610), server_address))
Expand Down
4 changes: 4 additions & 0 deletions resources/lib/jellyfin/core/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ def _convert_endpoint_address_to_manual_address(self, info):
return None

def _normalize_address(self, address):
# TODO: Try HTTPS first, then HTTP if that fails.
if '://' not in address:
address = 'http://' + address

# Attempt to correct bad input
url = urllib3.util.parse_url(address.strip())

Expand Down

0 comments on commit fb6e8f5

Please sign in to comment.