1.1 --- a/MoinShare.py Fri Jun 14 18:01:52 2013 +0200
1.2 +++ b/MoinShare.py Sat Jun 15 00:45:10 2013 +0200
1.3 @@ -115,6 +115,13 @@
1.4
1.5 self.page = None
1.6
1.7 + # Identification.
1.8 +
1.9 + self.path = []
1.10 +
1.11 + def unique_id(self):
1.12 + return "moinshare-tab-%s-%s" % (self.message_number, "-".join(map(str, self.path)))
1.13 +
1.14 def __cmp__(self, other):
1.15 if self.updated is None and other.updated is not None:
1.16 return 1
1.17 @@ -123,6 +130,20 @@
1.18 else:
1.19 return cmp(self.updated, other.updated)
1.20
1.21 + def copy(self, part_number=None):
1.22 + update = Update()
1.23 + update.title = self.title
1.24 + update.link = self.link
1.25 + update.updated = self.updated
1.26 + update.fragment = self.fragment
1.27 + update.preferred = self.preferred
1.28 + update.message_number = self.message_number
1.29 + update.page = self.page
1.30 + update.path = self.path[:]
1.31 + if part_number is not None:
1.32 + update.path.append(part_number)
1.33 + return update
1.34 +
1.35 # Update retrieval from pages.
1.36
1.37 def getUpdatesFromPage(page, request):
1.38 @@ -217,36 +238,56 @@
1.39 update.page = page
1.40 update.message_number = n
1.41
1.42 - # Determine whether the message has several representations.
1.43 -
1.44 - # For a single part, use it as the update content.
1.45 -
1.46 - if not message.is_multipart():
1.47 - charset = message.get_content_charset()
1.48 - payload = message.get_payload(decode=True)
1.49 - update.content = charset and unicode(payload, charset) or payload
1.50 - update.content_type = message.get_content_type()
1.51 -
1.52 - # For a collection of related parts, use the first as the update content
1.53 - # and assume that the formatter will reference the other parts.
1.54 -
1.55 - elif message.get_content_subtype() == "related":
1.56 - main_part = message.get_payload()[0]
1.57 - charset = main_part.get_content_charset()
1.58 - payload = main_part.get_payload(decode=True)
1.59 - update.content = charset and unicode(payload, charset) or payload
1.60 - update.content_type = main_part.get_content_type()
1.61 -
1.62 - # Otherwise, just obtain the parts for separate display.
1.63 -
1.64 - else:
1.65 - update.parts = message.get_payload()
1.66 - update.content_type = message.get_content_type()
1.67 + update.content, update.content_type, update.parts = getUpdateContentFromPart(message)
1.68
1.69 updates.append(update)
1.70
1.71 return updates
1.72
1.73 +def getUpdateContentFromPart(part):
1.74 +
1.75 + """
1.76 + Return decoded content, the content type and any subparts in a tuple for a
1.77 + given 'part'.
1.78 + """
1.79 +
1.80 + # Determine whether the part has several representations.
1.81 +
1.82 + # For a single part, use it as the update content.
1.83 +
1.84 + if not part.is_multipart():
1.85 + content, content_type = getPartContent(part)
1.86 + return content, content_type, None
1.87 +
1.88 + # For a collection of related parts, use the first as the update content
1.89 + # and assume that the formatter will reference the other parts.
1.90 +
1.91 + elif part.get_content_subtype() == "related":
1.92 + main_part = part.get_payload()[0]
1.93 + content, content_type = getPartContent(main_part)
1.94 + return content, content_type, [main_part]
1.95 +
1.96 + # Otherwise, just obtain the parts for separate display.
1.97 +
1.98 + else:
1.99 + return None, part.get_content_type(), part.get_payload()
1.100 +
1.101 +def getPartContent(part):
1.102 +
1.103 + "Decode the 'part', returning the decoded payload and the content type."
1.104 +
1.105 + charset = part.get_content_charset()
1.106 + payload = part.get_payload(decode=True)
1.107 + return (charset and unicode(payload, charset) or payload), part.get_content_type()
1.108 +
1.109 +def getUpdateFromPart(parent, part, part_number):
1.110 +
1.111 + "Using the 'parent' update, return an update object for the given 'part'."
1.112 +
1.113 + update = parent.copy(part_number)
1.114 + update.content, update.content_type, update.parts = getUpdateContentFromPart(part)
1.115 + return update
1.116 +
1.117 # Source management.
1.118
1.119 def getUpdateSources(pagename, request):