Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format code with yapf #24

Merged
merged 6 commits into from
May 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions librespot/ZeroconfServer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from __future__ import annotations

import concurrent.futures
import random
import socket

from librespot.common import Utils
from librespot.core import Session
from librespot.crypto import DiffieHellman
from librespot.standard import Closeable, Runnable
from librespot.proto import Connect
import concurrent.futures
import random
import socket
from librespot.standard import Closeable
from librespot.standard import Runnable


class ZeroconfServer(Closeable):
Expand All @@ -16,7 +19,8 @@ class ZeroconfServer(Closeable):
__keys: DiffieHellman
__inner: ZeroconfServer.Inner

def __init__(self, inner: ZeroconfServer.Inner, listen_port: int, listen_all: bool):
def __init__(self, inner: ZeroconfServer.Inner, listen_port: int,
listen_all: bool):
self.__inner = inner
self.__keys = DiffieHellman()

Expand All @@ -39,7 +43,17 @@ def set_listen_port(self, listen_port: int) -> ZeroconfServer.Builder:
return self

def create(self) -> ZeroconfServer:
return ZeroconfServer(ZeroconfServer.Inner(self.device_type, self.device_name, self.preferred_locale, self.conf, self.device_id), self.__listenPort, self.__listenAll)
return ZeroconfServer(
ZeroconfServer.Inner(
self.device_type,
self.device_name,
self.preferred_locale,
self.conf,
self.device_id,
),
self.__listenPort,
self.__listenAll,
)

class Inner:
device_type: Connect.DeviceType = None
Expand All @@ -48,22 +62,25 @@ class Inner:
preferred_locale: str = None
conf = None

def __init__(self,
device_type: Connect.DeviceType,
device_name: str,
preferred_locale: str,
conf: Session.Configuration,
device_id: str = None):
def __init__(
self,
device_type: Connect.DeviceType,
device_name: str,
preferred_locale: str,
conf: Session.Configuration,
device_id: str = None,
):
self.preferred_locale = preferred_locale
self.conf = conf
self.device_type = device_type
self.device_name = device_name
self.device_id = device_id if device_id is not None else Utils.random_hex_string(
40)
self.device_id = (device_id if device_id is not None else
Utils.random_hex_string(40))

class HttpRunner(Runnable, Closeable):
__sock: socket
__executorService: concurrent.futures.ThreadPoolExecutor = concurrent.futures.ThreadPoolExecutor()
__executorService: concurrent.futures.ThreadPoolExecutor = (
concurrent.futures.ThreadPoolExecutor())
__shouldStop: bool = False

def __init__(self, port: int):
Expand All @@ -86,4 +103,3 @@ def __handle(self, client: socket.socket):

def close(self) -> None:
super().close()