A Python UPnP Media Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.6 KiB

  1. #!/usr/bin/env python
  2. from twisted.internet import reactor
  3. # Make sure to update the global line when adding a new function
  4. __all__ = [ 'appendnamespace', 'insertnamespace', 'insertringbuf' ]
  5. DEFAULTRINGSIZE = 50
  6. appendnamespace = lambda k, v: []
  7. insertnamespace = lambda k, v: None
  8. insertringbuf = lambda k, l = DEFAULTRINGSIZE: None
  9. # This code from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68429
  10. class RingBuffer:
  11. def __init__(self,size_max):
  12. self.max = size_max
  13. self.data = []
  14. def append(self,x):
  15. """append an element at the end of the buffer"""
  16. self.data.append(x)
  17. if len(self.data) == self.max:
  18. self.cur=0
  19. self.__class__ = RingBufferFull
  20. def get(self):
  21. """ return a list of elements from the oldest to the newest"""
  22. return self.data
  23. class RingBufferFull:
  24. def __init__(self,n):
  25. raise "you should use RingBuffer"
  26. def append(self,x):
  27. self.data[self.cur]=x
  28. self.cur=(self.cur+1) % self.max
  29. def get(self):
  30. return self.data[self.cur:]+self.data[:self.cur]
  31. def doDebugging(opt):
  32. if not opt:
  33. return
  34. global insertnamespace, appendnamespace, insertringbuf
  35. def insertnamespace(k, v):
  36. assert isinstance(k, basestring)
  37. sf.namespace[k] = v
  38. def appendnamespace(k, v):
  39. try:
  40. sf.namespace[k].append(v)
  41. except KeyError:
  42. sf.namespace[k] = [ v ]
  43. def insertringbuf(k, l = DEFAULTRINGSIZE):
  44. insertnamespace(k, RingBuffer(l))
  45. from twisted.manhole import telnet
  46. class Debug(telnet.Shell):
  47. def welcomeMessage(self):
  48. data = [ '', 'PyMedS Debugging Console', '', '' ]
  49. return '\r\n'.join(data)
  50. sf = telnet.ShellFactory()
  51. sf.protocol = Debug
  52. reactor.listenTCP(56283, sf)