1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
from twisted.application import strports
6
from twisted.trial import unittest
8
class ParserTestCase(unittest.TestCase):
12
def testSimpleNumeric(self):
13
self.assertEqual(strports.parse('80', self.f),
14
('TCP', (80, self.f), {'interface':'', 'backlog':50}))
16
def testSimpleTCP(self):
17
self.assertEqual(strports.parse('tcp:80', self.f),
18
('TCP', (80, self.f), {'interface':'', 'backlog':50}))
20
def testInterfaceTCP(self):
21
self.assertEqual(strports.parse('tcp:80:interface=127.0.0.1', self.f),
23
{'interface':'127.0.0.1', 'backlog':50}))
25
def testBacklogTCP(self):
26
self.assertEqual(strports.parse('tcp:80:backlog=6', self.f),
28
{'interface':'', 'backlog':6}))
31
def test_simpleUNIX(self):
33
L{strports.parse} returns a C{'UNIX'} port description with defaults
34
for C{'mode'}, C{'backlog'}, and C{'wantPID'} when passed a string with
35
the C{'unix:'} prefix and no other parameter values.
38
strports.parse('unix:/var/run/finger', self.f),
39
('UNIX', ('/var/run/finger', self.f),
40
{'mode': 0666, 'backlog': 50, 'wantPID': True}))
43
def test_modeUNIX(self):
45
C{mode} can be set by including C{"mode=<some integer>"}.
48
strports.parse('unix:/var/run/finger:mode=0660', self.f),
49
('UNIX', ('/var/run/finger', self.f),
50
{'mode': 0660, 'backlog': 50, 'wantPID': True}))
53
def test_wantPIDUNIX(self):
55
C{wantPID} can be set to false by included C{"lockfile=0"}.
58
strports.parse('unix:/var/run/finger:lockfile=0', self.f),
59
('UNIX', ('/var/run/finger', self.f),
60
{'mode': 0666, 'backlog': 50, 'wantPID': False}))
63
def testAllKeywords(self):
64
self.assertEqual(strports.parse('port=80', self.f),
65
('TCP', (80, self.f), {'interface':'', 'backlog':50}))
69
strports.parse(r'unix:foo\:bar\=baz\:qux\\', self.f),
70
('UNIX', ('foo:bar=baz:qux\\', self.f),
71
{'mode': 0666, 'backlog': 50, 'wantPID': True}))
74
def testImpliedEscape(self):
76
strports.parse(r'unix:address=foo=bar', self.f),
77
('UNIX', ('foo=bar', self.f),
78
{'mode': 0666, 'backlog': 50, 'wantPID': True}))
80
def testNonstandardDefault(self):
82
strports.parse('filename', self.f, 'unix'),
83
('UNIX', ('filename', self.f),
84
{'mode': 0666, 'backlog': 50, 'wantPID': True}))