Skip to content
This repository was archived by the owner on Nov 2, 2020. It is now read-only.
Open
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
18 changes: 11 additions & 7 deletions lcdproc/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from __future__ import print_function
import telnetlib
import urllib
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote
import select

from screen import Screen
Expand Down Expand Up @@ -43,9 +47,9 @@ def request(self, command_string):
""" Request """

self.tn.write((command_string + "\n").encode())
if self.debug: print "Telnet Request: %s" % (command_string)
if self.debug: print("Telnet Request:", command_string)
while True:
response = urllib.unquote(self.tn.read_until(b"\n").decode())
response = unquote(self.tn.read_until(b"\n").decode())
if "success" in response: # Normal successful reply
break
if "huh" in response: # Something went wrong
Expand All @@ -54,7 +58,7 @@ def request(self, command_string):
break
# TODO Keep track of which screen is displayed
# Try again if response was key, menu or visibility notification.
if "huh" in response or self.debug: print "Telnet Response: %s" % (response[:-1])
if "huh" in response or self.debug: print("Telnet Response:", response[:-1])
return response


Expand All @@ -66,8 +70,8 @@ def poll(self):
LCDd generates strings for key presses, menu events & screen visibility changes.
"""
if select.select([self.tn], [], [], 0) == ([self.tn], [], []):
response = urllib.unquote(self.tn.read_until(b"\n").decode())
if self.debug: print "Telnet Poll: %s" % (response[:-1])
response = unquote(self.tn.read_until(b"\n").decode())
if self.debug: print("Telnet Poll:", response[:-1])
# TODO Keep track of which screen is displayed
return response
else:
Expand Down Expand Up @@ -99,7 +103,7 @@ def add_key(self, ref, mode = "shared"):
Return key name or None on error
"""
if ref not in self.keys:
response = self.request("client_add_key %s -%s" % (ref, mode))
response = self.request("client_add_key -%s %s" % (mode, ref))
if "success" not in response: return None
self.keys.append(ref)
return ref
Expand Down