[Patchew-devel] [PATCH v2] rest: add api/v1/messages endpoint (POST support)

Paolo Bonzini pbonzini at redhat.com
Wed May 16 08:02:56 UTC 2018


On 16/05/2018 09:53, Fam Zheng wrote:
> On Wed, 05/16 09:38, Paolo Bonzini wrote:
>> On 16/05/2018 03:31, Fam Zheng wrote:
>>> On Tue, 05/15 14:08, Paolo Bonzini wrote:
>>>> On 15/05/2018 14:02, Shubham Jain wrote:
>>>>> +    def create(self, request, *args, **kwargs):
>>>>> +        projects = [p for p in Project.objects.all() if p.recognizes(MboxMessage(self.request.data['mbox']))]
>>>
>>> It is better to create MboxMessage object once to avoid repeating the mbox
>>> parse:
>>>
>>>              m = MboxMessage(self.request.data['mbox'])
>>>              projects = [p for p in Project.objects.all() if p.recognizes(m)]
>>
>> Also the MboxMessage probably should be created from self.request.data,
>> without doing more parsing of the mbox.
> 
> Not sure I understand this, is it related to your below idea? I don't see how
> MboxMessage.__init__ should handle self.request.data.

No, I mean that just like MboxMessage can do text->json, it should be
possible to create a MboxMessage from JSON input.

So you'd have:

- parsing message/rfc822 requests does the text->json conversion (using
MboxMessage, but that's an implementation detail)

- create() does json->MboxMessage and uses the MboxMessage to do
p.recognizes(m)

>> Alternatively, p.recognizes() could take an array of recipients rather
>> than an MboxMessage.
> 
> Yes, but remember there is also the prefix_tags conditions.

You're right, so we do have to go through MboxMessage.

Paolo




More information about the Patchew-devel mailing list