chiark / gitweb /
server/gstdecode.c: Label dest element correctly on link failure.
[disorder] / python / disorder.py.in
index 3e1541eaf97104d29ab3bcf46679fd6b4fb17b78..8a758c9bc11a586a631d6dc5f96722ba368cee51 100644 (file)
@@ -50,7 +50,7 @@ import os
 import pwd
 import socket
 import binascii
-import sha
+import hashlib
 import sys
 import locale
 
@@ -66,6 +66,18 @@ _unquoted = re.compile("[^\"' \\t\\n\\r][^ \t\n\r]*")
 
 _response = re.compile("([0-9]{3}) ?(.*)")
 
+# hashes
+_hashes = {
+  "sha1": hashlib.sha1,
+  "SHA1": hashlib.sha1,
+  "sha256": hashlib.sha256,
+  "SHA256": hashlib.sha256,
+  "sha384": hashlib.sha384,
+  "SHA384": hashlib.sha384,
+  "sha512": hashlib.sha512,
+  "SHA512": hashlib.sha512,
+};
+
 version = "_version_"
 
 ########################################################################
@@ -75,6 +87,7 @@ class Error(Exception):
   """Base class for DisOrder exceptions."""
 
 class _splitError(Error):
+  """Error parsing a quoted string list"""
   # _split failed
   def __init__(self, value):
     self.value = value
@@ -387,8 +400,7 @@ class client:
             password = self.config['password']
           else:
             password = self.password
-          # TODO support algorithms other than SHA-1
-          h = sha.sha()
+          h = _hashes[algo]()
           h.update(password)
           h.update(binascii.unhexlify(challenge))
           self._simple("user", user, h.hexdigest())
@@ -428,6 +440,16 @@ class client:
     res, details = self._simple("play", track)
     return unicode(details)             # because it's unicode in queue() output
 
+  def playafter(self, target, tracks):
+    """Insert tracks into a specific point in the queue.
+
+    Arguments:
+    target -- target ID or None to insert at start of queue
+    tracks -- a list of tracks to play"""
+    if target is None:
+      target = ''
+    self._simple("playafter", target, *tracks)
+
   def remove(self, track):
     """Remove a track from the queue.
 
@@ -602,7 +624,7 @@ class client:
     track -- the track to modify
     key -- the preference to remove
     """
-    self._simple("set", track, key, value)
+    self._simple("set", track, key)
 
   def get(self, track, key):
     """Get a preference value.
@@ -822,7 +844,7 @@ class client:
     Arguments:
     key -- the preference to remove
     """
-    self._simple("set-global", key, value)
+    self._simple("set-global", key)
 
   def getglobal(self, key):
     """Get a global preference value.