K2LL33D SHELL

 Apache/2.4.7 (Ubuntu)
 Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64
 uid=33(www-data) gid=33(www-data) groups=33(www-data)
 safemode : OFF
 MySQL: ON | Perl: ON | cURL: OFF | WGet: ON
  >  / usr / lib / python2.7 / dist-packages / twisted / test /
server ip : 172.67.156.115

your ip : 172.70.127.59

H O M E


Filename/usr/lib/python2.7/dist-packages/twisted/test/test_postfix.py
Size3.47 kb
Permissionrw-r--r--
Ownerroot : root
Create time27-Apr-2025 09:56
Last modified15-Jul-2011 03:05
Last accessed06-Jul-2025 21:49
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
Test cases for twisted.protocols.postfix module.
"""

from twisted.trial import unittest
from twisted.protocols import postfix
from twisted.test.proto_helpers import StringTransport


class PostfixTCPMapQuoteTestCase(unittest.TestCase):
data = [
# (raw, quoted, [aliasQuotedForms]),
('foo', 'foo'),
('foo bar', 'foo%20bar'),
('foo\tbar', 'foo%09bar'),
('foo\nbar', 'foo%0Abar', 'foo%0abar'),
('foo\r\nbar', 'foo%0D%0Abar', 'foo%0D%0abar', 'foo%0d%0Abar', 'foo%0d%0abar'),
('foo ', 'foo%20'),
(' foo', '%20foo'),
]

def testData(self):
for entry in self.data:
raw = entry[0]
quoted = entry[1:]

self.assertEqual(postfix.quote(raw), quoted[0])
for q in quoted:
self.assertEqual(postfix.unquote(q), raw)

class PostfixTCPMapServerTestCase:
data = {
# 'key': 'value',
}

chat = [
# (input, expected_output),
]

def test_chat(self):
"""
Test that I{get} and I{put} commands are responded to correctly by
L{postfix.PostfixTCPMapServer} when its factory is an instance of
L{postifx.PostfixTCPMapDictServerFactory}.
"""
factory = postfix.PostfixTCPMapDictServerFactory(self.data)
transport = StringTransport()

protocol = postfix.PostfixTCPMapServer()
protocol.service = factory
protocol.factory = factory
protocol.makeConnection(transport)

for input, expected_output in self.chat:
protocol.lineReceived(input)
self.assertEqual(
transport.value(), expected_output,
'For %r, expected %r but got %r' % (
input, expected_output, transport.value()))
transport.clear()
protocol.setTimeout(None)


def test_deferredChat(self):
"""
Test that I{get} and I{put} commands are responded to correctly by
L{postfix.PostfixTCPMapServer} when its factory is an instance of
L{postifx.PostfixTCPMapDeferringDictServerFactory}.
"""
factory = postfix.PostfixTCPMapDeferringDictServerFactory(self.data)
transport = StringTransport()

protocol = postfix.PostfixTCPMapServer()
protocol.service = factory
protocol.factory = factory
protocol.makeConnection(transport)

for input, expected_output in self.chat:
protocol.lineReceived(input)
self.assertEqual(
transport.value(), expected_output,
'For %r, expected %r but got %r' % (
input, expected_output, transport.value()))
transport.clear()
protocol.setTimeout(None)



class Valid(PostfixTCPMapServerTestCase, unittest.TestCase):
data = {
'foo': 'ThisIs Foo',
'bar': ' bar really is found\r\n',
}
chat = [
('get', "400 Command 'get' takes 1 parameters.\n"),
('get foo bar', "500 \n"),
('put', "400 Command 'put' takes 2 parameters.\n"),
('put foo', "400 Command 'put' takes 2 parameters.\n"),
('put foo bar baz', "500 put is not implemented yet.\n"),
('put foo bar', '500 put is not implemented yet.\n'),
('get foo', '200 ThisIs%20Foo\n'),
('get bar', '200 %20bar%20really%20is%20found%0D%0A\n'),
('get baz', '500 \n'),
('foo', '400 unknown command\n'),
]