profiling memory usage

2006-10-05 Thread Eddie
Hi,

I am looking for a method to profile memory usage in my python program.
The program provides web service and therefore is intended to run for a
long time. However, the memory usage tends to increase all the time,
until in a day or two the system cannot handle it any more and starts
to do constant swapping. Is there a way to look at which objects or
variables are taking the huge amount of memory space?

Thanks,

Eddie

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


Re: RPy / R

2006-02-07 Thread Eddie
Hi Jason

I had more success, being able to run a few test programs.
Not sure why yours would be crashing - I have a similar setup (Win XP 
SP2 with all updates) - my version of Python is the Activestate download 
(ActivePython-2.4.2.10-win32-x86.msi). Have you installed Numeric?
If all else fails might be worth trying to unistall Python and 
installing the Activestate version (which includes the Win32 extensions).

Good luck

Eddie

jason wrote:
> Hello:
> 
> I installed the following:
> 
> python-2.4.2.msi
> pywin32-207.win32-py2.4.exe
> R-2.2.1-win32.exe
> rpy-0.4.6-R-2.0.0-to-2.2.1-py24.win32.exe
> 
> on a Windows XP (SP2) box.
> 
> [SNIP]
> 
> Is this a setup issue? Thanks for your help.
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RPy / R

2006-02-12 Thread Eddie
R = 2.2.1
Rpy = rpy-0.4.6-R-2.0.0-to-2.2.1-py24.win32.exe
Active Python = ActivePython-2.4.2.10-win32-x86.msi
Numeric = Numeric-24.2.win32-py2.4.exe
NumPy = numpy-0.9.4.win32-py2.4.exe
I don't believe I have installed SciPy

The Numeric and NumPy differences are explained at http://numeric.scipy.org/

Eddie


jason wrote:
> Thanks for your response. I'll try to install all the same versions that you 
> have.
> 
> I have removed my version of Python and installed ActivePython 
> (ActivePython-2.4.2.10-win32-x86.msi).
> 
> Could you please tell me which versions of the following you have installed:
> NumPy
> SciPy
> RPy
> R
> 
> I have not installed Numeric. Is that different from NumPy? If so, which 
> version do you have?
> 
> Thanks.
> 
> "Eddie" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
>>Hi Jason
>>
>>I had more success, being able to run a few test programs.
>>Not sure why yours would be crashing - I have a similar setup (Win XP SP2 
>>with all updates) - my version of Python is the Activestate download 
>>(ActivePython-2.4.2.10-win32-x86.msi). Have you installed Numeric?
>>If all else fails might be worth trying to unistall Python and installing 
>>the Activestate version (which includes the Win32 extensions).
>>
>>Good luck
>>
>>Eddie
>>
>>jason wrote:
>>
>>>Hello:
>>>
>>>I installed the following:
>>>
>>>python-2.4.2.msi
>>>pywin32-207.win32-py2.4.exe
>>>R-2.2.1-win32.exe
>>>rpy-0.4.6-R-2.0.0-to-2.2.1-py24.win32.exe
>>>
>>>on a Windows XP (SP2) box.
>>>
>>>[SNIP]
>>>
>>>Is this a setup issue? Thanks for your help.
>>>
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


integer multiplication

2011-04-03 Thread Eddie Tsay
Does anyone know what algorithms for integer multiplication does Python use?
I am trying to compare it to those used by Sage as it seems like it takes
much longer for Python to do large integer multiplication as compared to
Sage (anyone know off the top of their heads?)

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


Re: another time challenge

2005-09-29 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>Hey there pythoneers

>i have another question about time, specifically, the mxDateTime
>module.
>i have been able to get a RelativeDateTimeDiff between two times,
>it gives me a difference between two DateTimes in the form of +3days
>+2hours etc...

>so, if i have a date that is 6 days and 6 hours from another day,
>it will give me Days+6, hours+5.

>what i need is something like 6.4 days or close to it.
>is there an easy way to convert this ?

>if not i can write up something to do the math.

>i guess i am just looking for a cleaner shortcut.

You could extract the hours,mins,secs part to a DateTimeDelta which supports
float() and just divide that into 86400.0.

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


Re: HTML Tree View with and

2005-01-28 Thread Eddie Corns
Gregor Horvath <[EMAIL PROTECTED]> writes:

>Hi,

>Before I reinvent the wheel I`d like to ask if someone has done this 
>before since I did not find an advice at Google.

>The goal is to create a dynamic Tree View in HTML.

>Say I have a data strucure like this:

>structList = 
>{'Sun':{'Sun.1':['Sun1.1','Sun1.2'],'Sun.2':['Sun2.1','Sun2.2']},'Kupa':['Kupa1']}

>I want to transform this into HTML:

>
>Sun
>   
>   Sun.1
> 
> Sun1.1
> Sun1.2
> 
>   Sun.2
> 
> Sun2.1
> Sun2.2
> 
>   
>Kupa
>   
>   Kupa1
>   
>

>If the user clicks on a branch-link say 'Sun.1' then the branch below 
>opens/closes (not printed by the servlet). Like a tree view control in 
>an native GUI app.

>Has this, or a similar approach, been done before in python ( I am using 
>webware/cheetah)?

Here is a browser side solution that you can have a play with:

 htmltree.py ---
import sys

id = 0
def new_id ():
global id
id += 1
return id

def mk_expander (id, lab='+'):
return '%s' % 
(id,id,lab)

def start_invisible (id):
return '' % id

def finish_invisible (dst):
dst.write ('')

def build_tree (dst, node):
dst.write ('\n')
for branch in node:
##sys.stderr.write ('-- %s\n'%branch)
id = new_id()
if type(node) == type([]):
dst.write ('%s\n' % branch)
else:
dst.write ('%s\n%s' % (mk_expander (id,branch),
   start_invisible(id)))
build_tree (dst, node[branch])
finish_invisible (dst)

style_stuff = '''

A.expander {border-style: solid; border-width: thin 0 thin thin}
A {text-decoration: none}
.mono {font-family : monospace}
TD {text-align : right}
TR.col {background: #9F9 }
.link {background: #99f;
   border-style : solid}
'''

print 'BLAH'
print ''
print style_stuff
print '''


'''

structList = 
{'Sun':{'Sun.1':['Sun1.1','Sun1.2'],'Sun.2':['Sun2.1','Sun2.2']},'Kupa':['Kupa1']}

build_tree (sys.stdout, structList)
print '\n\n'

-

and the javascript file that goes with it


-hier.js --
visibility_state = new Array();
highlighted  = new Array();
selected_node = null;
selected_id = null;
function get_visibility (id) {
var m = visibility_state[id];
if (m == undefined)
m = "none";
return m;
}
function set_visibility (id, e, vis) {
e.style.display = vis;
visibility_state[id] = vis;
}
function togglen(id) {
toggle_branch (id);
do_select (id);
return false;
}
function toggle_branch(id) {
var e = document.getElementById(id);
var m = get_visibility (id);
if (m == "none")
m = "inline";
else
m = "none";
set_visibility (id, e, m);
}
function show_branch (id) {
var e = document.getElementById(id);
set_visibility (id, e, "inline");
}
function hide_branch (id) {
var e = document.getElementById(id);
set_visibility (id, e, "none");
}
function do_select (id) {
if (selected_id != null) {
var e = document.getElementById("e."+selected_id);
e.style.backgroundColor = 'transparent';
}
var n = document.getElementById("e."+id);
n.style.backgroundColor = 'red';
selected_node = document.getElementById(id);
selected_id = id;
}
function set_visibility_all (n, vis) {
if (n == null) return false;
if (n.nodeType == 1) {
if (n.tagName == "DIV" && n.id != "")
set_visibility (n.id, n, vis);
for (var c = n.firstChild; c != null; c = c.nextSibling)
set_visibility_all (c, vis);
}
}

---

the javascript code is extracted from a larger set of functions that include a
popup menu with inbuilt search (which opens tree levels as necessary), if
you're interested.

Eddie


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


Re: ideas for university project ??

2005-08-26 Thread Eddie Corns
Jon Hewer <[EMAIL PROTECTED]> writes:

>Hi

>I'm about to start my third, and final, year in computer science at
>cambridge uni, and i need to come up with an idea for a software
>project, but i'm really struggling for ideas, and i was wondering
>whether anyone here had any suggestions.

>I'd say i'm probably most experienced in Java, but I have started
>learning Python, and although i haven't got very far yet, I plan on
>doing some more in the next few weeks.

>Areas of interested include AI, distributed systems.  Most of all i
>want something that is interesting, and actually useful (thats
>probably stating the obvious!)

Well, there's a dearth of good software for network management especially for
medium to large networks.  Traffic stats, configuration management, device
status etc.  It would certainly be useful but whether it rocks your boat
interest wise ...  Admittedly I personally would like to play with Erlang
rather than Python for this.

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


Re: How to know if connection is active when using telnetlib?

2005-08-26 Thread Eddie Corns
Wojciech Halicki-Piszko <[EMAIL PROTECTED]> writes:

>How to know if connection is active after telnetlib.Telnet.open(host,port)?

If open() doesn't throw an exception then you should have a connection you can
start reading/writing with.  Unless you have some special meaning for
'active'?

I'm just basing this on reading telnetlib.py.

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


Re: need a little help with time

2005-08-26 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>Hey there.
>i have a time string (created with strftime) then read from a file,
>i am having some trouble understanding how to get the difference
>between times.
>i know i can structime(timestring) and get a time value, but i dont
>know how to manipulate it.

>basically, if i have string 2005-08-24 09:25:58
>and another string 2005-08-24 09:28:58

>how can i tell how many minutes, hours, seconds, days, months etc..
>have passed between the first string and the second ?

>or, if there is a good tutorial on this kind of thing, please post a
>url.

Either the datetime module or mxDateTime from
  http://www.egenix.com/files/python/mxDateTime.html
which is more extensive.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "week-year" conversion to date

2005-09-14 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>I was wondering if it there is an "easy" way to get the dd-mm- from
>ww-.

>I would like to get, for example the first day (date-month-year) in the
>week i specify. Found plenty of ways to go th other way, but none that
>give me the reverse.

>Idealy I would like both the beginning date/time and the end date/time
>of the specified week, but if i can just get a hold one of the or some
>other defined time in this week i could probably work out the rest.

>This is in Python :-)

>dd = day in month
>mm = month
> = year
>ww = week #

>Thanks for any and all help.

>>> import mx.DateTime
>>> d=mx.DateTime.DateTime(1992)+mx.DateTime.RelativeDateTime(weeks=15) 
>>> d

>>> d=mx.DateTime.DateTime(1992)+mx.DateTime.RelativeDateTime(weeks=51)
>>> d


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


Re: Looking for system/network monitoring tool written in Python

2005-09-22 Thread Eddie Corns
Mike Meyer <[EMAIL PROTECTED]> writes:

>I've found a fair number of systems/network monitoring tools (things
>like Big Brother, Big Sister, cricket, etc.) written in Perl.

Depressing isn't it!

>I'm curious if there are any written in Python.

I couldn't find any after extensive searching.  I wasn't really looking for
Python solutions as such, more avoiding things in Perl/PHP etc. but I would
have noticed any Python ones.  I won't bore you with my theories on why this
is.

Some applications such as nagios and moodss will at least allow you to write
your own scripts in Python.  This is probably OK for small networks.

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


Re: Looking for system/network monitoring tool written in Python

2005-09-22 Thread Eddie Corns
Simon Brunning <[EMAIL PROTECTED]> writes:

>On 9/22/05, Mike Meyer <[EMAIL PROTECTED]> wrote:
>> I've found a fair number of systems/network monitoring tools (things
>> like Big Brother, Big Sister, cricket, etc.) written in Perl. I'm
>> curious if there are any written in Python.

>There's EDDIE - <http://eddie-tool.net/>. I've never used it myself,

How annoying that I didn't even notice one that was named after me.  It's not
what I was after but interesting none the less.

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


Re: Tar module issue

2005-02-07 Thread Eddie Corns
I don't have the original query any more but I think your problem is related
to mixing absolute and relative file paths.  That is the filenames themselves,
I think I recall in your original message you were mixing up the idea of
global variables in your code versus the filenames stored in the TAR archive.

When tar restores files it will either be doing them as relative paths
(directory + filename) or absolute paths, I think relative is the default.
This is relative to where you are now when you extract NOT where you were when
you archived them.  I think there may be extra confusion to do with the way
tar stores hard links  What might be happening is that some paths are actually
links to other files, you would need to figure out how tar is dealing with
this - is it converting links back to relative paths (unlikely I suspect)?
Either way it might be trying to create a link to a file that either doesn't
exist on the system you are restoring to or not from the directory where you
now are.

I hope that makes sense.

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



Re: Trees

2005-02-28 Thread Eddie Corns
Alex Le Dain <[EMAIL PROTECTED]> writes:

>Is there a generic "tree" module that can enable me to sort and use 
>trees (and nodes). Basically having methods such as .AddNode(), 
>.GetAllChildren(), .FindNode() etc.

http://newcenturycomputers.net/projects/rbtree.html

might do most of what you want.

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


Re: Trouble using telentlib

2005-02-28 Thread Eddie Corns
[EMAIL PROTECTED] (Nitin Chaumal) writes:

>I sarched the existing threads but didnt find an answer to this.

>I am writing simple script which uses telentlib to open a session with
>a unix machine and run "tail -f logfile.txt" on one of the logfiles.

>import telnetlib

>HOST = "192.X.X.X"
>user = "myname"
>password = "mypass"

>tn = telnetlib.Telnet(HOST)

>tn.read_until("login: ")
>tn.write(user + "\n")
>if password:
>tn.read_until("Password: ")
>tn.write(password + "\n")

>tn.write("tail -f /tmp/logfile.txt\n")

># what do i write here ? #

>tn.write("exit\n")

>I want to read every line of the output into a string and run regex on
>it.
>I tried tn.interact() which does show me the ouput but the CPU usage
>on my win2k machine reaches 99% !! :(

>How do i execute a command and then read its output, then another
>command and read its output and so on. I tried to find docs on
>telnetlib but in vain.

>Can somebody guide me please

>Thanks
>Nitin

tn.write("tail -f /tmp/logfile.txt\n")
while True:
  # get one more line
  line = tn.read_until ('\n')
  regex_thing (line)

Remember, "tail -f" never exits, so you probably want to break when you've
find what you want and then just close the telnet session.  It would probably
be nice if telnetlib had a readline function that handled all the messy
details for portable end of line checking.

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


Re: shuffle the lines of a large file

2005-03-07 Thread Eddie Corns
"Joerg Schuster" <[EMAIL PROTECTED]> writes:

>Hello,

>I am looking for a method to "shuffle" the lines of a large file.

>I have a corpus of sorted and "uniqed" English sentences that has been
>produced with (1):

>(1) sort corpus | uniq > corpus.uniq

>corpus.uniq is 80G large. The fact that every sentence appears only
>once in corpus.uniq plays an important role for the processes
>I use to involve my corpus in.  Yet, the alphabetical order is an
>unwanted side effect of (1): Very often, I do not want (or rather, I
>do not have the computational capacities) to apply a program to all of
>corpus.uniq. Yet, any series of lines of corpus.uniq is obviously a
>very lopsided set of English sentences.

>So, it would be very useful to do one of the following things:

>- produce corpus.uniq in a such a way that it is not sorted in any way
>- shuffle corpus.uniq > corpus.uniq.shuffled

>Unfortunately, none of the machines that I may use has 80G RAM.
>So, using a dictionary will not help.

>Any ideas?

Instead of shuffling the file itself maybe you could index it (with dbm for
instance) and select random lines by using random indexes whenever you need a
sample.

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


Re: Question on sorting

2004-11-30 Thread Eddie Corns
wes weston <[EMAIL PROTECTED]> writes:

>Lad wrote:
>> Hi,
>> I have a file of records of 4 fields each.
>> Each field is separated by a semicolon. That is
>> 
>> Filed1;Ffield2;Field3;Field4
>> 
>> But there may be also empty records such as
>> 
>> (only semicolons).
>> 
>> For sorting I used
>> #
>> lines = file('Config.txt').readlines()# a file I want to sort
>> lines.sort()
>> ff=open('ConfigSorted.txt','w')# sorted file
>> ff.writelines(lines)
>> ff.close()
>> ###
>> It was sorted but empty records were first. I need them to be last(at
>> the end of the file). How can I do that?
>> 
>> Thanks for help
>> Lad

>Lad,
>The sort call can have a function name as an arg. You
>could do:

>def mycompare(s1,s2):
>#return -1 to put s1's at front; 1 to put s1's at back; 0 for a tie
>#if s1=="" and s2<>"": return 1

>lines.sort(mycompare)

I can't help feeling that the OP might have really wanted to be sorting on
individual fields rather than whole lines.  In which case I would think of
doing a line.split(';') on each line before sorting.  It would still need
either to use a function to make empty fields go later or alternatively use
DSU (google!) and convert '' to say '~' and back again. This also solves the
problem of what to expect when only some of the fields are blank rather than
all of them.

Eddie

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


Clarification of two concepts (or maybe one?)

2004-12-10 Thread Eddie Parker








Sorry, I’ve tried to search the web on this,
but I’m still a little fuzzy. I was hoping a quick e-mail might clear
this up.


What I’m looking for, is a way to turn a python ‘application’,
into a ‘stand-alone’ application. i.e., you don’t need the
Python interpreter, libraries, etc, installed on your hard drive. (I’m OK
with .py files existing – I just don’t want to have to bother the
user to install more then just my app). 

 

One alternative is to embed the Python interpreter in
a C++ app, and then just call the entry point... But I’m curious if there’s
a better way?

 

On the unrelated (or maybe related) concept, the words
“python freezing” keeps buzzing around my subconscious. I’m
not sure if this item can help me in any such way, but I can’t find any
good articles on what this phenomenon *is*.
Can anyone point me to a definitive web page that describe this, or indicate if
it *is* in fact what I’m
looking for? (I’m probably way off base on this one).

 

Anyhow, your help is most appreciated! Thank you!

 

-e-








---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 01/11/2004
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python and curses

2005-12-16 Thread Eddie Corns
"linuxfreak" <[EMAIL PROTECTED]> writes:

>Was wanting to write a text based application in python seems
>curses module is the way to go... anyone knows of any good tutorials
>apart from the one written by esr

There is at least 1 higher level library atop curses.
http://excess.org/urwid/  I've only played with it a little bit but it looks
useful.

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


Re: BaseHTTPServer weirdness

2006-09-12 Thread Eddie Corns
Ron Garret <[EMAIL PROTECTED]> writes:

>In article <[EMAIL PROTECTED]>,
> Steve Holden <[EMAIL PROTECTED]> wrote:

>> I wouldn't necessarily say you are wrong here, It's just that the cgi 
>> module has sort of "just growed", so it isn't conveniently factyored for 
>> reusability in other contexts. Several people (including me) have taken 
>> a look at it with a view to possible re-engineering and backed away 
>> because of the difficulty of maintaining compatibility. Python 3K will 
>> be an ideal oppoertunity to replace it, but until then it's probably 
>> going to stay in the same rather messy but working state.

>It's not necessary to re-engineer cgi, just cutting and pasting and 
>editing the code as I've done would seem to suffice.

>But all I'm really looking for here at this point is confirmation that 
>I'm not in fact doing something stupid.  In the past I've found that 
>nine times out of ten if I find myself wanting to rewrite or add 
>something to a Python module it's an indication that I'm doing something 
>wrong.

Well if it's any consolation; that's exactly what I did - cut about 7 lines
from CGIHTTPSERVER into my do_POST method.  Maybe we're both stoopid.  This
was at least 3 years ago before I moved on to Quixote and then
CherryPy/TurboGears but I recall thinking at the time that it was probably
just one of those little cracks that show up from time to time in the library
(there aren't so very many of them).

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


Re: Twisted book opinions?

2006-02-09 Thread Eddie Corns
Jay Parlar <[EMAIL PROTECTED]> writes:

>I was hoping to get some c.l.p. opinions on O'Reilly's new Twisted book.

Well I certainly felt that I understood it better after reading the book.
OTOH I haven't tried to put that knowledge into practice yet.

I think calling it a cookbook is misleading, it shows how to do essential
tasks using fairly complete examples.

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


Re: telnetlib problems

2006-03-01 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>I'm trying to use a python script to access an embedded computer
>running linux and connected via a crossover ethernet cable using the
>following script...

>...and I realize the username and password is not realistic... I'm
>still in "proof of concept" stage here :)

>#
>import telnetlib

>tn = telnetlib.Telnet('192.168.100.11')
>tn.read_until('login: ', 5)
>tn.write('user\n')
>tn.read_until('Password: ', 5)
>tn.write('password\n')
>tn.read_until('bash-2.05$ ', 5)
>tn.write('ls\n')
>print tn.read_very_eager()


>As a script, this doesn't work.  However, if I execute the same
>commands interactively, it works fine.  If I insert some time delays as
>follows...

What doesn't work about it?  Have you checked the return value from the
read_until()s to see if they're returning anything sensible? are any of them
timing out?

Anyway, my first guess would be the use of read_very_eager(), it's something
you normally only descend to when you're stuck for something to match on.
Normally you would do another read_until() for the prompt.

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


Re: telnetlib problems

2006-03-02 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>Thanks for the reply. I've replaced the call to read_very_eager() with
>read_until() and enabled debugging messages.  My script now looks like
>this...

>#
>import telnetlib

>tn = telnetlib.Telnet('192.168.100.11')

>tn.set_debuglevel(9)

>tn.read_until('login: ', 5)

>tn.write('user\n')

>tn.read_until('Password: ', 5)

>tn.write('password\n')

>tn.read_until('bash-2.05$ ', 5)

>tn.write('ls\n')

>print tn.read_until('bash-2.05$ ', 5)
>#

>Each call to read_until() returns a valid string except for the second
>one, i.e.,
>tn.read_until('Password: ', 5) returns a null string.

>Here's the program output with debugging enabled...
>#
>Telnet(192.168.100.11,23): recv "\xff\xfd\x18\xff\xfd
>\xff\xfd#\xff\xfd'"
>Telnet(192.168.100.11,23): IAC DO 24
>Telnet(192.168.100.11,23): IAC DO 32
>Telnet(192.168.100.11,23): IAC DO 35
>Telnet(192.168.100.11,23): IAC DO 39
>Telnet(192.168.100.11,23): recv
>'\xff\xfb\x03\xff\xfd\x01\xff\xfd\x1f\xff\xfb\x05\xff\xfd!'
>Telnet(192.168.100.11,23): IAC WILL 3
>Telnet(192.168.100.11,23): IAC DO 1
>Telnet(192.168.100.11,23): IAC DO 31
>Telnet(192.168.100.11,23): IAC WILL 5
>Telnet(192.168.100.11,23): IAC DO 33
>Telnet(192.168.100.11,23): recv '\xff\xfb\x03'
>Telnet(192.168.100.11,23): IAC WILL 3
>Telnet(192.168.100.11,23): recv '\xff\xfb\x01Embedded Systems, 2050
>Single Board Computer.\r\nR'
>Telnet(192.168.100.11,23): IAC WILL 1
>Telnet(192.168.100.11,23): recv 'uning \\s Kernel \\r.\r\nEmbedded:
>2050 Special Feature'
>Telnet(192.168.100.11,23): recv 's Enabled.\r\n\r\n'
>Telnet(192.168.100.11,23): recv 'login: '
>Telnet(192.168.100.11,23): send 'user\n'
>Telnet(192.168.100.11,23): send 'password\n'
>Telnet(192.168.100.11,23): recv 'Password: '
>Telnet(192.168.100.11,23): send 'ls\n'
>Telnet(192.168.100.11,23): recv '\r\n'
>Telnet(192.168.100.11,23): recv 'Login incorrect\r\n\r\nlogin: '


>Login incorrect



>login:
>#
>It looks like it's sending the password before receiving the password
>prompt.

It looks more like it's taking longer than 5 seconds to receive the Password:
prompt so it times out, returns to your code and you send the next string
anyway but (assuming this is a valid password) the far end might throw away
any pending input when it finally does send the Password: prompt (otherwise it
would probably have got back in sync).

In short you shouldn't go past each stage unless you've verified that you got
the expected response.  I can't actually remember exactly what the responses
signify but at a minimum I assume the empty string means there's no point in
continuing because what you expected to see wasn't there so you need to either
abort or try some recovery process.  And also make sure you give it a
reasonable time to respond.

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


Re: How Can I Increase the Speed of a Large Number of Date Conversions

2007-06-08 Thread Eddie Corns
vdicarlo <[EMAIL PROTECTED]> writes:

>I am a programming amateur and a Python newbie who needs to convert
>about 100,000,000 strings of the form "1999-12-30" into ordinal dates
>for sorting, comparison, and calculations. Though my script does a ton
>of heavy calculational lifting (for which numpy and psyco are a
>blessing) besides converting dates, it still seems to like to linger
>in the datetime and time libraries.  (Maybe there's a hot module in
>there with a cute little function and an impressive set of
>attributes.)

>Anyway, others in this group have said that the date and time
>libraries are a little on the slow side but, even if that's true, I'm
>thinking that the best code I could come up with to do the conversion
>looks so clunky that I'm probably running around the block three times
>just to go next door. Maybe someone can suggest a faster, and perhaps
>simpler, way.

>Here's my code, in which I've used a sample date string instead of its
>variable name for the sake of clarity. Please don't laugh loud enough
>for me to hear you in Davis, California.

>dateTuple = time.strptime("2005-12-19", '%Y-%m-%d')
>dateTuple = dateTuple[:3]
>date = datetime.date(dateTuple[0], dateTuple[1],
>dateTuple[2])
>ratingDateOrd = date.toordinal()

>P.S. Why is an amateur newbie trying to convert 100,000,000 date
>strings into ordinal dates? To win try to win a million dollars, of
>course! In case you haven't seen it, the contest is at www.netflixprize.com.
>There are currently only about 23,648 contestants on 19,164 teams from
>151 different countries competing, so I figure my chances are pretty
>good. ;-)

I can't help noticing that dates in '-mm-dd' format are already sortable
as strings.


>>> '1999-12-30' > '1999-12-29'
True

depending on the pattern of access the slightly slower compare speed _might_
compensate for the conversion speed.  Worth a try.

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


Re: Can a low-level programmer learn OOP?

2007-07-17 Thread Eddie Corns
[EMAIL PROTECTED] (Aahz) writes:

>In article <[EMAIL PROTECTED]>,
>Wolfgang Strobl  <[EMAIL PROTECTED]> wrote:
>>
>>SNOBOLs powerfull patterns still shine, compared to Pythons clumsy
>>regular expressions. 

>Keep in mind that Python regular expressions are modeled on the
>grep/sed/awk/Perl model so as to be familiar to any sysadmin -- but
>there's a reason why Python makes it a *library* unlike Perl.  So adding
>SNOBOL patterns to another library would be a wonderful gift to the
>Python community...

I don't believe you can get the benefit of SNOBOL matching without direct
language support.  There's only so much a library can do. However a valiant
and interesting effort:

http://www.wilmott.ca/python/patternmatching.html

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


Re: Calculating CIDR blocks

2007-04-20 Thread Eddie Corns
Look at:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466298
it handles most of the logic of combining IP ranges.

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


Re: Calculating CIDR blocks

2007-04-20 Thread Eddie Corns
=?iso-8859-1?q?Pekka_J=E4rvinen?= <[EMAIL PROTECTED]> writes:

>On 20 huhti, 14:34, [EMAIL PROTECTED] (Eddie Corns) wrote:
>> Look at:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466298
>> it handles most of the logic of combining IP ranges.
>>
>> Eddie

>I'm getting error:
>Traceback (most recent call last):
>  File "ipr.py", line 5, in 
>x = ipv4.IP4Range(ips)
>  File "IP4Range.py", line 119, in __init__
>raise TypeError("Invalid argument.")
>TypeError: Invalid argument.

I haven't used this module for some time but if I recall your requirements
properly you need something like:

>>> R=IP4.IP4Range()
>>> for i in ips:
...  R=R|IP4.IP4Range(i) 
... 
>>> for m in R.itermasks():
...  print m
... 
192.168.0.0/26
192.168.0.64/27
192.168.0.96/29
192.168.0.104/30
192.168.0.108/31
192.168.0.110/32
192.168.0.128/25
192.168.0.112/28
>>>

There may be an easier way my memory is hazy.

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


Re: Can a low-level programmer learn OOP?

2007-07-23 Thread Eddie Corns
Wolfgang Strobl <[EMAIL PROTECTED]> writes:
>few of James Gimple's snippets from "Algorithms in SNOBOL4"
>(->http://www.snobol4.org/) as an exercise using that library might help
>to get a better appreciation. Perhaps I'll try, eventually ...

I never noticed them or the PDF of the book there before.  Some Friday
afternoon reading for sure.

Personally I hope to get more to time to look at a combination of Lua and
PEGs (http://en.wikipedia.org/wiki/Parsing_expression_grammar) for my parsing
needs.

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


Re: Can a low-level programmer learn OOP?

2007-07-23 Thread Eddie Corns
Paul McGuire <[EMAIL PROTECTED]> writes:

>On Jul 23, 5:53 am, [EMAIL PROTECTED] (Eddie Corns) wrote:
>> Wolfgang Strobl <[EMAIL PROTECTED]> writes:
>> >few of James Gimple's snippets from "Algorithms in SNOBOL4"
>> >(->http://www.snobol4.org/) as an exercise using that library might help
>> >to get a better appreciation. Perhaps I'll try, eventually ...
>>
>> I never noticed them or the PDF of the book there before.  Some Friday
>> afternoon reading for sure.
>>
>> Personally I hope to get more to time to look at a combination of Lua and
>> PEGs (http://en.wikipedia.org/wiki/Parsing_expression_grammar) for my parsing
>> needs.
>>
>> Eddie

>If you get a chance to look at pyparsing, I'd be interested in your
>comments.  The PEG page and the SNOBOL implementation have many
>similar concepts with pyparsing (or is it the other way around?).

It's on my list of things to get round to.

I think what I'm really after though is a parsing DSL.  I only did only one
fairly small project in SNOBOL but I was impressed at the ease with which I
could express the problem (some googling suggested that many end users found
the same).  I guess I want SNOBOL embedded in a modern language with scoping
etc.  Python is antithetical to (this class of) DSLs (IMHO) :(

Probably what I really need is parser combinators in Haskell or maybe camlp4
or some such exotica but unfortunately I've never heard of them.

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


Re: Can a low-level programmer learn OOP?

2007-07-24 Thread Eddie Corns
Paul McGuire <[EMAIL PROTECTED]> writes:

>On Jul 23, 12:43 pm, [EMAIL PROTECTED] (Eddie Corns) wrote:
>> Paul McGuire <[EMAIL PROTECTED]> writes:
>> >On Jul 23, 5:53 am, [EMAIL PROTECTED] (Eddie Corns) wrote:
>> >> Wolfgang Strobl <[EMAIL PROTECTED]> writes:
>> >> >few of James Gimple's snippets from "Algorithms in SNOBOL4"
>> >> >(->http://www.snobol4.org/) as an exercise using that library might help
>> >> >to get a better appreciation. Perhaps I'll try, eventually ...
>>
>> >> I never noticed them or the PDF of the book there before.  Some Friday
>> >> afternoon reading for sure.
>>
>> >> Personally I hope to get more to time to look at a combination of Lua and
>> >> PEGs (http://en.wikipedia.org/wiki/Parsing_expression_grammar) for my 
>> >> parsing
>> >> needs.
>>
>> >> Eddie
>> >If you get a chance to look at pyparsing, I'd be interested in your
>> >comments.  The PEG page and the SNOBOL implementation have many
>> >similar concepts with pyparsing (or is it the other way around?).
>>
>> It's on my list of things to get round to.
>>
>> I think what I'm really after though is a parsing DSL.  I only did only one
>> fairly small project in SNOBOL but I was impressed at the ease with which I
>> could express the problem (some googling suggested that many end users found
>> the same).  I guess I want SNOBOL embedded in a modern language with scoping
>> etc.  Python is antithetical to (this class of) DSLs (IMHO) :(
>>
>> Probably what I really need is parser combinators in Haskell or maybe camlp4
>> or some such exotica but unfortunately I've never heard of them.
>>
>> Eddie- Hide quoted text -
>>
>> - Show quoted text -

>I have had pyparsing users refer to pyparsing as an in-Python DSL, and
>others make comparisons between pyparsing and Parsec (monadic
>combinator in Haskell).  I'm not sure why you would say this approach
>is antithetical to Python - the builtin support for operator
>overloading, __call__, __len__, __nonzero__(soon to be __bool__),
>__set/getattr__, etc. permit you to impart quite a bit of expressive
>behavior to your parsing classes.  What I tried to do with pyparsing
>was to emulate Python's builtin container classes and object instances
>with the results that get returned from invoking a parser, so that the
>after-parsing work would feel natural to established Python users.

I don't dispute it is _a_ DSL nor even that it's a very powerful way to do
parsing (in case anyone was wondering).  But my intuition tells me that it
ought to be possible to close the remaining gap and I'm trying to understand
how that could be done and that's the bit I suspect might require a higher
class of DSL (ie macros).  Of course my intuition never
fails but sometimes reality distorts so as to make me look wrong.

The plan is to apply pyparsing to some real project and hopefully gain a
better understanding.  I have in mind parsing Cisco config files as a first
trial.  As to when I get time...

You see I could just sit down and work out how to solve the problem (eg the
config files) using pyparsing or whatever and move on but I'm sure you of all
people know why that's not enough!

>If you want to just see some existing BNF's implemented in pyparsing,
>you can view them online at the pyparsing wiki.  Here are some
>representative examples:
>http://pyparsing.wikispaces.com/space/showimage/simpleSQL.py
>http://pyparsing.wikispaces.com/space/showimage/fourFn.py
>http://pyparsing.wikispaces.com/space/showimage/jsonParser.py

>-- Paul

I appreciate the input and hopefully one day I'll be posting some questions on
the wiki.

Cheers,
Eddie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: flattening/rolling up/aggregating a large sorted text file

2007-03-22 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>Hi,

>Given a large ascii file (delimited or fixed width) with one ID field
>and dimensions/measures fields, sorted by dimensions, I'd like to
>"flatten" or "rollup" the file by creating new columns: one for each
>combination of dimension level, and summing up measures over all
>records for a given ID.

>If the wheel has already been invented, great, please point me in the
>right direction. If not, please share some pointers on how to think
>about this problem in order to write efficient code.

>Is a hash with dimension level combinations a good approach, with
>values reset at each new ID level?

>I know mysql, Oracle etc will do this , but they all have a cap on #
>of columns allowed. SAS will allow unlimited columns, but I don't own
>SAS.

>Thanks.


>ID,color,shape,msr1
>--
>001, blue, square,  4
>001, red , circle,5
>001, red,  circle,6


>ID, blue_circle, blue_square, red_circle, red_square
>--
>001,0,4,11,0
>002 ...

Something like:

import sys
from sets import Set

ids  = {}
keys = Set()

for line in sys.stdin:
ID,COL,SHAPE,VAL = [s.strip() for s in line.split(',')]
ids.setdefault(ID,{})
key = '%s_%s'%(COL,SHAPE)
ids[ID].setdefault(key,0)
ids[ID][key] += int(VAL)
keys.add(key)

print 'id',',',','.join([str(key) for key in keys])
for id,cols in ids.items():
print id,',', ', '.join([str(cols.get(k,0)) for k in keys])


Doesn't keep all possible keys just those that are actually used.
Needs to sort() things here and there.

Incidentally I don't think you could do it in SQL at all in this way but you
could do it in a more vertical fashion (eg
001, red, circle, 11
001, blue, square, 4
002, red, rhombus, 99) etc.

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


Re: Need help to learn Python

2007-03-26 Thread Eddie Corns
"wesley chun" <[EMAIL PROTECTED]> writes:

>with that said, i would still like to state that the book's target
>audience is for people who know how to program but need to pick up
>Python as quickly as possible.  the "theory" that's in the book is
>really more explanation of how the Python interpreter works,
>especially the relationship between objects and memory management.
>the goal is to give you enough of an understanding of how Python works
>"under the covers" that you will write very effective code, even as a
>beginner to the language.

Worked for me.  The 1/e was the easiest intro to a language I've ever read.
(I don't suppose you fancy doing one for Ruby :)

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


Re: why did these companies choose Tcl over Python

2007-10-31 Thread Eddie Corns
chewie54 <[EMAIL PROTECTED]> writes:

>Hello,

>As an electronics engineer I use some very expensive EDA CAD tool
>programs that are scriptable using Tcl.  I was wondering why these
>companies have choose to use Tcl instead of Python.   Some of these
>are:

>   Mentor Graphics ModelTech VHDL and Verilog simulator
>   Synopsys  Design Compiler and Primetime Static Timing Analyzer
>   Actel FPGA tools.

>Tcl seems to very popular in my business as the scripting language of
>choice.

>I'm in the process of deciding to use Tcl or Python for a CAD tool
>program that I have been working on.Most of the core of the
>program,  the database,   will be done is C as an extension to either
>Tcl or Python,   but I intend to use Tk or wxPthon for the GUI.   I do
>need publishing quality outputs from drawings done on a graphics
>device that are scaled to standard printer paper sizes.


>I would prefer to use Python but can't deny how popular Tcl is,  as
>mentioned above,  so my question is why wasn't Python selected by
>these companies as the choice of scripting languages for their
>product?

Having abandoned TCL for Python years ago, my thought is:

If you expect your users to write (and maintain) large scripts - have mercy on
them and don't give them TCL.

For larger programs/scripts having proper data structures, readable syntax,
etc. is a very significant factor.  (Of course TCL may have improved beyond
all recognition since I last used it).  Try putting together some sample
scripts in both languages and see how easily others can understand them (and
yourself in a few months).

When I want something nimbler than Python I use Lua.

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


Re: CherryPy/Turbogears on server not controlled by me

2007-02-20 Thread Eddie Corns
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:

>Brian Blais wrote:

>> Hello,
>> 
>> I was wondering if there is a way to run CherryPy/Turbogears on a server
>> that I don't
>> have root access to.  If I just choose a random port, I think the security
>> guys on
>> the server would get annoyed at me.  

>Why should they? Opening anything networking will open a port. And if you
>have shell access, you can point PYTHONPATH to a directory of your choice
>and let easy_install install the packages required there.

>I don't see a problem. And _if_ they get mad at you, well - there isn't
>anything you can do about that I presume apart from telling them to shut
>up - because without a port, there is no webapp...

And since your application is not running as root the worst that can happen if
you introduce a security hazard in your app is that only your files are
endangered.  I run several TG apps in user space and the only small problem
I've had is the logistics of telling people if you have to move it somewhere
else since a DNS alias doesn't help much with explicit port numbers in the URL.

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


Re: Natural-language datetime parsing and display (was: user friendly datetime features)

2008-01-09 Thread Eddie Corns

For PARSING see http://code-bear.com/code/parsedatetime/

The OP was looking for presentation though.  I know roundup has code for this
if an independent library can't be found.

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


Re: Wo killed Benazir Bhutto of Pakistan = NEOCON/ZIOCON many layers of deception

2008-01-30 Thread Eddie Davis
A moron posting from google?

How unusual!



-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: Online Debugging

2008-01-31 Thread Eddie Corns
Yansky <[EMAIL PROTECTED]> writes:

>I'm trying to debug a script on my server and it's taking forever
>using print to find the error. I've tried to use the debugging
>examples on this page http://webpython.codepoint.net/debugging but
>they don't seem to be working for me.

>Is there an easier/better way to debug online scripts? I was hoping
>there might be something similar to php where it gives some error info
>and the line code.

One simple method might be something along these lines:

 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52215

which I came across yesterday.

Eddie

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


Re: Intelligent Date & Time parsing

2008-03-10 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>I'm new to python and I was wondering if there are any intelligent
>date/time parsing modules out there. I've looked at strptime (or
>whichever it is) and mxDateTime from the eGenix package. I need
>something to parse user input for a django app, and it's awesome to be
>able to write "last monday", "a year ago", or "10pm tuesday" like
>PHP's strtotime.

>So are there any modules that allow for that kind of parsing?

http://code-bear.com/code/parsedatetime/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thousand Seperator

2008-03-14 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>I'm trying to find some code that will turn:

>100 -> 100
>1000 -> 1,000
>100 -> 1,000,000
>-1000 -> -1,000

>I know that can be done using a regular expression. In Perl I would do
>something like:

>sub thousand {
>$number = reverse $_[0];
>$number =~ s/(\d\d\d)(?=\d)(?!d*\.)/$1,/g;
>return scalar reverse $number;
>}

>But I cannot find how to do this in Python.

Look at the locale module.  If you're producing the numbers yourself then they
get printed in that format otherwise you can convert them to numbers first.

Eddie

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


function call overhead

2009-02-03 Thread Eddie Watson
What's the Python function call overhead like?

Eddie Watson
"CLC plonkers in a state of panic!!!"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a file with iterators

2008-10-17 Thread Eddie Corns
Luis Zarrabeitia <[EMAIL PROTECTED]> writes:


>I need to parse a file, text file. The format is something like that:

>TYPE1 metadata
>data line 1
>data line 2
>...
>data line N
>TYPE2 metadata
>data line 1
>...
>TYPE3 metadata
>...

>And so on. The type and metadata determine how to parse the following dat=
>a
>lines. When the parser fails to parse one of the lines, the next parser i=
>s
>chosen (or if there is no 'TYPE metadata' line there, an exception is thr=
>own).

>This doesn't work:

>=3D=3D=3D
>for line in input:
>parser =3D parser_from_string(line)
>parser(input)
>=3D=3D=3D

>because when the parser iterates over the input, it can't know that it fi=
>nished
>processing the section until it reads the next "TYPE" line (actually, unt=
>il it
>reads the first line that it cannot parse, which if everything went well,=
> should
>be the 'TYPE'), but once it reads it, it is no longer available to the ou=
>ter
>loop. I wouldn't like to leak the internals of the parsers to the outside=
>.

>What could I do?
>(to the curious: the format is a dialect of the E00 used in GIS)
>=20
>--=20
>Luis Zarrabeitia
>Facultad de Matem=E1tica y Computaci=F3n, UH
>http://profesores.matcom.uh.cu/~kyrie




One simple way is to allow your "input" iterator to support pushing values
back into the input stream as soon as it finds an input it can't handle.

See http://code.activestate.com/recipes/502304/ for an example.
--
http://mail.python.org/mailman/listinfo/python-list


Re: parse dates

2008-06-02 Thread Eddie Corns
brechmos <[EMAIL PROTECTED]> writes:

>Hi,

>I have been using PHP the last while and in particular strtotime.
>What I want to replicate is finding the second or fourth Monday of the
>next month.  In PHP with strtotime it is easy (strtotime("second
>Monday", strtotime("next month"), but I can't find an easy way to do
>it in Python.  I have seen DateUtil, but it seems to be able to do
>only the simpler parsing (could be wrong).

>Any other ideas?

http://code-bear.com/code/parsedatetime/

>>> import parsedatetime.parsedatetime as pdt
>>> p = pdt.Calendar()
>>> p.parse('next month')
((2008, 7, 1, 9, 0, 0, 1, 183, -1), 1)

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


Re: trying to match a string

2008-07-18 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>Hi,

>Hi,

>I am taking a string as an input from the user and it should only
>contain the chars:L , M or R

>I tried the folllowing in kodos but they are still not perfect:

>[^A-K,^N-Q,^S-Z,^0-9]
>[L][M][R]
>[LRM]?L?[LRM]? etc but they do not exactly meet what I need.

>For eg: LRLRLRLRLM is ok but LRLRLRNL is not as it has 'N' .like that.

>regards,
>SZ

>The string may or may not have all the three chars.


>>> var = 'LRLRLRNL'
>>> residue = var.replace('L','').replace('R','').replace('M','')
>>> if residue != '':
...   print 'Invalid characters in input',residue
... 
Invalid characters in input N
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regarding Telnet library in python

2008-08-13 Thread Eddie Corns
Hishaam <[EMAIL PROTECTED]> writes:

>Hi,

>In python documentation, i found a telnet example as follows:

>-
>import getpass
>import sys
>import telnetlib

>HOST = "localhost"
>user = raw_input("Enter your remote account: ")
>password = getpass.getpass()

>tn = telnetlib.Telnet(HOST)

>tn.read_until("login: ")
>tn.write(user + "\n")
>if password:
>tn.read_until("Password: ")
>tn.write(password + "\n")

>tn.write("ls\n")
>tn.write("exit\n")

>print tn.read_all()
>-

>The ouput of it as follows:

>-
>Enter your remote account: root

>Last login: Mon Aug 13 11:54:32 from pcp246879pcs.ca
>Sun Microsystems Inc.   SunOS 5.10  Generic January 2005
># Desktop boothishaam net system  work
>Documents   cdrom   homeopt tfile2  zonemgr
>File.txtdev kernel  platformtmp
>QA_tmp  devices lib procusr
>acunix  etc lost+found  sbinvar
>bin export  mnt sfile   vol
>#

>-

>The difficulty i find in this is th code line "print tn.read_all()" is
>used for reading all of the output of the code at once.

>Is there a possibility to read the stdout of each command by command
>like -

># ls
>
>[capture  in a variable]
># cd /root
>
>[capture  in a variable]


>Like the above would be useful if there are a large number of commands
>to be executed in the telnet session.

>Can anyone help on this?

>Regards,
>Hishaam

One way of doing this is to send the commands one at a time and do: (untested)

  prompt = '\n# '

  tn.write("ls\n")
  stdout = tn.read_until(prompt)
  for line in stdout.splitlines():
...
  etc.

alternatively just send them all in one go as you have been and save the
output in a variable and split that on the prompt.  In either case you may
want to change the prompt to something easier to match on like "$hostname# ".

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


Re: A better RE?

2006-03-10 Thread Eddie Corns
Magnus Lycka <[EMAIL PROTECTED]> writes:

>I want an re that matches strings like "21MAR06 31APR06 1236",
>where the last part is day numbers (1-7), i.e it can contain
>the numbers 1-7, in order, only one of each, and at least one
>digit. I want it as three groups. I was thinking of

Just a small point - what does "in order" mean here? if it means that eg 1362
is not valid then you're stuck because it's context sensitive and hence not
regular.

I can't see how any of the fancy extensions could help here but maybe I'm just
lacking insight.

Now if "[\1-7]" worked you'd be home and dry.

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


Re: A better RE?

2006-03-10 Thread Eddie Corns
"Fredrik Lundh" <[EMAIL PROTECTED]> writes:

>Eddie Corns wrote:


>> >I want an re that matches strings like "21MAR06 31APR06 1236",
>> >where the last part is day numbers (1-7), i.e it can contain
>> >the numbers 1-7, in order, only one of each, and at least one
>> >digit. I want it as three groups. I was thinking of
>>
>> Just a small point - what does "in order" mean here? if it means that eg 1362
>> is not valid then you're stuck because it's context sensitive and hence not
>> regular.
>>
>> I can't see how any of the fancy extensions could help here but maybe I'm
>> just lacking insight.

>import re

>p = re.compile("(?=[1234567])(1?2?3?4?5?6?7?)$")

>def test(s):
>m = p.match(s)
>print repr(s), "=>", m and m.groups() or "none"

>test("")
>test("1236")
>test("1362")
>test("12345678")

>prints

>'' => none
>'1236' => ('1236',)
>'1362' => none
>'12345678' => none

>

I know I know!  I cancelled the article about a minute after posting it.

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


Re: A better RE?

2006-03-10 Thread Eddie Corns
"Jim" <[EMAIL PROTECTED]> writes:


>Eddie Corns wrote:
>> Just a small point - what does "in order" mean here? if it means that eg 1362
>> is not valid then you're stuck because it's context sensitive and hence not
>> regular.
>I'm not seeing that.  Any finite language is regular -- as a last
>resort you could list all ascending sequences of 7 or fewer digits (but
>perhaps I misunderstood the original poster's requirements).

No, that's what I did.  Just carelessnes on my part, time I had a holiday!

Eddie

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


Re: Help: Creating condensed expressions

2006-03-24 Thread Eddie Corns
David Hirschfield <[EMAIL PROTECTED]> writes:

>Here's the problem: Given a list of item names like:

>apple1
>apple2
>apple3_SD
>formA
>formB
>formC
>kla_MM
>kla_MB
>kca_MM

>which is a subset of a much larger list of items,
>is there an efficient algorithm to create condensed forms that match 
>those items, and only those items? Such as:

>apple[12]
>apple3_SD
>form[ABC]
>kla_M[MB]
>kca_MM

>The condensed expression syntax only has [...] and * as operators. [...] 
>matches a set of individual characters, * matches any string.
>I'd be satisfied with a solution that only uses the [...] syntax, since 
>I don't think it's possible to use * without potentially matching items 
>not explicitly in the given list.

>I'm not sure what this condensed expression syntax is called (looks a 
>bit like shell name expansion syntax), and I'm not even sure there is an 
>efficient way to do what I'm asking. Any ideas would be appreciated.

If you used regular expressions instead of globs then I think what you want is
to optimize the regular expression for:

 'apple1|apple2|apple3_SD|formA|formB|formC|kla_MM|kla_MB|kca_MM'

then spit the optimised finite automaton back out.  Of course if you're just
searching Python might do a decent job of optimising it anyway.

Looking at:

  http://en.wikipedia.org/wiki/Finite_state_machine#Optimization

they make it sound so easy!.  There's also a whole bunch of tools on that
page.  Maybe there's an optimiser you can use in one of them.

Failing that I guess you build a tree and try to merge nodes where they fork.
I suspect an optimal solution would be hard but if you knew your input did
have lots of redundancy a simple algorithm might work.

Or I could be talking crap as usual.

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


Re: telnet session

2006-03-29 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>hi
>i am using a telnet session to simulate an authentication mechanism
>USER = "user"
>PASSWORD = "password"
>try:
>telnet = telnetlib.Telnet(HOST)
>telnet.set_debuglevel(5)
>telnet.read_until("login: ")
>telnet.write(USER + "\n")
>telnet.read_until("Password: ")
>telnet.write(PASSWORD + "\n")
>except:
>print "failed to telnet"
>else:
>try:
>telnet.write("ls\n")
>except:
>print "cannot ls"
>else:
>telnet.write("exit\n")
>print telnet.read_all()


>When i purposely input a wrong password, it "hangs" at the login prompt
>waiting for
>login and Password. The host i am telnetting to is a unix server.
>How can i "exit" this login prompt if the user keys in wrong password
>in my script?

Either do an explicit read_until() for the prompt and fail if it times out or
use expect() to see whether you saw "Password:" or prompt.  If you absolutely
don't know what the prompt might be I suppose you could do another
read_until("Password:") and if it times out then assume you got through.

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


Re: String pattern matching

2006-04-03 Thread Eddie Corns
"Jim Lewis" <[EMAIL PROTECTED]> writes:

>Anyone have experience with string pattern matching?
>I need a fast way to match variables to strings. Example:

>string - variables
>
>abcaaab - xyz
>abca - xy
>eeabcac - vxw

>x matches abc
>y matches a
>z matches aab
>w maches ac
>v maches ee

Off topic I know but I've been learning snobol pattern matching recently so I
thought I'd give this one a bash.  Here is my effort:

define('foo(str)')
&fullscan = 1
'/abcaaab/abca/eeabcac/' '/' arb $ x arb $ y arb $ z '/' *x *y '/'
+arb $ v *x arb $ w '/' *foo(v '/' w '/' x '/' y '/' z) :F(end)
foo output = str :(FRETURN)

end

Good eh?  Here's the output:

/eeabcac//abca/aab
e/eabcac//abca/aab
ee/abcac//abca/aab
eea/bcac//abca/aab
eeab/cac//abca/aab
eeabc/ac//abca/aab
eeabca/c//abca/aab
eeabcac///abca/aab
ee/bcac/a/bca/aab
eeabc/c/a/bca/aab
ee/cac/ab/ca/aab
ee/ac/abc/a/aab
ee/c/abca//aab

Removing empty entries is quite easy:

'/abcaaab/abca/eeabcac/' '/' arb $ x arb $ y arb $ z '/' *x *y '/'
+arb $ v *x arb $ w '/' *differ(v) *differ(w) *differ(x)
+*differ(y) *differ(z) *foo(v '/' w '/' x '/' y '/' z) :F(end)

generates:

ee/bcac/a/bca/aab
eeabc/c/a/bca/aab
ee/cac/ab/ca/aab
ee/ac/abc/a/aab

If I get time I'll try to get this working in Sam Wilmott's Python pattern
matching library.

What fun!

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


Re: String pattern matching

2006-04-03 Thread Eddie Corns
Kent Johnson <[EMAIL PROTECTED]> writes:

>Eddie Corns wrote:

>> If I get time I'll try to get this working in Sam Wilmott's Python pattern
>> matching library.
>> 
>> What fun!

>Cool! I have to get in on the fun :-)

>This program uses Sam Wilmott's library to find one solution. It is a 
>simple translation of your program above. I couldn't figure out how to 
>get multiple solutions.

Nice!

FWIW,
import string
from patterns_b import *

# investigate captured text and force a failure for backtracking.
# A bit clumsy perhaps! passing a lambda would be more elegant.
class DumpP (Pattern):
def Match (self, subject):
print 
print 'v =', subject['v']
print 'w =', subject['w']
print 'x =', subject['x']
print 'y =', subject['y']
print 'z =', subject['z']
if 1 == 2: yield None

subject = MatchingInput ('/abcaaab/abca/eeabcac/')
Letters = AnyOfP(string.letters)[1:]

while True:
subject ^ FenceP() & IsP('/') & Letters >> 'x' & Letters >> 'y' & Letters 
>> 'z' & IsP('/') \
 & AnotherP('x') & AnotherP('y') & IsP('/') \
 & Letters >> 'v' & AnotherP('x') & Letters >> 'w' & IsP('/') & 
DumpP()


Not sure if it's supposed to exit in quite the way it does.

With a more compact notation, I think this beats regexs for many uses
especially when dealing with end users.

Note: if anyone else plays with this interesting pattern library, note there
are a couple of small bugs in it.

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