~ubuntu-branches/debian/sid/pyro/sid

« back to all changes in this revision

Viewing changes to examples/stockquotes/Server_noNS.py

  • Committer: Bazaar Package Importer
  • Author(s): Carl Chenet, Carl Chenet, Jakub Wilk
  • Date: 2010-09-14 01:04:28 UTC
  • Revision ID: james.westby@ubuntu.com-20100914010428-02r7p1rzr7jvw94z
Tags: 1:3.9.1-2
[Carl Chenet]
* revert to 3.9.1-1 package because of the development status 
  of the 4.1 package is unsuitable for stable use
  DPMT svn #8557 revision (Closes: #589172) 
* added debian/source
* added debian/source/format
* package is now 3.0 (quilt) source format
* debian/control
  - Bump Standards-Version to 3.9.1

[Jakub Wilk]
* Add ‘XS-Python-Version: >= 2.5’ to prevent bytecompilation with python2.4
  (closes: #589053).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# This server connects to the Event server directly,
 
4
# it doesn't use the name server but requires a direct URI.
 
5
 
 
6
from Pyro.EventService.Clients import Publisher
 
7
 
 
8
import random, time
 
9
 
 
10
symbols = ('SUN','MICROSOFT','IBM','ORACLE','SAP','NOVELL')
 
11
 
 
12
class StockMarket(Publisher):
 
13
        def __init__(self, symbols, es_URI):
 
14
                Publisher.__init__(self, esURI=es_URI)
 
15
                self.symbols=symbols
 
16
        def publishQuote(self):
 
17
                symbol=random.choice(self.symbols)
 
18
                quote =round(random.random()*100+50,2)
 
19
                print symbol,'=',quote
 
20
                self.publish('STOCKQUOTE.'+symbol, quote)
 
21
 
 
22
def main():
 
23
        es_URI = raw_input("enter URI of the Event Server: ")
 
24
        market1 = StockMarket(symbols[:3], es_URI)
 
25
        market2 = StockMarket(symbols[3:], es_URI)
 
26
 
 
27
        print 'Publishing quotes.'
 
28
        while 1:
 
29
                time.sleep(random.random())
 
30
                market = random.choice( (market1, market2) )
 
31
                market.publishQuote()
 
32
 
 
33
if __name__=='__main__':
 
34
        main()
 
35