예제 #1
0
    def parse(cls, content):
        message = StringIO(content)
        summary = cls()
        tmp_headers = []
        for line in message:
            if line == '\r\n':
                if tmp_headers:
                    summary.optional_headers.append(tmp_headers)
                    tmp_headers = []
            else:
                field, sep, rest = line.partition(':')
                if not field and not rest:
                    raise ValidationError("incorrect line format")
                field = field.strip()
                rest = rest.strip()

                if field.lower() == "messages-waiting":
                    summary.messages_waiting = Boolean(rest)
                elif field.lower() == "message-account":
                    summary.message_account = rest
                elif field.lower() in set(["voice-message", "fax-message", "pager-message", "multimedia-message", "text-message", "none"]):
                    m = re.match("((\d+)/(\d+))( \((\d+)/(\d+)\))?", rest)
                    if m:
                        summary.summaries[field.lower()] = dict(new_messages=m.groups()[1], old_messages=m.groups()[2], new_urgent_messages=m.groups()[4] or 0, old_urgent_messages=m.groups()[5] or 0)
                    else:
                        raise ValidationError("invalid message context class")
                else:
                    tmp_headers.append(line.strip())
        if tmp_headers:
            summary.optional_headers.append(tmp_headers)
            tmp_headers = []
        return summary
예제 #2
0
 def __init__(self,
              entity,
              state='full',
              version=None,
              conference_description=None,
              host_info=None,
              conference_state=None,
              users=None,
              sidebars_by_ref=None,
              sidebars_by_val=None):
     XMLElement.__init__(self)
     self.entity = entity
     self.state = state
     self.version = version
     self.conference_description = conference_description
     self.host_info = host_info
     self.conference_state = conference_state
     self.users = users
     self.sidebars_by_ref = sidebars_by_ref
     self.sidebars_by_val = sidebars_by_val
     if self.state == "full" and (self.conference_description is None
                                  or self.users is None):
         raise ValidationError(
             "A full conference document must at least include the <conference-description> and <users> child elements."
         )
    def parse(content):
        message = StringIO(content)
        summary = MessageSummary()
        tmp_header = []
        for line in message:
            if line == '\r\n':
                if tmp_header:
                    summary.optional_headers.append(tmp_header)
                    tmp_header = []
                continue
            else:
                field, sep, rest = line.partition(':')
                if not field and not rest:
                    raise ValidationError("incorrect line format")
                field = field.strip()
                rest = rest.strip()

                if field.lower() == "messages-waiting":
                    summary.messages_waiting = BooleanValue(rest)
                    continue
                elif field.lower() == "message-account":
                    summary.message_account = rest
                    continue
                elif field.lower() in MessageSummary.message_context_class:
                    m = re.match("((\d+)\/(\d+))(\ \((\d+)\/(\d+)\))?", rest)
                    if m:
                        s = {}
                        s['new_messages'] = m.groups()[1]
                        s['old_messages'] = m.groups()[2]
                        s['new_urgent_messages'] = m.groups()[4] or 0
                        s['old_urgent_messages'] = m.groups()[5] or 0
                        summary.summaries[field.lower()] = s
                    else:
                        raise ValidationError("invalid message context class")
                    continue
                else:
                    tmp_header.append(line.strip())
        if tmp_header:
            summary.optional_headers.append(tmp_header)
            tmp_header = []
        return summary
예제 #4
0
 def check_validity(self):
     if not self:
         raise ValidationError("cannot have Validity element without any children")
     super(Validity, self).check_validity(self)
예제 #5
0
 def check_validity(self):
     if len(self.element) == 0:
         raise ValidationError(
             "Status objects must have at least one child")
     super(Status, self).check_validity()
예제 #6
0
 def check_validity(self):
     if not self:
         raise ValidationError("Mood element must have at least one value")
예제 #7
0
 def check_validity(self):
     if not self:
         raise ValidationError(
             "Activity element must have at least one value")
     super(Activities, self).check_validity()
예제 #8
0
 def check_validity(self):
     if not self:
         raise ValidationError(
             "cannot have Validity element without any children")
     XMLListElement.check_validity(self)
예제 #9
0
 def _parse_element(self, element, *args, **kwargs):
     try:
         self.sipuri = element.text
     except ValueError, e:
         raise ValidationError("invalid SIPURI in Watcher: %s" % str(e))