/usr/share/pyshared/nws/babelfish.py is in python-nwsclient 1.6.4-8build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #
# Copyright (c) 2005-2008, REvolution Computing, Inc.
#
# NetWorkSpaces is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
import sys, getopt, traceback
from nws.client import NetWorkSpace
from nws.client import NwsServerException, NwsConnectException
from nws.client import NwsUnpicklingException
MAXLEN = 1000
def babelfish(host, port):
ws = NetWorkSpace('Python babelfish', host, port)
while 1:
try:
v = ws.fetch('food')
t = str(v)
if len(t) > MAXLEN:
t = t[:MAXLEN] + '[WARNING: output truncated]'
elif not t:
t = repr(v)
except NwsUnpicklingException, e:
t = 'Unpickling error: ' + str(e.exception)
ws.store('doof', t)
def main(argv):
host = 'localhost'
port = 8765
try:
opts, args = getopt.getopt(argv, 'h:p:')
for opt, arg in opts:
if opt == '-h':
host = arg
elif opt == '-p':
port = int(arg)
else:
raise Exception('internal error: out-of-sync with getopt')
if len(args) > 0:
print >> sys.stderr, 'ignoring unused arguments:', args
babelfish(host, port)
except getopt.GetoptError, e:
print >> sys.stderr, e.msg
sys.exit(1)
except ValueError, e:
print >> sys.stderr, "option %s requires an integer argument" % opt
sys.exit(1)
except NwsConnectException, e:
# the server isn't running
print >> sys.stderr, e.args[0]
except (KeyboardInterrupt, NwsServerException, SystemExit):
# either the user or the server is telling us to shutdown
pass
except:
traceback.print_exc()
if __name__ == '__main__':
main(sys.argv[1:])
|