Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / internet / test / fakeendpoint.py
1 # -*- test-case-name: twisted.internet.test.test_endpoints -*-
2 # Copyright (c) Twisted Matrix Laboratories.
3 # See LICENSE for details.
4
5 """
6 Fake client and server endpoint string parser plugins for testing purposes.
7 """
8
9 from zope.interface.declarations import implements
10 from twisted.plugin import IPlugin
11 from twisted.internet.interfaces import (IStreamClientEndpoint,
12                                          IStreamServerEndpoint,
13                                          IStreamClientEndpointStringParser,
14                                          IStreamServerEndpointStringParser)
15
16 class PluginBase(object):
17     implements(IPlugin)
18
19     def __init__(self, pfx):
20         self.prefix = pfx
21
22
23
24 class FakeClientParser(PluginBase):
25
26     implements(IStreamClientEndpointStringParser)
27
28     def parseStreamClient(self, *a, **kw):
29         return StreamClient(self, a, kw)
30
31
32
33 class FakeParser(PluginBase):
34
35     implements(IStreamServerEndpointStringParser)
36
37     def parseStreamServer(self, *a, **kw):
38         return StreamServer(self, a, kw)
39
40
41
42 class EndpointBase(object):
43
44     def __init__(self, parser, args, kwargs):
45         self.parser = parser
46         self.args = args
47         self.kwargs = kwargs
48
49
50
51 class StreamClient(EndpointBase):
52
53     implements(IStreamClientEndpoint)
54
55
56
57 class StreamServer(EndpointBase):
58
59     implements(IStreamServerEndpoint)
60
61
62
63 # Instantiate plugin interface providers to register them.
64 fake = FakeParser('fake')
65 fakeClient = FakeClientParser('cfake')
66