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.

71 lines
1.7 KiB

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