diff --git a/Makefile b/Makefile index 4bd3fc72..340314e8 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -python ?= python2.7 +python ?= python3.8 user ?= $(shell whoami) all: pulseaudio_dlna.egg-info diff --git a/pulseaudio_dlna/__init__.py b/pulseaudio_dlna/__init__.py index 427d5a79..24d4d552 100644 --- a/pulseaudio_dlna/__init__.py +++ b/pulseaudio_dlna/__init__.py @@ -15,12 +15,12 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import os import pkg_resources -import utils.git +from .utils import git try: version = pkg_resources.get_distribution(__package__).version @@ -30,7 +30,7 @@ if os.environ.get('USE_PKG_VERSION', None) == '1': branch, rev = None, None else: - branch, rev = utils.git.get_head_version() + branch, rev = git.get_head_version() __version__ = '{version}{rev}'.format( version=version, diff --git a/pulseaudio_dlna/__main__.py b/pulseaudio_dlna/__main__.py index f49941bf..5c8f17db 100644 --- a/pulseaudio_dlna/__main__.py +++ b/pulseaudio_dlna/__main__.py @@ -116,7 +116,7 @@ ''' -from __future__ import unicode_literals + import sys import os diff --git a/pulseaudio_dlna/application.py b/pulseaudio_dlna/application.py index bca5a10a..c0a625c6 100644 --- a/pulseaudio_dlna/application.py +++ b/pulseaudio_dlna/application.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import multiprocessing import signal @@ -157,11 +157,11 @@ def run(self, options): SSDPDiscover.MSEARCH_PORT = int(msearch_port) if options['--create-device-config']: - self.create_device_config() + self.create_device_config(host=host) sys.exit(0) if options['--update-device-config']: - self.create_device_config(update=True) + self.create_device_config(update=True, host=host) sys.exit(0) device_config = None @@ -213,7 +213,7 @@ def run(self, options): logger.info(' {}'.format(encoder)) logger.info('Codec settings:') - for identifier, _type in pulseaudio_dlna.codecs.CODECS.iteritems(): + for identifier, _type in pulseaudio_dlna.codecs.CODECS.items(): codec = _type() logger.info(' {}'.format(codec)) @@ -291,10 +291,10 @@ def run(self, options): signal.signal(signal.SIGHUP, self.shutdown) signal.pause() - def create_device_config(self, update=False): + def create_device_config(self, update=False, host=None): logger.info('Starting discovery ...') holder = pulseaudio_dlna.holder.Holder(plugins=self.PLUGINS) - holder.search(ttl=5) + holder.search(ttl=20, host=host) logger.info('Discovery complete.') def device_filter(obj): @@ -331,9 +331,9 @@ def obj_to_dict(obj): continue try: with open(config_file, 'w') as h: - h.write(json_text.encode(self.ENCODING)) + h.write(json_text) logger.info('Found the following devices:') - for device in holder.devices.values(): + for device in list(holder.devices.values()): logger.info('{name} ({flavour})'.format( name=device.name, flavour=device.flavour)) for codec in device.codecs: @@ -356,7 +356,7 @@ def read_device_config(self): if os.path.isfile(config_file) and \ os.access(config_file, os.R_OK): with open(config_file, 'r') as h: - json_text = h.read().decode(self.ENCODING) + json_text = h.read() logger.debug('Device configuration:\n{}'.format(json_text)) json_text = json_text.replace('\n', '') try: diff --git a/pulseaudio_dlna/codecs.py b/pulseaudio_dlna/codecs.py index cb671cb5..c6c59d05 100644 --- a/pulseaudio_dlna/codecs.py +++ b/pulseaudio_dlna/codecs.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import functools import logging @@ -67,7 +67,7 @@ def set_backend(backend): def set_codecs(identifiers): step = 3 priority = (len(CODECS) + 1) * step - for identifier, _type in CODECS.iteritems(): + for identifier, _type in CODECS.items(): _type.ENABLED = False _type.PRIORITY = 0 for identifier in identifiers: @@ -81,7 +81,7 @@ def set_codecs(identifiers): def enabled_codecs(): codecs = [] - for identifier, _type in CODECS.iteritems(): + for identifier, _type in CODECS.items(): if _type.ENABLED: codecs.append(_type()) return codecs @@ -168,7 +168,7 @@ def __str__(self, detailed=False): def to_json(self): attributes = ['priority', 'suffix', 'mime_type'] d = { - k: v for k, v in self.__dict__.iteritems() + k: v for k, v in self.__dict__.items() if k not in attributes } d['mime_type'] = self.specific_mime_type diff --git a/pulseaudio_dlna/covermodes.py b/pulseaudio_dlna/covermodes.py index d3dbd905..883935a6 100644 --- a/pulseaudio_dlna/covermodes.py +++ b/pulseaudio_dlna/covermodes.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import sys import inspect diff --git a/pulseaudio_dlna/daemon.py b/pulseaudio_dlna/daemon.py index 3f9e7cda..97608339 100644 --- a/pulseaudio_dlna/daemon.py +++ b/pulseaudio_dlna/daemon.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + from gi.repository import GObject diff --git a/pulseaudio_dlna/encoders/__init__.py b/pulseaudio_dlna/encoders/__init__.py index 667e15fe..619a8677 100644 --- a/pulseaudio_dlna/encoders/__init__.py +++ b/pulseaudio_dlna/encoders/__init__.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import distutils.spawn import inspect @@ -66,10 +66,7 @@ def _find_executable(path): # The distutils module uses python's ascii default encoding and is # therefore not capable of handling unicode properly when it contains # non-ascii characters. - encoding = 'utf-8' - result = distutils.spawn.find_executable(path.encode(encoding)) - if result is not None and type(result) is str: - result = result.decode(encoding) + result = distutils.spawn.find_executable(path) return result @@ -113,7 +110,7 @@ def supported_bit_rates(self): def __str__(self): return '<{} available="{}">'.format( self.__class__.__name__, - unicode(self.available), + str(self.available), ) @@ -139,8 +136,8 @@ def supported_bit_rates(self): def __str__(self): return '<{} available="{}" bit-rate="{}">'.format( self.__class__.__name__, - unicode(self.available), - unicode(self.bit_rate), + str(self.available), + str(self.bit_rate), ) @@ -165,9 +162,9 @@ def channels(self, value): def __str__(self): return '<{} available="{}" sample-rate="{}" channels="{}">'.format( self.__class__.__name__, - unicode(self.available), - unicode(self.sample_rate), - unicode(self.channels), + str(self.available), + str(self.sample_rate), + str(self.channels), ) diff --git a/pulseaudio_dlna/encoders/avconv.py b/pulseaudio_dlna/encoders/avconv.py index 5f09b25a..e5290525 100644 --- a/pulseaudio_dlna/encoders/avconv.py +++ b/pulseaudio_dlna/encoders/avconv.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import logging diff --git a/pulseaudio_dlna/encoders/ffmpeg.py b/pulseaudio_dlna/encoders/ffmpeg.py index c16b2a4b..339aaa53 100644 --- a/pulseaudio_dlna/encoders/ffmpeg.py +++ b/pulseaudio_dlna/encoders/ffmpeg.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import logging diff --git a/pulseaudio_dlna/encoders/generic.py b/pulseaudio_dlna/encoders/generic.py index e68e1267..afa576bb 100644 --- a/pulseaudio_dlna/encoders/generic.py +++ b/pulseaudio_dlna/encoders/generic.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import logging diff --git a/pulseaudio_dlna/holder.py b/pulseaudio_dlna/holder.py index 69e061be..b19297b0 100644 --- a/pulseaudio_dlna/holder.py +++ b/pulseaudio_dlna/holder.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import logging import threading @@ -96,7 +96,7 @@ def lookup(self, locations): 'Connection refused.'.format(url=url)) for plugin in self.plugins: - for url, xml in xmls.items(): + for url, xml in list(xmls.items()): device = plugin.lookup(url, xml) self.add_device(device) diff --git a/pulseaudio_dlna/images.py b/pulseaudio_dlna/images.py index 40a46349..375997ef 100644 --- a/pulseaudio_dlna/images.py +++ b/pulseaudio_dlna/images.py @@ -15,8 +15,8 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals -from __future__ import with_statement + + import tempfile import logging diff --git a/pulseaudio_dlna/notification.py b/pulseaudio_dlna/notification.py index d270c4e7..f99761f2 100644 --- a/pulseaudio_dlna/notification.py +++ b/pulseaudio_dlna/notification.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import logging diff --git a/pulseaudio_dlna/plugins/__init__.py b/pulseaudio_dlna/plugins/__init__.py index 98f2252c..ad27771d 100644 --- a/pulseaudio_dlna/plugins/__init__.py +++ b/pulseaudio_dlna/plugins/__init__.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals import functools diff --git a/pulseaudio_dlna/plugins/chromecast/__init__.py b/pulseaudio_dlna/plugins/chromecast/__init__.py index adf8318d..ff6b47d7 100644 --- a/pulseaudio_dlna/plugins/chromecast/__init__.py +++ b/pulseaudio_dlna/plugins/chromecast/__init__.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals import logging diff --git a/pulseaudio_dlna/plugins/chromecast/mdns.py b/pulseaudio_dlna/plugins/chromecast/mdns.py index 625e3c58..dd4e9c44 100644 --- a/pulseaudio_dlna/plugins/chromecast/mdns.py +++ b/pulseaudio_dlna/plugins/chromecast/mdns.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals from gi.repository import GObject @@ -66,6 +65,7 @@ def run(self, ttl=None): self.__running = True self.__mainloop = GObject.MainLoop() context = self.__mainloop.get_context() + logger.info('MDNSListener.run()') try: while self.__running: if context.pending(): @@ -75,7 +75,6 @@ def run(self, ttl=None): except KeyboardInterrupt: pass self.zeroconf.close() - logger.info('MDNSListener.run()') def shutdown(self): logger.info('MDNSListener.shutdown()') diff --git a/pulseaudio_dlna/plugins/chromecast/pycastv2/__init__.py b/pulseaudio_dlna/plugins/chromecast/pycastv2/__init__.py index cd6fbce4..1941e23c 100644 --- a/pulseaudio_dlna/plugins/chromecast/pycastv2/__init__.py +++ b/pulseaudio_dlna/plugins/chromecast/pycastv2/__init__.py @@ -15,13 +15,13 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import time import logging -import commands -import cast_socket +from . import commands +from . import cast_socket logger = logging.getLogger('pycastv2') diff --git a/pulseaudio_dlna/plugins/chromecast/pycastv2/cast_channel_pb2.py b/pulseaudio_dlna/plugins/chromecast/pycastv2/cast_channel_pb2.py index b9b084de..04638153 100644 --- a/pulseaudio_dlna/plugins/chromecast/pycastv2/cast_channel_pb2.py +++ b/pulseaudio_dlna/plugins/chromecast/pycastv2/cast_channel_pb2.py @@ -13,7 +13,7 @@ DESCRIPTOR = _descriptor.FileDescriptor( name='cast_channel.proto', package='extensions.api.cast_channel', - serialized_pb='\n\x12\x63\x61st_channel.proto\x12\x1b\x65xtensions.api.cast_channel\"\xe3\x02\n\x0b\x43\x61stMessage\x12R\n\x10protocol_version\x18\x01 \x02(\x0e\x32\x38.extensions.api.cast_channel.CastMessage.ProtocolVersion\x12\x11\n\tsource_id\x18\x02 \x02(\t\x12\x16\n\x0e\x64\x65stination_id\x18\x03 \x02(\t\x12\x11\n\tnamespace\x18\x04 \x02(\t\x12J\n\x0cpayload_type\x18\x05 \x02(\x0e\x32\x34.extensions.api.cast_channel.CastMessage.PayloadType\x12\x14\n\x0cpayload_utf8\x18\x06 \x01(\t\x12\x16\n\x0epayload_binary\x18\x07 \x01(\x0c\"!\n\x0fProtocolVersion\x12\x0e\n\nCASTV2_1_0\x10\x00\"%\n\x0bPayloadType\x12\n\n\x06STRING\x10\x00\x12\n\n\x06\x42INARY\x10\x01\"\x0f\n\rAuthChallenge\"B\n\x0c\x41uthResponse\x12\x11\n\tsignature\x18\x01 \x02(\x0c\x12\x1f\n\x17\x63lient_auth_certificate\x18\x02 \x02(\x0c\"~\n\tAuthError\x12\x44\n\nerror_type\x18\x01 \x02(\x0e\x32\x30.extensions.api.cast_channel.AuthError.ErrorType\"+\n\tErrorType\x12\x12\n\x0eINTERNAL_ERROR\x10\x00\x12\n\n\x06NO_TLS\x10\x01\"\xc6\x01\n\x11\x44\x65viceAuthMessage\x12=\n\tchallenge\x18\x01 \x01(\x0b\x32*.extensions.api.cast_channel.AuthChallenge\x12;\n\x08response\x18\x02 \x01(\x0b\x32).extensions.api.cast_channel.AuthResponse\x12\x35\n\x05\x65rror\x18\x03 \x01(\x0b\x32&.extensions.api.cast_channel.AuthErrorB\x02H\x03') + serialized_pb=b'\n\x12\x63\x61st_channel.proto\x12\x1b\x65xtensions.api.cast_channel\"\xe3\x02\n\x0b\x43\x61stMessage\x12R\n\x10protocol_version\x18\x01 \x02(\x0e\x32\x38.extensions.api.cast_channel.CastMessage.ProtocolVersion\x12\x11\n\tsource_id\x18\x02 \x02(\t\x12\x16\n\x0e\x64\x65stination_id\x18\x03 \x02(\t\x12\x11\n\tnamespace\x18\x04 \x02(\t\x12J\n\x0cpayload_type\x18\x05 \x02(\x0e\x32\x34.extensions.api.cast_channel.CastMessage.PayloadType\x12\x14\n\x0cpayload_utf8\x18\x06 \x01(\t\x12\x16\n\x0epayload_binary\x18\x07 \x01(\x0c\"!\n\x0fProtocolVersion\x12\x0e\n\nCASTV2_1_0\x10\x00\"%\n\x0bPayloadType\x12\n\n\x06STRING\x10\x00\x12\n\n\x06\x42INARY\x10\x01\"\x0f\n\rAuthChallenge\"B\n\x0c\x41uthResponse\x12\x11\n\tsignature\x18\x01 \x02(\x0c\x12\x1f\n\x17\x63lient_auth_certificate\x18\x02 \x02(\x0c\"~\n\tAuthError\x12\x44\n\nerror_type\x18\x01 \x02(\x0e\x32\x30.extensions.api.cast_channel.AuthError.ErrorType\"+\n\tErrorType\x12\x12\n\x0eINTERNAL_ERROR\x10\x00\x12\n\n\x06NO_TLS\x10\x01\"\xc6\x01\n\x11\x44\x65viceAuthMessage\x12=\n\tchallenge\x18\x01 \x01(\x0b\x32*.extensions.api.cast_channel.AuthChallenge\x12;\n\x08response\x18\x02 \x01(\x0b\x32).extensions.api.cast_channel.AuthResponse\x12\x35\n\x05\x65rror\x18\x03 \x01(\x0b\x32&.extensions.api.cast_channel.AuthErrorB\x02H\x03') @@ -94,21 +94,21 @@ _descriptor.FieldDescriptor( name='source_id', full_name='extensions.api.cast_channel.CastMessage.source_id', index=1, number=2, type=9, cpp_type=9, label=2, - has_default_value=False, default_value=unicode("", "utf-8"), + has_default_value=False, default_value=b"", message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='destination_id', full_name='extensions.api.cast_channel.CastMessage.destination_id', index=2, number=3, type=9, cpp_type=9, label=2, - has_default_value=False, default_value=unicode("", "utf-8"), + has_default_value=False, default_value=b"", message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='namespace', full_name='extensions.api.cast_channel.CastMessage.namespace', index=3, number=4, type=9, cpp_type=9, label=2, - has_default_value=False, default_value=unicode("", "utf-8"), + has_default_value=False, default_value=b"", message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), @@ -122,7 +122,7 @@ _descriptor.FieldDescriptor( name='payload_utf8', full_name='extensions.api.cast_channel.CastMessage.payload_utf8', index=5, number=6, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=unicode("", "utf-8"), + has_default_value=False, default_value=b"", message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), @@ -290,37 +290,32 @@ DESCRIPTOR.message_types_by_name['AuthError'] = _AUTHERROR DESCRIPTOR.message_types_by_name['DeviceAuthMessage'] = _DEVICEAUTHMESSAGE -class CastMessage(_message.Message): - __metaclass__ = _reflection.GeneratedProtocolMessageType +class CastMessage(_message.Message, metaclass=_reflection.GeneratedProtocolMessageType): DESCRIPTOR = _CASTMESSAGE # @@protoc_insertion_point(class_scope:extensions.api.cast_channel.CastMessage) -class AuthChallenge(_message.Message): - __metaclass__ = _reflection.GeneratedProtocolMessageType +class AuthChallenge(_message.Message, metaclass=_reflection.GeneratedProtocolMessageType): DESCRIPTOR = _AUTHCHALLENGE # @@protoc_insertion_point(class_scope:extensions.api.cast_channel.AuthChallenge) -class AuthResponse(_message.Message): - __metaclass__ = _reflection.GeneratedProtocolMessageType +class AuthResponse(_message.Message, metaclass=_reflection.GeneratedProtocolMessageType): DESCRIPTOR = _AUTHRESPONSE # @@protoc_insertion_point(class_scope:extensions.api.cast_channel.AuthResponse) -class AuthError(_message.Message): - __metaclass__ = _reflection.GeneratedProtocolMessageType +class AuthError(_message.Message, metaclass=_reflection.GeneratedProtocolMessageType): DESCRIPTOR = _AUTHERROR # @@protoc_insertion_point(class_scope:extensions.api.cast_channel.AuthError) -class DeviceAuthMessage(_message.Message): - __metaclass__ = _reflection.GeneratedProtocolMessageType +class DeviceAuthMessage(_message.Message, metaclass=_reflection.GeneratedProtocolMessageType): DESCRIPTOR = _DEVICEAUTHMESSAGE # @@protoc_insertion_point(class_scope:extensions.api.cast_channel.DeviceAuthMessage) DESCRIPTOR.has_options = True -DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), 'H\003') +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), b'H\003') # @@protoc_insertion_point(module_scope) diff --git a/pulseaudio_dlna/plugins/chromecast/pycastv2/cast_socket.py b/pulseaudio_dlna/plugins/chromecast/pycastv2/cast_socket.py index fdcc6cd3..54b52499 100644 --- a/pulseaudio_dlna/plugins/chromecast/pycastv2/cast_socket.py +++ b/pulseaudio_dlna/plugins/chromecast/pycastv2/cast_socket.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import ssl import socket @@ -26,7 +26,7 @@ import traceback import select -import cast_channel_pb2 +from . import cast_channel_pb2 logger = logging.getLogger('pycastv2.cast_socket') @@ -76,7 +76,7 @@ def send(self, data, sender_id, destination_id, namespace=None): def read(self, timeout=10): try: start_time = time.time() - data = str('') + data = b'' while len(data) < 4: if time.time() - start_time > timeout: raise NoResponseException() @@ -85,7 +85,7 @@ def read(self, timeout=10): raise ConnectionTerminatedException() data += part length = struct.unpack('>I', data)[0] - data = str('') + data = b'' while len(data) < length: part = self.sock.recv(2048) data += part diff --git a/pulseaudio_dlna/plugins/chromecast/pycastv2/commands.py b/pulseaudio_dlna/plugins/chromecast/pycastv2/commands.py index e9bc9e43..e7d8ed74 100644 --- a/pulseaudio_dlna/plugins/chromecast/pycastv2/commands.py +++ b/pulseaudio_dlna/plugins/chromecast/pycastv2/commands.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + class BaseCommand(object): diff --git a/pulseaudio_dlna/plugins/chromecast/pycastv2/example.py b/pulseaudio_dlna/plugins/chromecast/pycastv2/example.py index ebb296d3..19ff0c66 100644 --- a/pulseaudio_dlna/plugins/chromecast/pycastv2/example.py +++ b/pulseaudio_dlna/plugins/chromecast/pycastv2/example.py @@ -15,10 +15,10 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import logging -import __init__ as pycastv2 +from . import __init__ as pycastv2 logging.basicConfig(level=logging.DEBUG) diff --git a/pulseaudio_dlna/plugins/chromecast/renderer.py b/pulseaudio_dlna/plugins/chromecast/renderer.py index fc051bbe..2b49de9f 100644 --- a/pulseaudio_dlna/plugins/chromecast/renderer.py +++ b/pulseaudio_dlna/plugins/chromecast/renderer.py @@ -15,16 +15,16 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import requests import logging -import urlparse +import urllib.parse import socket import traceback import lxml -import pycastv2 +from . import pycastv2 import pulseaudio_dlna.plugins.renderer import pulseaudio_dlna.rules import pulseaudio_dlna.codecs @@ -101,8 +101,7 @@ def play(self, url=None, codec=None, artist=None, title=None, thumb=None): traceback.print_exc() return 500, None except (pulseaudio_dlna.plugins.renderer.NoEncoderFoundException, - pulseaudio_dlna.plugins.renderer.NoSuitableHostFoundException)\ - as e: + pulseaudio_dlna.plugins.renderer.NoSuitableHostFoundException) as e: return 500, e except Exception: traceback.print_exc() @@ -180,7 +179,7 @@ def from_url(cls, url): @classmethod def from_xml(cls, url, xml): - url_object = urlparse.urlparse(url) + url_object = urllib.parse.urlparse(url) ip, port = url_object.netloc.split(':') try: xml_root = lxml.etree.fromstring(xml) @@ -202,14 +201,14 @@ def from_xml(cls, url, xml): return None return ChromecastRenderer( - name=unicode(device_friendlyname.text), - ip=unicode(ip), + name=str(device_friendlyname.text), + ip=str(ip), port=None, - udn=unicode(device_udn.text), - model_name=unicode(device_modelname.text), + udn=str(device_udn.text), + model_name=str(device_modelname.text), model_number=None, model_description=None, - manufacturer=unicode(device_manufacturer.text), + manufacturer=str(device_manufacturer.text), ) except: logger.error('No valid XML returned from {url}.'.format(url=url)) @@ -223,24 +222,24 @@ def from_header(cls, header): @classmethod def from_mdns_info(cls, info): - def _bytes2string(bytes): + def _bytes2string(input_bytes): ip = [] - for b in bytes: - subnet = int(b.encode('hex'), 16) + for b in input_bytes: + subnet = str(int(b)) ip.append(str(subnet)) return '.'.join(ip) def _get_device_info(info): try: return { - 'udn': '{}:{}'.format('uuid', info.properties['id']), - 'type': info.properties['md'].decode('utf-8'), - 'name': info.properties['fn'].decode('utf-8'), + 'udn': '{}:{}'.format('uuid', info.properties[b'id']), + 'type': info.properties[b'md'].decode('utf-8'), + 'name': info.properties[b'fn'].decode('utf-8'), 'ip': _bytes2string(info.address), 'port': int(info.port), } - except (KeyError, AttributeError, TypeError): - return None + except (KeyError, AttributeError, TypeError) as e: + raise e device_info = _get_device_info(info) if device_info: diff --git a/pulseaudio_dlna/plugins/dlna/__init__.py b/pulseaudio_dlna/plugins/dlna/__init__.py index fe5ca2d3..5c5b9485 100644 --- a/pulseaudio_dlna/plugins/dlna/__init__.py +++ b/pulseaudio_dlna/plugins/dlna/__init__.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import logging import threading diff --git a/pulseaudio_dlna/plugins/dlna/pyupnpv2/__init__.py b/pulseaudio_dlna/plugins/dlna/pyupnpv2/__init__.py index 6fb0ea0c..4dffb438 100644 --- a/pulseaudio_dlna/plugins/dlna/pyupnpv2/__init__.py +++ b/pulseaudio_dlna/plugins/dlna/pyupnpv2/__init__.py @@ -15,16 +15,16 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import requests -import urlparse +import urllib.parse import logging import collections import lxml import lxml.builder -import byto +from . import byto logger = logging.getLogger('pyupnpv2') @@ -138,16 +138,16 @@ def etree_to_dict(t): if children: dd = defaultdict(list) for dc in map(etree_to_dict, children): - for k, v in dc.items(): + for k, v in list(dc.items()): dd[k].append(v) d = { _tag_name(t): { - k: v[0] if len(v) == 1 else v for k, v in dd.items() + k: v[0] if len(v) == 1 else v for k, v in list(dd.items()) } } if t.attrib: d[_tag_name(t)].update( - ('@' + k, v) for k, v in t.attrib.items() + ('@' + k, v) for k, v in list(t.attrib.items()) ) if t.text: text = t.text.strip() @@ -261,7 +261,7 @@ def _generate_soap_xml( xml_declaration=True, pretty_print=False, encoding='utf-8'): def _add_dict(root, dict_): - for tag, value in dict_.items(): + for tag, value in list(dict_.items()): if isinstance(value, dict): element = lxml.etree.Element(tag) _add_dict(element, value) @@ -386,7 +386,7 @@ def control_url(self): ip=self.ip, port=self.port, ) - return urlparse.urljoin(host, self._control_url) + return urllib.parse.urljoin(host, self._control_url) @property def event_url(self): @@ -394,7 +394,7 @@ def event_url(self): ip=self.ip, port=self.port, ) - return urlparse.urljoin(host, self._event_url) + return urllib.parse.urljoin(host, self._event_url) @property def scpd_url(self): @@ -402,7 +402,7 @@ def scpd_url(self): ip=self.ip, port=self.port, ) - return urlparse.urljoin(host, self._scpd_url) + return urllib.parse.urljoin(host, self._scpd_url) class UpnpAVTransportService(UpnpService): @@ -642,7 +642,7 @@ def from_url(cls, url): def from_xml(cls, url, xml): def process_xml(url, xml_root, xml): - url_object = urlparse.urlparse(url) + url_object = urllib.parse.urlparse(url) ip, port = url_object.netloc.split(':') services = [] for device in xml_root.findall('.//{*}device'): @@ -671,20 +671,20 @@ def process_xml(url, xml_root, xml): upnp_device = UpnpMediaRenderer( description_xml=xml, access_url=url, - ip=unicode(ip), + ip=str(ip), port=port, - name=unicode(device_friendlyname.text), - udn=unicode(device_udn.text), - model_name=unicode( + name=str(device_friendlyname.text), + udn=str(device_udn.text), + model_name=str( device_modelname.text) if ( device_modelname is not None) else None, - model_number=unicode( + model_number=str( device_modelnumber.text) if ( device_modelnumber is not None) else None, - model_description=unicode( + model_description=str( device_modeldescription.text) if ( device_modeldescription is not None) else None, - manufacturer=unicode( + manufacturer=str( device_manufacturer.text) if ( device_manufacturer is not None) else None, services=services, diff --git a/pulseaudio_dlna/plugins/dlna/renderer.py b/pulseaudio_dlna/plugins/dlna/renderer.py index b695e8d5..a674ef3c 100644 --- a/pulseaudio_dlna/plugins/dlna/renderer.py +++ b/pulseaudio_dlna/plugins/dlna/renderer.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import logging import time @@ -27,7 +27,7 @@ import pulseaudio_dlna.codecs import pulseaudio_dlna.rules import pulseaudio_dlna.plugins.renderer -import pyupnpv2 +from . import pyupnpv2 logger = logging.getLogger('pulseaudio_dlna.plugins.dlna.renderer') @@ -123,8 +123,7 @@ def play(self, url=None, codec=None, artist=None, title=None, thumb=None): pyupnpv2.ConnectionErrorException, pyupnpv2.ConnectionTimeoutException, pulseaudio_dlna.plugins.renderer.NoEncoderFoundException, - pulseaudio_dlna.plugins.renderer.NoSuitableHostFoundException)\ - as e: + pulseaudio_dlna.plugins.renderer.NoSuitableHostFoundException) as e: return 500, '"{}" : {}'.format(self.label, str(e)) except Exception: traceback.print_exc() diff --git a/pulseaudio_dlna/plugins/dlna/ssdp/__init__.py b/pulseaudio_dlna/plugins/dlna/ssdp/__init__.py index 5cef4942..6672cfb0 100644 --- a/pulseaudio_dlna/plugins/dlna/ssdp/__init__.py +++ b/pulseaudio_dlna/plugins/dlna/ssdp/__init__.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import re @@ -23,7 +23,7 @@ def _get_header_map(header): header = re.findall(r"(?P.*?):(?P.*?)\n", header) header = { - k.strip().lower(): v.strip() for k, v in dict(header).items() + k.strip().lower(): v.strip() for k, v in list(dict(header).items()) } return header diff --git a/pulseaudio_dlna/plugins/dlna/ssdp/discover.py b/pulseaudio_dlna/plugins/dlna/ssdp/discover.py index 5a52694f..1e727892 100644 --- a/pulseaudio_dlna/plugins/dlna/ssdp/discover.py +++ b/pulseaudio_dlna/plugins/dlna/ssdp/discover.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import socket import logging @@ -117,7 +117,7 @@ def _search(self, host, ssdp_ttl, ssdp_mx, ssdp_amount): def _send_discover(self, sock, ssdp_mx): msg = self.MSEARCH_MSG.format( - host=self.SSDP_ADDRESS, port=self.SSDP_PORT, mx=ssdp_mx) + host=self.SSDP_ADDRESS, port=self.SSDP_PORT, mx=ssdp_mx).encode('utf-8') if self.USE_SINGLE_SOCKET: for addr in self.addresses: sock.setsockopt( diff --git a/pulseaudio_dlna/plugins/dlna/ssdp/listener.py b/pulseaudio_dlna/plugins/dlna/ssdp/listener.py index 7f1663c4..df11ab8a 100644 --- a/pulseaudio_dlna/plugins/dlna/ssdp/listener.py +++ b/pulseaudio_dlna/plugins/dlna/ssdp/listener.py @@ -15,11 +15,11 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + from gi.repository import GObject -import SocketServer +import socketserver import logging import socket import struct @@ -32,7 +32,7 @@ logger = logging.getLogger('pulseaudio_dlna.plugins.dlna.ssdp') -class SSDPHandler(SocketServer.BaseRequestHandler): +class SSDPHandler(socketserver.BaseRequestHandler): SSDP_ALIVE = 'ssdp:alive' SSDP_BYEBYE = 'ssdp:byebye' @@ -70,7 +70,7 @@ def _get_method(self, method_header): return method_header.split(' ')[0] -class SSDPListener(SocketServer.UDPServer): +class SSDPListener(socketserver.UDPServer): SSDP_ADDRESS = '239.255.255.250' SSDP_PORT = 1900 @@ -89,7 +89,7 @@ def run(self, ttl=None): return self.allow_reuse_address = True - SocketServer.UDPServer.__init__( + socketserver.UDPServer.__init__( self, (self.host or '', self.SSDP_PORT), SSDPHandler) self.socket.setsockopt( socket.IPPROTO_IP, @@ -148,5 +148,5 @@ def shutdown(self, *args): class ThreadedSSDPListener( - GobjectMainLoopMixin, SocketServer.ThreadingMixIn, SSDPListener): + GobjectMainLoopMixin, socketserver.ThreadingMixIn, SSDPListener): pass diff --git a/pulseaudio_dlna/plugins/renderer.py b/pulseaudio_dlna/plugins/renderer.py index 3cb17cee..a1ef371f 100644 --- a/pulseaudio_dlna/plugins/renderer.py +++ b/pulseaudio_dlna/plugins/renderer.py @@ -15,12 +15,12 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import re import random -import urlparse -import urllib +import urllib.parse +import urllib.request, urllib.parse, urllib.error import functools import logging import base64 @@ -189,7 +189,7 @@ def codec(self): missing_encoders = [] for codec in self.codecs: - for identifier, encoder_type in codec.ENCODERS.items(): + for identifier, encoder_type in list(codec.ENCODERS.items()): encoder = encoder_type() if encoder.binary not in missing_encoders: missing_encoders.append(encoder.binary) @@ -257,7 +257,7 @@ def stop(self): raise NotImplementedError() def add_mime_type(self, mime_type): - for identifier, _type in pulseaudio_dlna.codecs.CODECS.iteritems(): + for identifier, _type in pulseaudio_dlna.codecs.CODECS.items(): if _type.accepts(mime_type): codec = _type(mime_type) if codec not in self.codecs: @@ -312,7 +312,7 @@ def set_rules_from_config(self, config): codec_type = pulseaudio_dlna.codecs.CODECS[ codec_properties['identifier']] codec = codec_type(codec_properties['mime_type']) - for k, v in codec_properties.iteritems(): + for k, v in codec_properties.items(): forbidden_attributes = ['mime_type', 'identifier', 'rules'] if hasattr(codec, k) and k not in forbidden_attributes: setattr(codec, k, v) @@ -338,12 +338,12 @@ def _encode_settings(self, settings, suffix=''): port=server_port, ) data_string = ','.join( - ['{}="{}"'.format(k, v) for k, v in settings.iteritems()]) + ['{}="{}"'.format(k, v) for k, v in settings.items()]) stream_name = '/{base_string}/{suffix}'.format( - base_string=urllib.quote(base64.b64encode(data_string)), + base_string=urllib.parse.quote(base64.b64encode(data_string.encode('utf-8'))), suffix=suffix, ) - return urlparse.urljoin(base_url, stream_name) + return urllib.parse.urljoin(base_url, stream_name) def get_stream_url(self): settings = { diff --git a/pulseaudio_dlna/pulseaudio.py b/pulseaudio_dlna/pulseaudio.py index 5f3752c0..302b4b4a 100644 --- a/pulseaudio_dlna/pulseaudio.py +++ b/pulseaudio_dlna/pulseaudio.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + from gi.repository import GObject @@ -227,7 +227,7 @@ def dbus_server_lookup(self): 'org.PulseAudio.ServerLookup1', 'Address', dbus_interface='org.freedesktop.DBus.Properties') - return unicode(address) + return str(address) except dbus.exceptions.DBusException: return None @@ -237,14 +237,14 @@ def get_modules(self): stdout=subprocess.PIPE) stdout, stderr = process.communicate() if process.returncode == 0: - matches = re.findall(r'(\d+)\s+([\w-]+)(.*?)\n', stdout) + matches = re.findall(r'(\d+)\s+([\w-]+)(.*?)\n', stdout.decode('utf-8')) return [match[1] for match in matches] return None def load_module(self, module_name, options=None): command = ['pactl', 'load-module', module_name] if options: - for key, value in options.items(): + for key, value in list(options.items()): command.append('{}={}'.format(key, value)) process = subprocess.Popen(command, stdout=subprocess.PIPE) stdout, stderr = process.communicate() @@ -299,8 +299,8 @@ def new(self, bus, client_path): icon_bytes = properties.get('application.icon_name', []) binary_bytes = properties.get('application.process.binary', []) return PulseClient( - object_path=unicode(client_path), - index=unicode(obj.Get('org.PulseAudio.Core1.Client', 'Index')), + object_path=str(client_path), + index=str(obj.Get('org.PulseAudio.Core1.Client', 'Index')), name=self._convert_bytes_to_unicode(name_bytes), icon=self._convert_bytes_to_unicode(icon_bytes), binary=self._convert_bytes_to_unicode(binary_bytes), @@ -352,9 +352,9 @@ def new(self, bus, module_path): try: obj = bus.get_object(object_path=module_path) return PulseModule( - object_path=unicode(module_path), - index=unicode(obj.Get('org.PulseAudio.Core1.Module', 'Index')), - name=unicode(obj.Get('org.PulseAudio.Core1.Module', 'Name')), + object_path=str(module_path), + index=str(obj.Get('org.PulseAudio.Core1.Module', 'Index')), + name=str(obj.Get('org.PulseAudio.Core1.Module', 'Name')), ) except dbus.exceptions.DBusException: logger.error( @@ -400,13 +400,13 @@ def new(self, bus, object_path): properties = obj.Get('org.PulseAudio.Core1.Device', 'PropertyList') description_bytes = properties.get('device.description', []) - module_path = unicode( + module_path = str( obj.Get('org.PulseAudio.Core1.Device', 'OwnerModule')) return PulseSink( - object_path=unicode(object_path), - index=unicode(obj.Get('org.PulseAudio.Core1.Device', 'Index')), - name=unicode(obj.Get('org.PulseAudio.Core1.Device', 'Name')), + object_path=str(object_path), + index=str(obj.Get('org.PulseAudio.Core1.Device', 'Index')), + name=str(obj.Get('org.PulseAudio.Core1.Device', 'Name')), label=self._convert_bytes_to_unicode(description_bytes), module=PulseModuleFactory.new(bus, module_path), ) @@ -498,13 +498,13 @@ class PulseStreamFactory(object): def new(self, bus, stream_path): try: obj = bus.get_object(object_path=stream_path) - client_path = unicode( + client_path = str( obj.Get('org.PulseAudio.Core1.Stream', 'Client')) return PulseStream( - object_path=unicode(stream_path), - index=unicode(obj.Get( + object_path=str(stream_path), + index=str(obj.Get( 'org.PulseAudio.Core1.Stream', 'Index')), - device=unicode(obj.Get( + device=str(obj.Get( 'org.PulseAudio.Core1.Stream', 'Device')), client=PulseClientFactory.new(bus, client_path), ) diff --git a/pulseaudio_dlna/recorders.py b/pulseaudio_dlna/recorders.py index fb3270a2..99f85e43 100644 --- a/pulseaudio_dlna/recorders.py +++ b/pulseaudio_dlna/recorders.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import pulseaudio_dlna.codecs diff --git a/pulseaudio_dlna/rules.py b/pulseaudio_dlna/rules.py index 31690d87..a68f7f8a 100644 --- a/pulseaudio_dlna/rules.py +++ b/pulseaudio_dlna/rules.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import functools import logging @@ -44,7 +44,7 @@ def __eq__(self, other): if type(other) is type: return type(self) is other try: - if isinstance(other, basestring): + if isinstance(other, str): return type(self) is RULES[other] except: raise RuleNotFoundException(other) @@ -54,7 +54,7 @@ def __gt__(self, other): if type(other) is type: return type(self) > other try: - if isinstance(other, basestring): + if isinstance(other, str): return type(self) > RULES[other] except: raise RuleNotFoundException() @@ -63,7 +63,7 @@ def __gt__(self, other): def to_json(self): attributes = [] d = { - k: v for k, v in self.__dict__.iteritems() + k: v for k, v in self.__dict__.items() if k not in attributes } d['name'] = str(self) @@ -122,11 +122,11 @@ def append(self, *args): except KeyError: raise RuleNotFoundException(name) attributes = ['name'] - for k, v in arg.iteritems(): + for k, v in arg.items(): if hasattr(rule, k) and k not in attributes: setattr(rule, k, v) self._add_rule(rule) - elif isinstance(arg, basestring): + elif isinstance(arg, str): try: rule = RULES[arg]() self._add_rule(rule) diff --git a/pulseaudio_dlna/streamserver.py b/pulseaudio_dlna/streamserver.py index fd42ac66..1e8bab1a 100644 --- a/pulseaudio_dlna/streamserver.py +++ b/pulseaudio_dlna/streamserver.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + from gi.repository import GObject @@ -27,14 +27,14 @@ import select import sys import base64 -import urllib +import urllib.request, urllib.parse, urllib.error import json import os import signal import pkg_resources -import BaseHTTPServer -import SocketServer -import Queue +import http.server +import socketserver +import queue import threading import pulseaudio_dlna.encoders @@ -49,7 +49,7 @@ PROTOCOL_VERSION_V11 = 'HTTP/1.1' -class ProcessQueue(Queue.Queue): +class ProcessQueue(queue.Queue): def data(self): data = self.get() @@ -266,28 +266,28 @@ def __str__(self): '\n'.join( [' {}\n {}'.format( path, - ' '.join([str(s) for id, s in streams.items()])) - for path, streams in self.streams.items()], + ' '.join([str(s) for id, s in list(streams.items())])) + for path, streams in list(self.streams.items())], ), ) -class StreamRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): +class StreamRequestHandler(http.server.BaseHTTPRequestHandler): def __init__(self, *args): try: - BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args) + http.server.BaseHTTPRequestHandler.__init__(self, *args) except IOError: pass def do_HEAD(self): logger.debug('Got the following HEAD request:\n{header}'.format( - header=json.dumps(self.headers.items(), indent=2))) + header=json.dumps(list(self.headers.items()), indent=2))) item = self.get_requested_item() self.handle_headers(item) def do_GET(self): logger.debug('Got the following GET request:\n{header}'.format( - header=json.dumps(self.headers.items(), indent=2))) + header=json.dumps(list(self.headers.items()), indent=2))) item = self.get_requested_item() self.handle_headers(item) if isinstance(item, pulseaudio_dlna.images.BaseImage): @@ -344,7 +344,7 @@ def handle_headers(self, item): header=json.dumps(headers, indent=2), )) self.send_response(response_code) - for name, value in headers.items(): + for name, value in list(headers.items()): self.send_header(name, value) self.end_headers() @@ -385,7 +385,7 @@ def get_requested_item(self): def _decode_settings(self, path): try: data_quoted = re.findall(r'/(.*?)/', path)[0] - data_string = base64.b64decode(urllib.unquote(data_quoted)) + data_string = base64.b64decode(urllib.parse.unquote(data_quoted)).decode('utf-8') settings = { k: v for k, v in re.findall('(.*?)="(.*?)",?', data_string) } @@ -394,15 +394,15 @@ def _decode_settings(self, path): path=path, data_string=data_string)) return settings - except (TypeError, ValueError, IndexError): - pass + except (TypeError, ValueError, IndexError) as e: + raise e return {} def log_message(self, format, *args): pass -class StreamServer(SocketServer.TCPServer): +class StreamServer(socketserver.TCPServer): HOST = None PORT = None @@ -423,7 +423,7 @@ def run(self): self.allow_reuse_address = True self.daemon_threads = True try: - SocketServer.TCPServer.__init__( + socketserver.TCPServer.__init__( self, (self.ip or '', self.port), StreamRequestHandler) except socket.error: logger.critical( @@ -486,5 +486,5 @@ def shutdown(self, *args): class ThreadedStreamServer( - GobjectMainLoopMixin, SocketServer.ThreadingMixIn, StreamServer): + GobjectMainLoopMixin, socketserver.ThreadingMixIn, StreamServer): pass diff --git a/pulseaudio_dlna/utils/encoding.py b/pulseaudio_dlna/utils/encoding.py index 86b14adb..12c5e749 100644 --- a/pulseaudio_dlna/utils/encoding.py +++ b/pulseaudio_dlna/utils/encoding.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import logging import sys @@ -34,10 +34,10 @@ def __init__(self, var): ) -def decode_default(bytes): - if type(bytes) is not str: - raise NotBytesException(bytes) - guess = chardet.detect(bytes) +def decode_default(input_bytes): + if type(input_bytes) is not bytes: + raise NotBytesException(input_bytes) + guess = chardet.detect(input_bytes) encodings = { 'sys.stdout.encoding': sys.stdout.encoding, 'locale.getpreferredencoding': locale.getpreferredencoding(), @@ -45,19 +45,19 @@ def decode_default(bytes): 'utf-8': 'utf-8', 'latin1': 'latin1', } - for encoding in encodings.values(): + for encoding in list(encodings.values()): if encoding and encoding != 'ascii': try: - return bytes.decode(encoding) + return input_bytes.decode(encoding) except UnicodeDecodeError: continue try: - return bytes.decode('ascii', errors='replace') + return input_bytes.decode('ascii', errors='replace') except UnicodeDecodeError: logger.error( 'Decoding failed using the following encodings: "{}"'.format( ','.join( - ['{}:{}'.format(f, e) for f, e in encodings.items()] + ['{}:{}'.format(f, e) for f, e in list(encodings.items())] ))) return 'Unknown' diff --git a/pulseaudio_dlna/utils/git.py b/pulseaudio_dlna/utils/git.py index b2e911fe..7210b2dc 100644 --- a/pulseaudio_dlna/utils/git.py +++ b/pulseaudio_dlna/utils/git.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import os diff --git a/pulseaudio_dlna/utils/network.py b/pulseaudio_dlna/utils/network.py index 47fbbee6..b1295af8 100644 --- a/pulseaudio_dlna/utils/network.py +++ b/pulseaudio_dlna/utils/network.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import netifaces import traceback diff --git a/pulseaudio_dlna/utils/psutil.py b/pulseaudio_dlna/utils/psutil.py index 011e9766..b61abb21 100644 --- a/pulseaudio_dlna/utils/psutil.py +++ b/pulseaudio_dlna/utils/psutil.py @@ -15,8 +15,8 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import absolute_import -from __future__ import unicode_literals + + import logging import psutil diff --git a/pulseaudio_dlna/utils/subprocess.py b/pulseaudio_dlna/utils/subprocess.py index 20091632..ed74f1d9 100644 --- a/pulseaudio_dlna/utils/subprocess.py +++ b/pulseaudio_dlna/utils/subprocess.py @@ -15,8 +15,8 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import absolute_import -from __future__ import unicode_literals + + from gi.repository import GObject diff --git a/pulseaudio_dlna/workarounds.py b/pulseaudio_dlna/workarounds.py index c82b3bcd..d47a7b66 100644 --- a/pulseaudio_dlna/workarounds.py +++ b/pulseaudio_dlna/workarounds.py @@ -15,12 +15,12 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import logging from lxml import etree import requests -import urlparse +import urllib.parse import traceback @@ -170,7 +170,7 @@ def _parse_xml(self, xml): control_url = xml_root.find(self.MR_YAMAHA_CONTROLURL_PATH, namespaces) if ((url_base is None) or (control_url is None)): return False - ip, port = urlparse.urlparse(url_base.text).netloc.split(':') + ip, port = urllib.parse.urlparse(url_base.text).netloc.split(':') if ((not ip) or (not port)): return False diff --git a/scripts/chromecast-beam.py b/scripts/chromecast-beam.py index 5b594f37..265e2530 100755 --- a/scripts/chromecast-beam.py +++ b/scripts/chromecast-beam.py @@ -110,7 +110,7 @@ ''' -from __future__ import unicode_literals + import docopt import logging @@ -125,8 +125,8 @@ import shutil import traceback import re -import SimpleHTTPServer -import SocketServer +import http.server +import socketserver import pulseaudio_dlna.utils.network import pulseaudio_dlna.plugins.chromecast.pycastv2 as pycastv2 @@ -193,7 +193,7 @@ def stop(host, port, timeout=5): stop(self.chromecast_host, self.PORT) -class ThreadedHTTPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): +class ThreadedHTTPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): allow_reuse_address = True daemon_threads = True @@ -207,7 +207,7 @@ def __init__(self, file_uri, bind_host, request_host, port, handler=None): self.handler = handler or DefaultRequestHandler os.chdir(self.file_path) - SocketServer.TCPServer.__init__( + socketserver.TCPServer.__init__( self, (self.bind_host, self.port), self.handler) @property @@ -270,7 +270,7 @@ def _apply_option(cls, attribute, value): @classmethod def _apply_options(cls, options, option_map): - for option, value in cls._decode_settings(options).items(): + for option, value in list(cls._decode_settings(options).items()): attribute = option_map.get(option, None) cls._apply_option(attribute, value) @@ -381,7 +381,7 @@ def _transcode_cmd_str(cls): if cls.SUB_TITLES: options['soverlay'] = None return ','.join([ - '{}={}'.format(k, v) if v else k for k, v in options.items() + '{}={}'.format(k, v) if v else k for k, v in list(options.items()) ]) @classmethod @@ -410,18 +410,18 @@ def command(cls, file_path): ] -class DefaultRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): +class DefaultRequestHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self, *args, **kwargs): logger.info('Serving unmodified media file to {} ...'.format( self.client_address[0])) - SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self, *args, **kwargs) + http.server.SimpleHTTPRequestHandler.do_GET(self, *args, **kwargs) def log_request(self, code='-', size='-'): logger.info('{} - {}'.format(self.requestline, code)) -class TranscodeRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): +class TranscodeRequestHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): client_address = self.client_address[0] diff --git a/scripts/fritzbox-device-sharing.py b/scripts/fritzbox-device-sharing.py index a6cd6cd5..6dd96bf0 100755 --- a/scripts/fritzbox-device-sharing.py +++ b/scripts/fritzbox-device-sharing.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import requests import sys @@ -94,7 +94,7 @@ def discover_devices(self): def _discover_devices(self): holder = pulseaudio_dlna.holder.Holder(self.PLUGINS) holder.search(ttl=self.TIMEOUT) - return holder.devices.values() + return list(holder.devices.values()) ip_detector = IPDetector() @@ -113,5 +113,5 @@ def _discover_devices(self): for device in dlna_discover.devices: link = device.upnp_device.access_url.replace( device.ip, ip_detector.public_ip) - print(SHARE_PATTERN.format( - name=device.name, ip=device.ip, port=device.port, link=link)) + print((SHARE_PATTERN.format( + name=device.name, ip=device.ip, port=device.port, link=link))) diff --git a/scripts/radio.py b/scripts/radio.py index 2483e073..bc3c9829 100755 --- a/scripts/radio.py +++ b/scripts/radio.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with pulseaudio-dlna. If not, see . -from __future__ import unicode_literals + import requests import logging @@ -101,7 +101,7 @@ def _get_device(self, name, flavour=None): return None def _get_codec(self, url): - for identifier, _type in pulseaudio_dlna.codecs.CODECS.iteritems(): + for identifier, _type in pulseaudio_dlna.codecs.CODECS.items(): codec = _type() if url.endswith(codec.suffix): return codec @@ -118,10 +118,10 @@ def _discover_devices(self): holder = pulseaudio_dlna.holder.Holder(self.PLUGINS) holder.search(ttl=5) logger.info('Found the following devices:') - for udn, device in holder.devices.items(): + for udn, device in list(holder.devices.items()): logger.info(' - "{name}" ({flavour})'.format( name=device.name, flavour=device.flavour)) - return holder.devices.values() + return list(holder.devices.values()) # Local pulseaudio-dlna installations running in a virutalenv should run this # script as module: