From nobody Mon Sep 16 19:26:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525780298253749.6641127740825; Tue, 8 May 2018 04:51:38 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 607C830001DA; Tue, 8 May 2018 11:51:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 50E90100195A; Tue, 8 May 2018 11:51:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 43FE84CA96; Tue, 8 May 2018 11:51:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w48Bpam0011097 for ; Tue, 8 May 2018 07:51:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id BE01D100195F; Tue, 8 May 2018 11:51:36 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B6FC7100195A for ; Tue, 8 May 2018 11:51:35 +0000 (UTC) Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21D645D5E9 for ; Tue, 8 May 2018 11:51:23 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id f7-v6so2093956plr.4 for ; Tue, 08 May 2018 04:51:23 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.149]) by smtp.gmail.com with ESMTPSA id r68sm60584105pfi.174.2018.05.08.04.51.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 04:51:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QgAN90RN9jmPuVI+dZObV96N1e0SvhGV7HQCOYoWQyA=; b=cucM7DSOZr6cDdI9khMD3pTC+pT7hNKly/+AVlYO7bknCAz3T7JRPCtUVDY6aTqR35 xD1rReBrSLb+zilsEjuruMRZB8ppMkhDPSxt4KztHAd3SuD9A44Ak3X70ZbSO8+i9ppS gQQEssgQGOu1L8cP2CJHCulZ6OyBkoR6QfVRStQ+3kGDPDQ/BY7pkOp9+urz8TMPwBYm dfKm5SG2SbLe/JerlTvY8XY4Uuj9iH76VBqrBYfXHdFSqrZKhW5/8m6S6t2Lm/i1v/8K DGQplH/P0HLp/I7lUxCMU+ndChMxAKH414MOa42e0HlxGFuJ3cOaCYfETdoZ8t2s3vKH 8PXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QgAN90RN9jmPuVI+dZObV96N1e0SvhGV7HQCOYoWQyA=; b=ghNboOCqpFIw5EN4AbW6wFGKV+C/uv0jnrBR+byPTpJfuW38tfwiFdSQCnUWoFjFFA eC4Zu8LdEB3YfXnnRxC+m2bZs9XAceJcXiTLIhMVgxqPQUf29H+vWLh9s4lEbhNx62l9 2CGhQDNcEHvbCZCjoaDLcdhBZYK5I7EMEtEZE/9t5mTyQp1es0cNCz/nVfqOasO59rWr p1gt+bxpbY5GaIpYp8drX5oVaqC7Vb8QDYk9Rn4ov3V192ff0Roohw+4sutI2gU2UCMd vnuos8+DjJzCrkcWItLbD6bWS6Ay6Rhen9jHAB1bPILyQ9S5tzSk2jniHpXgCGDuLjCF 7xBA== X-Gm-Message-State: ALQs6tC+jbMj1s8R3SJShGlxH2/ix/SezPeyeP5N5pO9OX84MPXw6/Un /BiNJEHv5Z+6A1x+8NoNkQeSBg== X-Google-Smtp-Source: AB8JxZpE9X7vXeY7xutHwaro5NPiBnhWYipVC0Ph0K9KSJh+2nSU0IwF0+e6YM6wRr/sHMl/0eihLw== X-Received: by 2002:a17:902:8:: with SMTP id 8-v6mr40511403pla.287.1525780282025; Tue, 08 May 2018 04:51:22 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Tue, 8 May 2018 17:20:51 +0530 Message-Id: <20180508115051.60844-4-shubhamjain7495@gmail.com> In-Reply-To: <20180508115051.60844-1-shubhamjain7495@gmail.com> References: <20180508115051.60844-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 08 May 2018 11:51:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 08 May 2018 11:51:23 +0000 (UTC) for IP:'209.85.160.67' DOMAIN:'mail-pl0-f67.google.com' HELO:'mail-pl0-f67.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.531 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.67 mail-pl0-f67.google.com 209.85.160.67 mail-pl0-f67.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH 3/3] Text to json converter for mbox X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 08 May 2018 11:51:37 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" - Mbox would now return a dictionary object which would help REST API deser= ialize easily into model object. - Added test for text to json converter. For recepients and sender couldn't use AddressSerializer as api.rest calls = models which call back mbox. Possible soulution to replace to_representatio= n in AddressSerializer with add_tuple_to_dic to remove code redundancy? --- mbox.py | 18 ++++++++++ tests/test_mbox.py | 102 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 120 insertions(+) diff --git a/mbox.py b/mbox.py index fe108f3..1296078 100644 --- a/mbox.py +++ b/mbox.py @@ -13,6 +13,7 @@ import email.utils import email.header import datetime import re +from rest_framework.fields import DateTimeField =20 def _parse_header(header): r =3D '' @@ -34,6 +35,11 @@ def _addr_fmt_text(name, addr): else: return addr =20 +def addr_tuple_to_dic(obj): + if obj[0] !=3D obj[1]: + return {"name": obj[0], "address": obj[1]} + else: + return {"address": obj[1]} =20 class MboxMessage(object): """ Helper class to process mbox """ @@ -269,3 +275,15 @@ class MboxMessage(object): if c =3D=3D 0: return True return False + + def get_json(self): + """Return the JSON format of the mbox """ + msg =3D {} + msg['message_id'] =3D self.get_message_id() + msg['in_reply_to'] =3D self.get_in_reply_to() or "" + msg['date'] =3D DateTimeField().to_representation(self.get_date()) + msg['subject'] =3D self.get_subject() + msg['sender'] =3D addr_tuple_to_dic(self.get_from()) + msg['recipients'] =3D [addr_tuple_to_dic(x) for x in (self.get_to(= ) + self.get_cc())] + msg['mbox'] =3D self.get_mbox() + return msg \ No newline at end of file diff --git a/tests/test_mbox.py b/tests/test_mbox.py index 8493df7..7a21d4a 100755 --- a/tests/test_mbox.py +++ b/tests/test_mbox.py @@ -52,5 +52,107 @@ Virtualization: qemu.org | libvirt.org msg =3D mbox.MboxMessage(f.read()) self.assertTrue(msg.is_patch()) =20 + def test_get_json(self): + expected =3D {'message_id': '20160628014747.20971-1-famz@redhat.co= m', + 'in_reply_to': '', + 'date': '2016-06-28T01:47:47', + 'subject': '[Qemu-devel] [PATCH] quorum: Only compile = when supported', + 'sender': {'name': 'Fam Zheng', 'address': 'famz@redha= t.com'}, + 'recipients': [{'address': 'qemu-devel@nongnu.org'}, + {'name': 'Kevin Wolf', 'address': 'kwol= f@redhat.com'}, + {'name': 'Alberto Garcia', 'address': '= berto@igalia.com'}, + {'address': 'qemu-block@nongnu.org'}, + {'name': 'Max Reitz', 'address': 'mreit= z@redhat.com'}], + 'mbox': 'Delivered-To: importer@patchew.org\nReceived-= SPF: ' + 'Pass (zoho.com: domain of qemu-devel-bounces@= nongnu.org ' + 'designates 208.118.235.17 as permitted sender= ) client-ip: ' + '208.118.235.17\nReceived-SPF: pass (zoho.com:= domain of ' + 'gnu.org designates 208.118.235.17 as permitte= d sender) ' + 'client-ip=3D208.118.235.17; envelope-from=3Dq= emu-devel-bounces+' + 'importer=3Dpatchew.org@nongnu.org; helo=3Dlis= ts.gnu.org;\n' + 'Return-Path: ' + '\nReceived: from lists.gnu.org (lists.gnu.org= [208.118.235.17]) ' + 'by mx.zohomail.com\n\twith SMTPS id 146707897= 1424862.8927889595075;' + ' Mon, 27 Jun 2016 18:56:11 -0700 (PDT)\nRecei= ved: from localhost ' + '([::1]:33689 helo=3Dlists.gnu.org)\n\tby list= s.gnu.org with esmtp ' + '(Exim 4.71)\n\t(envelope-from )\n\tid 1bHi94-0006LP-= Ok\n\tfor ' + 'importer@patchew.org; Mon, 27 Jun 2016 21:48:= 58 -0400\nReceived: ' + 'from eggs.gnu.org ([2001:4830:134:3::10]:5327= 0)\n\tby lists.gnu.org' + ' with esmtp (Exim 4.71)\n\t(envelope-from ) id ' + '1bHi8E-0002Lm-KR\n\tfor qemu-devel@nongnu.org= ; Mon, 27 Jun 2016 ' + '21:48:07 -0400\nReceived: from Debian-exim by= eggs.gnu.org with ' + 'spam-scanned (Exim 4.71)\n\t(envelope-from ) ' + 'id 1bHi8D-0008T4-N7\n\tfor qemu-devel@nongnu.= org; Mon, 27 Jun ' + '2016 21:48:06 -0400\nReceived: from mx1.redha= t.com ' + '([209.132.183.28]:47972)\n\tby eggs.gnu.org w= ith esmtp ' + '(Exim 4.71)\n\t(envelope-from )\n\tid ' + '1bHi86-0008SN-IZ; Mon, 27 Jun 2016 21:47:58 -= 0400\nReceived: ' + 'from int-mx10.intmail.prod.int.phx2.redhat.co= m\n\t' + '(int-mx10.intmail.prod.int.phx2.redhat.com [1= 0.5.11.23])\n\t' + '(using TLSv1.2 with cipher ECDHE-RSA-AES256-G= CM-SHA384 ' + '(256/256 bits))\n\t(No client certificate req= uested)\n\tby ' + 'mx1.redhat.com (Postfix) with ESMTPS id BDB00= 7F088;\n\tTue, ' + '28 Jun 2016 01:47:57 +0000 (UTC)\nReceived: ' + 'from ad.usersys.redhat.com (dhcp-15-133.nay.r= edhat.com\n\t' + '[10.66.15.133])\n\tby int-mx10.intmail.prod.i= nt.phx2.redhat.com' + ' (8.14.4/8.14.4) with ESMTP\n\tid u5S1lssT024= 908; Mon, 27 Jun ' + '2016 21:47:55 -0400\nFrom: Fam Zheng \nTo: ' + 'qemu-devel@nongnu.org\nDate: Tue, 28 Jun 2016= 09:47:47 ' + '+0800\nMessage-Id: <20160628014747.20971-1-fa= mz@redhat.com>\n' + 'X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23\n= X-Greylist: ' + 'Sender IP whitelisted, not delayed by milter-= greylist-4.5.16\n\t' + '(mx1.redhat.com [10.5.110.26]);\n\tTue, 28 Ju= n 2016 01:47:57 ' + '+0000 (UTC)\nX-detected-operating-system: by = eggs.gnu.org: ' + 'GNU/Linux 2.2.x-3.x [generic]\nX-Received-Fro= m: 209.132.183.28\n' + 'Subject: [Qemu-devel] [PATCH] quorum: Only co= mpile when supported\n' + 'X-BeenThere: qemu-devel@nongnu.org\nX-Mailman= -Version: 2.1.21\n' + 'Precedence: list\nList-Id: \nList-Unsubscribe:' + ' ,\n\t' + '\n' + 'List-Archive: \n' + 'List-Post: \nLi= st-Help: ' + '\nList-Subscribe:' + ' ,\n\t' + '\nCc:' + ' Kevin Wolf , Alberto Garci= a ,' + '\n\tqemu-block@nongnu.org, Max Reitz \nErrors-To:' + ' qemu-devel-bounces+importer=3Dpatchew.org@no= ngnu.org\nSender: ' + '"Qemu-devel" \n' + 'X-ZohoMail-Owner: <20160628014747.20971-1-fam= z@redhat.com>+zmo_0_' + '\n' + 'X-ZohoMail-Sender: 209.132.183.28\nX-ZohoMail= : RSF_0 Z_629925259 ' + 'SPT_1 Z_629926901 SPT_1 SS_1 SFPD SFPP UW246= 8 UB2468 ZFF-EB_1' + ' COSF ODL SGR3_1_2_0_27046_53\nX-Zoho-Viru= s-Status: 2\n\n' + 'This was the only exceptional module init fun= ction that does ' + 'something\nelse than a simple list of bdrv_re= gister() calls, ' + 'in all the block\ndrivers.\n\nThe qcrypto_has= h_supports is actually' + ' a static check, determined at\ncompile time.= Follow the ' + 'block-job-$(CONFIG_FOO) convention for\nconsi= stency.\n\n' + 'Signed-off-by: Fam Zheng \n-= --\n block/' + 'Makefile.objs | 2 +-\n block/quorum.c | = 4 ----\n 2 files' + ' changed, 1 insertion(+), 5 deletions(-)\n\nd= iff --git a/block/' + 'Makefile.objs b/block/Makefile.objs\nindex 44= a5416..c87d605 ' + '100644\n--- a/block/Makefile.objs\n+++ b/bloc= k/Makefile.objs\n@@' + ' -3,7 +3,7 @@ block-obj-y +=3D qcow2.o qcow2-= refcount.o qcow2-cluster.o' + ' qcow2-snapshot.o qcow2-c\n block-obj-y +=3D = qed.o qed-gencb.o ' + 'qed-l2-cache.o qed-table.o qed-cluster.o\n bl= ock-obj-y +=3D ' + 'qed-check.o\n block-obj-$(CONFIG_VHDX) +=3D v= hdx.o vhdx-endian.o' + ' vhdx-log.o\n-block-obj-y +=3D quorum.o\n+blo= ck-obj-$(CONFIG_GNUTLS_HASH)' + ' +=3D quorum.o\n block-obj-y +=3D parallels.o= blkdebug.o blkverify.o ' + 'blkreplay.o\n block-obj-y +=3D block-backend.= o snapshot.o qapi.o\n ' + 'block-obj-$(CONFIG_WIN32) +=3D raw-win32.o wi= n32-aio.o\ndiff --git ' + 'a/block/quorum.c b/block/quorum.c\nindex 331b= 726..18fbed8 100644\n' + '--- a/block/quorum.c\n+++ b/block/quorum.c\n@= @ -1113,10 +1113,6 @@' + ' static BlockDriver bdrv_quorum =3D {\n \n st= atic void bdrv_quorum_init' + '(void)\n {\n- if (!qcrypto_hash_supports(Q= CRYPTO_HASH_ALG_SHA256))' + ' {\n- /* SHA256 hash support is requir= ed for quorum device */\n-' + ' return;\n- }\n bdrv_register(&= bdrv_quorum);\n }\n \n-- \n' + '2.9.0\n\n\n'} + dp =3D self.get_data_path("0001-simple-patch.mbox.gz") + with open(dp, "r") as f: + msg =3D mbox.MboxMessage(f.read()).get_json() + self.assertEqual(msg, expected) + if __name__ =3D=3D '__main__': main() --=20 2.14.3 (Apple Git-98) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel