nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: aio-libs/aiosmtpd
Pull request #46 (2017-03-22 07:38:12)

Rename envelope data to content field
During #39  and #45 I missed this review based commit.


Patch:
diff --git a/aiosmtpd/handlers.py b/aiosmtpd/handlers.py
index 36a54c2..ad797cc 100644
--- a/aiosmtpd/handlers.py
+++ b/aiosmtpd/handlers.py
@@ -80,7 +80,7 @@ class Debugging:
             add_separator = True
         if add_separator:
             print(file=self.stream)
-        self._print_message_content(session.peer, envelope.data)
+        self._print_message_content(session.peer, envelope.content)
         print('------------ END MESSAGE ------------', file=self.stream)
 
 
@@ -92,7 +92,7 @@ class Proxy:
 
     @asyncio.coroutine
     def handle_DATA(self, session, envelope):
-        lines = envelope.data.splitlines(keepends=True)
+        lines = envelope.content.splitlines(keepends=True)
         # Look for the last header
         i = 0
         ending = CRLF
@@ -157,7 +157,7 @@ class Message:
     def prepare_message(self, session, envelope):
         # If the server was created with decode_data True, then data will be a
         # str, otherwise it will be bytes.
-        data = envelope.data
+        data = envelope.content
         if isinstance(data, bytes):
             message = message_from_bytes(data, self.message_class)
         else:
diff --git a/aiosmtpd/smtp.py b/aiosmtpd/smtp.py
index a3394b3..3126689 100644
--- a/aiosmtpd/smtp.py
+++ b/aiosmtpd/smtp.py
@@ -41,7 +41,7 @@ class Envelope:
     def __init__(self):
         self.mail_from = None
         self.mail_options = None
-        self.data = None
+        self.content = None
         self.rcpt_tos = []
         self.rcpt_options = []
 
@@ -561,7 +561,7 @@ class SMTP(asyncio.StreamReaderProtocol):
         received_data = EMPTYBYTES.join(data)
         if self._decode_data:
             received_data = received_data.decode('utf-8')
-        self.envelope.data = received_data
+        self.envelope.content = received_data
         # Call the new API first if it's implemented.
         if hasattr(self.event_handler, 'handle_DATA'):
             args = (self.session, self.envelope)
@@ -570,7 +570,7 @@ class SMTP(asyncio.StreamReaderProtocol):
             warn('Use handler.handle_DATA instead of .process_message()',
                  DeprecationWarning)
             args = (self.session.peer, self.envelope.mail_from,
-                    self.envelope.rcpt_tos, self.envelope.data)
+                    self.envelope.rcpt_tos, self.envelope.content)
             if asyncio.iscoroutinefunction(self.event_handler.process_message):
                 status = yield from self.event_handler.process_message(*args)
             else:


Test patch:
diff --git a/aiosmtpd/tests/test_smtp.py b/aiosmtpd/tests/test_smtp.py
index 840f23e..c73dc9a 100644
--- a/aiosmtpd/tests/test_smtp.py
+++ b/aiosmtpd/tests/test_smtp.py
@@ -33,7 +33,7 @@ class ReceivingHandler:
 
     @asyncio.coroutine
     def handle_DATA(self, session, envelope):
-        self.box.append(envelope.data)
+        self.box.append(envelope.content)
 
 
 class SizedController(Controller):
Repository: aio-libs/aiosmtpd
Pull request #51 (2017-03-25 11:15:32)

Data command fix
Hey! I watchng on you )

RFC 5321 4.1.1.4.  DATA (DATA)
The mail data are terminated by a line containing only a period, that
is, the character sequence "<CRLF>.<CRLF>", where the first <CRLF> is
actually the terminator of the previous line

So, empty email will raise IndexError exception with your last changes.
I`m lazy ass to not adding a test for that.


Patch:
diff --git a/aiosmtpd/smtp.py b/aiosmtpd/smtp.py
index 959ccdb..825bee3 100644
--- a/aiosmtpd/smtp.py
+++ b/aiosmtpd/smtp.py
@@ -533,7 +533,8 @@ class SMTP(asyncio.StreamReaderProtocol):
         while not self._connection_closed:          # pragma: no branch
             line = yield from self._reader.readline()
             if line == b'.\r\n':
-                data[-1] = data[-1].rstrip(b'\r\n')
+                if data:
+                    data[-1] = data[-1].rstrip(b'\r\n')
                 break
             num_bytes += len(line)
             if (not size_exceeded and


Test patch:
diff --git a/aiosmtpd/tests/test_smtp.py b/aiosmtpd/tests/test_smtp.py
index 110d998..79666c9 100644
--- a/aiosmtpd/tests/test_smtp.py
+++ b/aiosmtpd/tests/test_smtp.py
@@ -86,8 +86,13 @@ class ErrorController(Controller):
 
 
 class TestProtocol(unittest.TestCase):
+    def write(self, data):
+        self.responses.append(data)
+
     def setUp(self):
         self.transport = Mock()
+        self.transport.write = self.write
+        self.responses = []
         self._old_loop = asyncio.get_event_loop()
         self.loop = asyncio.new_event_loop()
         asyncio.set_event_loop(self.loop)
@@ -117,8 +122,27 @@ class TestProtocol(unittest.TestCase):
             self.loop.run_until_complete(protocol._handler_coroutine)
         except asyncio.CancelledError:
             pass
-        assert len(handler.box) == 1
-        assert handler.box[0] == data
+        self.assertEqual(len(handler.box), 1)
+        self.assertEqual(handler.box[0], data)
+
+    def test_empty_email(self):
+        handler = ReceivingHandler()
+        protocol = self._get_protocol(handler)
+        protocol.data_received(BCRLF.join([
+            b'HELO example.org',
+            b'MAIL FROM: <anne@example.com>',
+            b'RCPT TO: <anne@example.com>',
+            b'DATA',
+            b'.',
+            b'QUIT\r\n'
+            ]))
+        try:
+            self.loop.run_until_complete(protocol._handler_coroutine)
+        except asyncio.CancelledError:
+            pass
+        self.assertEqual(self.responses[5], b'250 OK\r\n')
+        self.assertEqual(len(handler.box), 1)
+        self.assertEqual(handler.box[0], b'')
 
 
 class TestSMTP(unittest.TestCase):