add normalize_uri instead of short_hostname
- use gethostbyaddr only in case of numeric IP - hard wired reverse CNAME (network alias) for linse-c
This commit is contained in:
21
streams.py
21
streams.py
@ -3,6 +3,7 @@ import time
|
||||
import re
|
||||
import logging
|
||||
from select import select
|
||||
from normalizeuri import normalizeuri
|
||||
|
||||
|
||||
class StreamDead(Exception):
|
||||
@ -34,20 +35,6 @@ class Base:
|
||||
logging.info('FINISH BASE')
|
||||
|
||||
|
||||
def short_hostname(host):
|
||||
"""psi/lin/se special
|
||||
|
||||
- treat case where -129129xxxx is appended
|
||||
"""
|
||||
host = socket.gethostbyaddr(host)[0]
|
||||
if host == 'localhost':
|
||||
host = socket.gethostname()
|
||||
match = re.match(r'([^.-]+)(?:-129129\d{6}|(-[~.]*|)).psi.ch', host)
|
||||
if match:
|
||||
host = match.group(1) + (match.group(2) or '')
|
||||
return host
|
||||
|
||||
|
||||
class Stream(Base):
|
||||
_last_time = None
|
||||
dead = False
|
||||
@ -82,10 +69,8 @@ class Stream(Base):
|
||||
self.socket = socket.create_connection(parse_uri(self.uri))
|
||||
self.select_read[self.socket.fileno()] = self
|
||||
self.settimeout(self.timeout)
|
||||
host, _, port = self.uri.partition(':')
|
||||
# try to convert uri to host name
|
||||
self.uri = self.tags['stream'] = f'{short_hostname(host)}:{port}'
|
||||
logging.info('connected %s:%s = %s', host, port, self.uri)
|
||||
self.uri = self.tags['stream'] = f'{normalizeuri(self.uri)}'
|
||||
logging.info('connected %s', self.uri)
|
||||
self._buffer = []
|
||||
self._deadline = INF
|
||||
self._next_connect = 0
|
||||
|
Reference in New Issue
Block a user