Esempio n. 1
0
 def demarshall(self, instance, data, **kwargs):
     # We don't want to pass file forward.
     if 'file' in kwargs:
         if not data:
             # TODO Yuck! Shouldn't read the whole file, never.
             # OTOH, if you care about large files, you should be
             # using the PrimaryFieldMarshaller or something
             # similar.
             data = kwargs['file'].read()
         del kwargs['file']
     headers, body = parseRFC822(data)
     
     query = {}
     for k, v in headers.items():
         if not k.startswith("query"):
             continue
         else:
             index = int(k[5])
             sub_key = k.split("_")[1]
             query_part = query.get(index, {})
             query_part[sub_key] = v
             query[index] = query_part
             del headers[k]
     query = [facet[1] for facet in sorted(query.items())]
     
     header = formatRFC822Headers(headers.items())
     data = '%s\n\n%s' % (header, body)
     
     try:
         return RFC822Marshaller.demarshall(self, instance, data, **kwargs)
     finally:
         instance.query = query
Esempio n. 2
0
    def demarshall(self, instance, data, **kwargs):
        # We don't want to pass file forward.
        if 'file' in kwargs:
            if not data:
                # TODO Yuck! Shouldn't read the whole file, never.
                # OTOH, if you care about large files, you should be
                # using the PrimaryFieldMarshaller or something
                # similar.
                data = kwargs['file'].read()
            del kwargs['file']
        headers, body = parseRFC822(data)

        query = {}
        for k, v in headers.items():
            if not k.startswith("query"):
                continue
            else:
                index = int(k[5])
                sub_key = k.split("_")[1]
                query_part = query.get(index, {})
                query_part[sub_key] = v
                query[index] = query_part
                del headers[k]
        query = [facet[1] for facet in sorted(query.items())]

        header = formatRFC822Headers(headers.items())
        data = '%s\n\n%s' % (header, body)

        try:
            return RFC822Marshaller.demarshall(self, instance, data, **kwargs)
        finally:
            instance.query = query