Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. import os
  4. from twisted.spread import pb
  5. class Maildir(pb.Referenceable):
  6. def __init__(self, directory, rootDirectory):
  7. self.virtualDirectory = directory
  8. self.rootDirectory = rootDirectory
  9. self.directory = os.path.join(rootDirectory, directory)
  10. def getFolderMessage(self, folder, name):
  11. if "/" in name:
  12. raise OSError("can only open files in '%s' directory'" % folder)
  13. with open(os.path.join(self.directory, "new", name)) as fp:
  14. return fp.read()
  15. def deleteFolderMessage(self, folder, name):
  16. if "/" in name:
  17. raise OSError("can only delete files in '%s' directory'" % folder)
  18. os.rename(
  19. os.path.join(self.directory, folder, name),
  20. os.path.join(self.rootDirectory, ".Trash", folder, name),
  21. )
  22. def deleteNewMessage(self, name):
  23. return self.deleteFolderMessage("new", name)
  24. remote_deleteNewMessage = deleteNewMessage
  25. def deleteCurMessage(self, name):
  26. return self.deleteFolderMessage("cur", name)
  27. remote_deleteCurMessage = deleteCurMessage
  28. def getNewMessages(self):
  29. return os.listdir(os.path.join(self.directory, "new"))
  30. remote_getNewMessages = getNewMessages
  31. def getCurMessages(self):
  32. return os.listdir(os.path.join(self.directory, "cur"))
  33. remote_getCurMessages = getCurMessages
  34. def getNewMessage(self, name):
  35. return self.getFolderMessage("new", name)
  36. remote_getNewMessage = getNewMessage
  37. def getCurMessage(self, name):
  38. return self.getFolderMessage("cur", name)
  39. remote_getCurMessage = getCurMessage
  40. def getSubFolder(self, name):
  41. if name[0] == ".":
  42. raise OSError("subfolder name cannot begin with a '.'")
  43. name = name.replace("/", ":")
  44. if self.virtualDirectoy == ".":
  45. name = "." + name
  46. else:
  47. name = self.virtualDirectory + ":" + name
  48. if not self._isSubFolder(name):
  49. raise OSError("not a subfolder")
  50. return Maildir(name, self.rootDirectory)
  51. remote_getSubFolder = getSubFolder
  52. def _isSubFolder(self, name):
  53. return not os.path.isdir(
  54. os.path.join(self.rootDirectory, name)
  55. ) or not os.path.isfile(os.path.join(self.rootDirectory, name, "maildirfolder"))
  56. class MaildirCollection(pb.Referenceable):
  57. def __init__(self, root):
  58. self.root = root
  59. def getSubFolders(self):
  60. return os.listdir(self.getRoot())
  61. remote_getSubFolders = getSubFolders
  62. def getSubFolder(self, name):
  63. if "/" in name or name[0] == ".":
  64. raise OSError("invalid name")
  65. return Maildir(".", os.path.join(self.getRoot(), name))
  66. remote_getSubFolder = getSubFolder
  67. class MaildirBroker(pb.Broker):
  68. def proto_getCollection(self, requestID, name, domain, password):
  69. collection = self._getCollection()
  70. if collection is None:
  71. self.sendError(requestID, "permission denied")
  72. else:
  73. self.sendAnswer(requestID, collection)
  74. def getCollection(self, name, domain, password):
  75. if domain not in self.domains:
  76. return
  77. domain = self.domains[domain]
  78. if name in domain.dbm and domain.dbm[name] == password:
  79. return MaildirCollection(domain.userDirectory(name))
  80. class MaildirClient(pb.Broker):
  81. def getCollection(self, name, domain, password, callback, errback):
  82. requestID = self.newRequestID()
  83. self.waitingForAnswers[requestID] = callback, errback
  84. self.sendCall("getCollection", requestID, name, domain, password)