~ubuntuone-control-tower/ubuntuone-storage-protocol/stable-1-6

« back to all changes in this revision

Viewing changes to samples/ping_client.py

  • Committer: Tarmac
  • Author(s): Rodney Dawes
  • Date: 2010-11-16 15:10:48 UTC
  • mfrom: (121.1.4 use-packages)
  • Revision ID: tarmac-20101116151048-b0e20j7lorb4yhe1
Switch to using packaged mocker and ubuntuone-dev-tools
Use pyflakes with u1lint and also run pep8
Fix a lot of pylint/pyflakes/pep8 errors

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#
5
5
# Copyright 2009 Canonical Ltd.
6
6
#
7
 
# This program is free software: you can redistribute it and/or modify it 
 
7
# This program is free software: you can redistribute it and/or modify it
8
8
# under the terms of the GNU Affero General Public License version 3,
9
9
# as published by the Free Software Foundation.
10
10
#
11
 
# This program is distributed in the hope that it will be useful, but 
12
 
# WITHOUT ANY WARRANTY; without even the implied warranties of 
13
 
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
11
# This program is distributed in the hope that it will be useful, but
 
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
14
# PURPOSE.  See the GNU Affero General Public License for more details.
15
15
#
16
16
# You should have received a copy of the GNU Affero General Public License
23
23
from ubuntuone.storageprotocol.client import (
24
24
    StorageClientFactory, StorageClient)
25
25
 
 
26
 
26
27
class PingClient(StorageClient):
27
28
    """Simple client that calls a callback on connection."""
28
29
 
29
30
    def connectionMade(self):
30
31
        """Setup and call callback."""
31
 
        # pylint: disable-msg=W0201
32
32
        # pylint: disable=W0201
33
33
        StorageClient.connectionMade(self)
34
34
        print "Connection made."
35
35
        d = self.ping()
 
36
 
36
37
        def done(request):
37
38
            """We have the ping reply"""
38
39
            print "Ping RTT:", request.rtt
46
47
 
47
48
        d.addCallbacks(done, error)
48
49
 
 
50
 
49
51
class PingClientFactory(StorageClientFactory):
50
52
    """A test oriented protocol factory."""
51
 
    # no init: pylint: disable-msg=W0232
52
53
    # no init: pylint: disable=W0232
53
54
 
54
55
    protocol = PingClient
59
60
        print 'Connection failed. Reason:', reason
60
61
        reactor.stop()
61
62
 
 
63
 
62
64
if __name__ == "__main__":
63
65
    # these 3 lines show the different ways of connecting a client to the
64
66
    # server