Re: Problems getting TwistedMatrix

2004-12-07 Thread donnal
I just downloaded it yesterday, and it was very fast.
Donnal Walter
Arkansas Children's Hospital

-- 
http://mail.python.org/mailman/listinfo/python-list


class attribute to instance attribute

2005-06-30 Thread Donnal Walter
This is a question about Python patterns or idioms. Over a period of 
time, I have evolved a pattern of usage that seems to work better for me 
than other ways I tried previously, but in writing some documentation I 
don't know what to call this syntax or how best to describe it. I have 
not seen it used in other places.

The somewhat longish version is that I have implemented an MVP 
(model-view-presenter) architecture where each "presenter" has a "view" 
as an attribute. Take the TextField and Frame presenters for example. 
Here is one way to do it:

import wx
class TextField:

 def __init__(self):
 # do some things here to calculate *args
 self.view = wx.TextCtrl(*args)
 # do more things to set up the view

 # and more methods to make this a presenter


class Frame:

 def __init__(self):
 # do some things here to calculate *args
 self.view = wx.Frame(*args)
 # do more things to set up the view

 # and more methods to make this a presenter


There are a number of presenters, some of which have the same type of 
view (TextField and NumberField, for example) and many of which have 
different views (Frame and Notebook, for example). The way I have chosen 
to do this is to put the logic in one superclass, "Presenter":

class Presenter:
 view = None

 def __init__(self):
 # do some things here to calculate *args
 # if view is class, create instance
 if callable(self.view):
 self.view = self.view(*args)
 # do more things to set up the view

 # and more methods to make this a presenter


class TextField(Presenter):
 view = wx.TextCtrl

class Frame(Presenter):
 view = wx.Frame


Then:
 >>> app = wx.App(False)
 >>> f = Frame()
 >>> isinstance(f.view, wx.Frame)
True

To summarize, each subclass has a class attribute "view" that is 
converted to an instance attribute of the same name at runtime.

Is this a common Python idiom? If so, does it have a name? Is there a 
better way to do the same thing?

Regards,
Donnal Walter
Arkansas Children's Hospital


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: class attribute to instance attribute

2005-07-01 Thread Donnal Walter
Devan L wrote:

> Why make it an instance attribute? Couldn't you just look at
 > the class attribute?

Each "presenter" (instance) needs its own "view" (instance). The class 
attribute references a wxPython class. The resulting instance attribute 
references a wxPython object (widget or container).

> If its something that depends on each instance's value
> assigned to the attribute, why not make it an instance attribute to
> start with?

The view instance is not known at design time; it can only be created at 
runtime. To do this requires doing so in the __init__() method, either 
in a separate version method for every different presenter class, or 
once in the superclass, as I have done.

Donnal


-- 
http://mail.python.org/mailman/listinfo/python-list


combining namespaces when importing two modules

2005-08-22 Thread Donnal Walter
I would like to be able to write something like:

import dcw as dw
import xyz as dw

such that the 'dw' namespace includes definitions from both dcw and xyz, 
but in the script above names from dcw1 are lost. How can I combine the 
two? (I'd rather not use 'import *'.) Thanks.

Best regards,
Donnal Walter
Arkansas Children's Hospital


-- 
http://mail.python.org/mailman/listinfo/python-list


AsciiDoc 6.0.0

2005-02-07 Thread Donnal Walter
Stuart Rackham wrote:
AsciiDoc

AsciiDoc is an uncomplicated text document format for writing short
documents, articles, books and UNIX man pages.
AsciiDoc files can be translated to HTML (with or without
stylesheets), DocBook (articles, books and refentry documents)
and LinuxDoc using the asciidoc(1) command.
Lately I've been thinking about using reStructuredText for creating 
simple web pages. Should I consider AsciiDoc as an alternative, and if 
so, what are its advantages by comparison? Thanks.

Donnal Walter
--
http://mail.python.org/mailman/listinfo/python-list


using cmd.exe as a telnet client

2004-12-03 Thread Donnal Walter
Several months ago I tried using the telnet module (on Windows XP) to 
communicate with a proprietary host on our network. This was 
unsuccessful due to problems with "option negotiation", and I gave up on 
the project for a while. I still have need for this, however, so I 
recently started thinking about alternatives. I suppose I could dig deep 
enough into option negotiation to use the socket module (with telnet as 
a guide), but I am hoping to find a way to use fewer synapses.

Using the Windows C:> prompt (cmd.exe) I can telnet into this host with 
no problems (the Windows telnet client performs option negotiation just 
fine). Is there a straightforward way of using os.popen() (or os.fork() 
or os.exec*() or os.wait*()) to connect to the host from Python via the 
Windows telnet client?

Thanks,
Donnal Walter
Arkansas Children's Hospital
--
http://mail.python.org/mailman/listinfo/python-list


Re: using cmd.exe as a telnet client

2004-12-06 Thread Donnal Walter
Grant Edwards wrote:
You don't have to start from scratch. The telnet module has
hooks built-into it1 so that you can have it call your routines
to handle option negotiation.  I did it once to impliment some
extra Telnet protocol features, and it wasn't difficult.
Ok, you've inspired me to give it a try. First, I am assuming that you 
mean writing a custom callback function to send to 
Telnet.set_option_negotiation_callback(callback). Or did you mean 
writing a subclass of Telnet? Can someone provide an example of a 
callback function that I might use as a template for writing mine?

This is unfamiliar territory for me, but I tried to snoop a bit using 
ethereal (also new to me) and as near as I can tell, the options in 
question are:
0, binary transmission
1, echo
3, suppress go ahead
23, send location

And it may be that not all of these are critical, but if so, I don't 
know how to tell which is which.

Eyal Lotem wrote:
I think I have a much simpler solution for you guys..
Assuming you can run arbitrary code on the proprietary
server.
Actually I cannot. The server runs a second-party information system, 
the primary access to which is third-party terminal emulator software 
that uses telnet connections. What I am trying to do is emulate this 
emulator. :-)

  cmd.exe is not a command line program.  It's a terminal (emulator).  
You might be able to use the telnet program, though.
Yes, I see that now. Thanks.
 Before doing this, 
I'd recommend looking at Twisted's telnet support (both
the version in 1.3 and the version that will be in 2.0),
which actually supports option negotiation in a
reasonable way.
I've been wanting to get acquainted with Twisted for awhile now, so this 
might be a good time to do so. I think I will give Grant's idea a whirl, 
but if I get bogged down there, I will definitely look at Twisted's 
telnet support. BTW, do you know if Twisted's option negotiation uses a 
callback function? I might download it just to take a look, even if I 
don't use it directly.

Thanks,
Donnal Walter
Arkansas Children's Hospital
--
http://mail.python.org/mailman/listinfo/python-list


Re: using cmd.exe as a telnet client

2004-12-06 Thread Donnal Walter
Grant Edwards wrote:
> You don't have to start from scratch. The telnet module has
> hooks built-into it1 so that you can have it call your routines
> to handle option negotiation.  I did it once to impliment some
> extra Telnet protocol features, and it wasn't difficult.
Ok, you've inspired me to give it a try. First, I am assuming that you 
mean writing a custom callback function to send to 
Telnet.set_option_negotiation_callback(callback). Or did you mean 
writing a subclass of Telnet? Can someone provide an example of a 
callback function that I might use as a template for writing mine?

This is unfamiliar territory for me, but as near as I can tell, the 
options in question are:
0, binary transmission
1, echo
3, suppress go ahead
23, send location

And it may be that not all of these are critical, but if so, I don't 
know how to tell which is which.

Eyal Lotem wrote:
> I think I have a much simpler solution for you guys..
> Assuming you can run arbitrary code on the proprietary
> server.
Actually I cannot. The server runs a second-party information system, 
the primary access to which is third-party terminal emulator software 
that uses telnet connections. What I am trying to do is emulate this 
emulator. :-)

Jp Calderone wrote:
>   cmd.exe is not a command line program.  It's a terminal (emulator).
> You might be able to use the telnet program, though.
Yes, I see that now. Thanks.
>  Before doing this,
> I'd recommend looking at Twisted's telnet support (both
> the version in 1.3 and the version that will be in 2.0),
> which actually supports option negotiation in a
> reasonable way.
I've been wanting to get acquainted with Twisted for awhile now, so this 
might be a good time to do so. I think I will give Grant's idea a whirl, 
but if I get bogged down there, I will definitely look at Twisted's 
telnet support. BTW, do you know if Twisted's option negotiation uses a 
callback function? I might download it just to take a look, even if I 
don't use it directly.

Thanks,
Donnal Walter
Arkansas Children's Hospital
--
http://mail.python.org/mailman/listinfo/python-list


Re: using cmd.exe as a telnet client

2004-12-06 Thread Donnal Walter
Grant Edwards wrote:
> You don't have to start from scratch. The telnet module has
> hooks built-into it1 so that you can have it call your routines
> to handle option negotiation.  I did it once to impliment some
> extra Telnet protocol features, and it wasn't difficult.
Ok, you've inspired me to give it a try. First, I am assuming that you 
mean writing a custom callback function to send to 
Telnet.set_option_negotiation_callback(callback). Or did you mean 
writing a subclass of Telnet? Can someone provide an example of a 
callback function that I might use as a template for writing mine?

This is unfamiliar territory for me, but as I can tell, the options in 
question are:
0, binary transmission
1, echo
3, suppress go ahead
23, send location

And it may be that not all of these are critical, but if so, I don't 
know how to tell which is which.

Eyal Lotem wrote:
> I think I have a much simpler solution for you guys..
> Assuming you can run arbitrary code on the proprietary
> server.
Actually I cannot. The server runs a second-party information system, 
the primary access to which is third-party terminal emulator software 
that uses telnet connections. What I am trying to do is emulate this 
emulator. :-)

Jp Calderone wrote:
>   cmd.exe is not a command line program.  It's a terminal (emulator).
> You might be able to use the telnet program, though.
Yes, I see that now. Thanks.
>  Before doing this,
> I'd recommend looking at Twisted's telnet support (both
> the version in 1.3 and the version that will be in 2.0),
> which actually supports option negotiation in a
> reasonable way.
I've been wanting to get acquainted with Twisted for awhile now, so this 
might be a good time to do so. I think I will give Grant's idea a whirl, 
but if I get bogged down there, I will definitely look at Twisted's 
telnet support. BTW, do you know if Twisted's option negotiation uses a 
callback function? I might download it just to take a look, even if I 
don't use it directly.

Thanks,
Donnal Walter
Arkansas Children's Hospital
--
http://mail.python.org/mailman/listinfo/python-list


Re: using cmd.exe as a telnet client

2004-12-06 Thread Donnal Walter
I wrote:
I've been wanting to get acquainted with Twisted for awhile
now, ... BTW, do you know if Twisted's option negotiation
uses a callback function? I might download it to take a look, ...
Sorry I did not do this earlier, before I posted. It is obvious (now 
that I have downloaded it) that Twisted's Telnet implementation is based 
on its own Protocol base class (nice design). The only documentation I 
have been able to find, however, is in the protocols/telnet module 
itself. It is still not immediately obvious (to me) how to use the iac* 
methods to negotiate these options. Any help is much appreciated.

(I've not given up on writing my own funtion for Python's telnetlib, but 
I'm trying to keep all my options open. Besides, I will probably have 
other uses for Twisted later.)

Donnal Walter
Arkansas Children's Hospital


--
http://mail.python.org/mailman/listinfo/python-list


Re: Problems getting TwistedMatrix

2004-12-07 Thread Donnal Walter
Lucas Raab wrote:
Has anybody who has recently downloaded Twisted seem to have any 
problems with downloading it?? I'm a dial-up user (which might be why) 
and whenever I click the link to download it it takes 30+ for a 1.8 MB 
file, which should take only about 7-10.
I just downloaded Twisted yesterday and had no problem. I don't recall 
the exact amount of time, but it seemed very fast.

Donnal Walter
--
http://mail.python.org/mailman/listinfo/python-list


Re: using cmd.exe as a telnet client

2004-12-07 Thread Donnal Walter
Jp Calderone wrote:
The iac_FOO method will be called whenever the telnet command FOO is received with the 
command's "argument" (the byte following it) as its only argument.  When a 
subnegotiation is received, iacSBchunk is called.
That's the 1.3 API, anyway.  It will still exist in 2.0, but it is lookingly increasingly likely that the new version will be ready in time for 2.0.  With the new API, the enableLocal() method is invoked when an option negotiation initiated by this side of the connection is allowed by the remote side, and enableRemote() is invoked when the remote side has requested an option be enabled (it can return true or false to allow or deny the enabling).  Similar disableLocal() and disableRemote() methods exist.  Callbacks can be registered for subnegotiation, based on the command for which the subnegotiation is negotiating options.  There are also do() and dont() methods that return Deferreds.  There's a whole bunch of other new cool features too, but I've probably gone on long enough, especially for a module that hasn't even been released :)
Thanks. When 2.0 comes out, I will take definitely a look. In the 
meantime I was determined to figure out how to make telnetlib work. 
(After all, Grant said is would be easy. :-) ) After much trial and 
error, I found that the following function works for me.

import telnetlib as tnl
HOST = 'nnn.nnn.nnn.nnn'
PORT = 23
def negotiate(sock, cmd, opt):
if cmd == tnl.DO and opt == tnl.SNDLOC:
sock.sendall(tnl.IAC + tnl.WONT + opt)
elif cmd == tnl.DO and opt == tnl.BINARY:
sock.sendall(tnl.IAC + tnl.WILL + opt)
elif cmd == tnl.DO and opt == tnl.ECHO:
sock.sendall(tnl.IAC + tnl.WILL + opt)
elif cmd == tnl.DO and opt == tnl.SGA:
sock.sendall(tnl.IAC + tnl.WILL + opt)
elif cmd == tnl.WILL and opt == tnl.BINARY:
sock.sendall(tnl.IAC + tnl.DO + opt)
elif cmd == tnl.WILL and opt == tnl.ECHO:
sock.sendall(tnl.IAC + tnl.DO + opt)
elif cmd == tnl.WILL and opt == tnl.SGA:
sock.sendall(tnl.IAC + tnl.DO + opt)
elif cmd in (tnl.DO, tnl.DONT):
sock.sendall(tnl.IAC + tnl.WONT + opt)
elif cmd in (tnl.WILL, tnl.WONT):
sock.sendall(tnl.IAC + tnl.DONT + opt)
return
mytn = tnl.Telnet(HOST, PORT)
mytn.set_debuglevel(2)
mytn.set_option_negotiation_callback(negotiate)
mytn.read_until("Enter device name?")
This function is currently a bit redundant, and I have not yet commented 
out each option to see what I can get away with and what not, but at 
least I can now connect without "Connection reset by peer". Thanks to 
all who replied for your advice and encouragement.

Donnal Walter
Arkansas Children's Hospital
--
http://mail.python.org/mailman/listinfo/python-list