~divmod-dev/divmod.org/1304710-storeless-adapter

« back to all changes in this revision

Viewing changes to Vertex/vertex/endpoint.py

  • Committer: cyli
  • Date: 2013-06-27 06:02:46 UTC
  • mto: This revision was merged to the branch mainline in revision 2702.
  • Revision ID: cyli-20130627060246-ciict8hwvjuy9d81
Move Vertex out of the Divmod.org repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2005 Divmod, Inc.  See LICENSE file for details
2
 
 
3
 
def stablesort(self, other):
4
 
    return cmp(self.__class__, getattr(other, '__class__', type(other)))
5
 
 
6
 
class TCPEndpoint:
7
 
    def __init__(self, host, port):
8
 
        self.host = host
9
 
        self.port = port
10
 
 
11
 
    def __hash__(self):
12
 
        return hash((self.host, self.port)) + 5
13
 
 
14
 
    def connect(self, protocolFactory):
15
 
        from twisted.internet import reactor
16
 
        return reactor.connectTCP(self.host, self.port, protocolFactory)
17
 
 
18
 
    def __repr__(self):
19
 
        return '<TCP@%s,%d>' % (self.host, self.port)
20
 
 
21
 
    def __cmp__(self, other):
22
 
        if isinstance(other, TCPEndpoint):
23
 
            return cmp((self.host, self.port),
24
 
                       (other.host, other.port))
25
 
        return stablesort(self, other)
26
 
 
27
 
 
28
 
class Q2QEndpoint:
29
 
    def __init__(self, service, fromAddress, toAddress, protocolName):
30
 
        self.service = service
31
 
        self.fromAddress = fromAddress
32
 
        self.toAddress = toAddress
33
 
        self.protocolName = protocolName
34
 
 
35
 
    def __repr__(self):
36
 
        return '<Q2Q from <%s> to <%s> on %r>' % (
37
 
            self.fromAddress, self.toAddress, self.protocolName)
38
 
 
39
 
    def __cmp__(self, other):
40
 
        if isinstance(other, Q2QEndpoint):
41
 
            return cmp((self.fromAddress, self.toAddress, self.protocolName),
42
 
                       (other.fromAddress, other.toAddress, other.protocolName))
43
 
        return stablesort(self, other)
44
 
 
45
 
    def __hash__(self):
46
 
        return hash((self.fromAddress,
47
 
                     self.toAddress,
48
 
                     self.protocolName)) + 7
49
 
 
50
 
    def connect(self, protocolFactory):
51
 
        # from twisted.python.context import get
52
 
        # get("q2q-service")
53
 
        return self.service.connectQ2Q(
54
 
            self.fromAddress, self.toAddress, self.protocolName,
55
 
            protocolFactory)
56