calendar.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # -*- coding: utf-8; indent-tabs-mode: nil; -*-
  2. #
  3. # This file is part of Radicale Server - Calendar Server
  4. # Copyright © 2008 The Radicale Team
  5. #
  6. # This library is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  18. # TODO: Manage inheritance for classes
  19. from time import time
  20. import support
  21. class Calendar(object):
  22. """
  23. Internal Calendar Class
  24. """
  25. def __init__(self, user, cal):
  26. # TODO: Use properties from the calendar
  27. self.encoding = "utf-8"
  28. self.owner = "lize"
  29. self.user = user
  30. self.cal = cal
  31. self.version = "2.0"
  32. self.ctag = str(hash(self.vcalendar()))
  33. def append(self, vcalendar):
  34. """
  35. Append vcalendar
  36. """
  37. self.ctag = str(hash(self.vcalendar()))
  38. support.append(self.cal, vcalendar)
  39. def remove(self, uid):
  40. """
  41. Remove Object Named uid
  42. """
  43. self.ctag = str(hash(self.vcalendar()))
  44. support.remove(self.cal, uid)
  45. def replace(self, uid, vcalendar):
  46. """
  47. Replace Objet Named uid by vcalendar
  48. """
  49. self.ctag = str(hash(self.vcalendar()))
  50. support.remove(self.cal, uid)
  51. support.append(self.cal, vcalendar)
  52. def vcalendar(self):
  53. return unicode(support.read(self.cal), self.encoding)
  54. class Event(object):
  55. """
  56. Internal Event Class
  57. """
  58. # TODO: Fix the behaviour if no UID is given
  59. def __init__(self, vcalendar):
  60. self.text = vcalendar
  61. def etag(self):
  62. return str(hash(self.text))
  63. class Header(object):
  64. """
  65. Internal Headers Class
  66. """
  67. def __init__(self, vcalendar):
  68. self.text = vcalendar
  69. class Timezone(object):
  70. """
  71. Internal Timezone Class
  72. """
  73. def __init__(self, vcalendar):
  74. lines = vcalendar.splitlines()
  75. for line in lines:
  76. if line.startswith("TZID:"):
  77. self.tzid = line.lstrip("TZID:")
  78. break
  79. self.text = vcalendar
  80. class Todo(object):
  81. """
  82. Internal Todo Class
  83. """
  84. # TODO: Fix the behaviour if no UID is given
  85. def __init__(self, vcalendar):
  86. self.text = vcalendar
  87. def etag(self):
  88. return str(hash(self.text))