JAPH

2005-11-12 Thread Lawrence D'Oliveiro
import sys
charset = " .JPacehknorstuy"
modulo = 17
s = 69859911049503515105680510599913390885187193231927247909305172858127641629
num = iter(range(2, ))
while s != 1 :
n = num.next()
if s % n == 0 :
sys.stdout.write("%s" % charset[(n - 1) % modulo])
s /= n
#end if
#end while
sys.stdout.write("\n")

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


Re: Is there a limit to os.popen()?

2006-07-11 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Carl J. Van Arsdall" <[EMAIL PROTECTED]> wrote:

>Well, running the make on the command line seems to work just fine, no 
>errors at all.

What about running it as

make kernelrelease | cat

This way the output goes to a pipe, which is what happens when it's 
called from your script. Do you see those "broken pipe" messages after a 
few minutes in this case?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a limit to os.popen()?

2006-07-12 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Carl J. Van Arsdall" <[EMAIL PROTECTED]> wrote:

>Lawrence D'Oliveiro wrote:
>> In article <[EMAIL PROTECTED]>,
>>  "Carl J. Van Arsdall" <[EMAIL PROTECTED]> wrote:
>>
>>   
>>> Well, running the make on the command line seems to work just fine, no 
>>> errors at all.
>>> 
>>
>> What about running it as
>>
>> make kernelrelease | cat
>>
>> This way the output goes to a pipe, which is what happens when it's 
>> called from your script. Do you see those "broken pipe" messages after a 
>> few minutes in this case?
>>   
>Alright, so I tried that line in the interpreter and got the same 
>problem.

No, I wanted you to try it from a bash command prompt, to try to 
simulate the environment when the make command on its own is invoked via 
popen.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hard time with installing MySQLdb for Python on Linux

2006-07-14 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "gmax2006" <[EMAIL PROTECTED]> wrote:

>I am having hard time with installing MySQLdb on Linux.

...

>My Linux is "Red Hat Enterprise Linux ES release 4 (Nahant)"

Why don't you just use yum to install python-mysql or whatever the 
package is called, and have it automatically work out what else is 
needed?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: printing raw postscript data on windows

2006-07-14 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Uwe Schmitt <[EMAIL PROTECTED]> wrote:

>I am trying to print raw postscript data on windows.
>win32print should do the work like this:
>
>   h=win32print.OpenPrinter(name)
>   win32print.StartDocPrinter(h, 1, ("", "", "RAW"))
>   win32print.WritePrinter(h, file("p.ps").read())
>   win32print.EndDocPrinter(h)
>   win32print.ClosePrinter(h)
>
>This works for some printers, but not for all.

One possibility is that the printer itself is doing some kind of 
auto-emulation-sensing. My experience is that this kind of thing never 
works reliably when PostScript is involved.

1) Can you check the printer settings, to ensure its "personality" (or 
whatever it's called) is set to "PostScript" and not "auto"?
2) Failing that, what if you make sure the first line of your PostScript 
is always a comment beginning with "%!" or "%!PS-"?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stderr, stdout, and errno 24

2006-07-15 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Wesley Henwood" <[EMAIL PROTECTED]> wrote:

>I've checked and double checked my code and I am closing all files
>explicitly after opening them.

If you're running your program under Linux, a very easy way to confirm 
this is to look in the directory

/proc//fd

where  is the PID of your running program. In here you will see a 
symlink to every file your program has open, the name of the link being 
the file descriptor number.

To make it easier to watch, you may want to stick in a sleep of a few 
seconds in-between iterations of the code that executes the Python 
script.

If you see the entries piling up in this directory, that will confirm 
that you're not closing those files.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a limit to os.popen()?

2006-07-15 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Steve Holden <[EMAIL PROTECTED]> wrote:

>If you are seeing alot of error messages you shoudl really redirect the 
>standard error to a file to avoid them cluttering up your console.

Surely a better technique would be to fix the errors causing the 
messages.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPU or MB Serial number

2006-07-15 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Sybren Stuvel <[EMAIL PROTECTED]> wrote:

>Bayazee enlightened us with:
>> How can I get CPU Serial number , or motherboard serial number with
>> python . I need an idetification of a computer 
>
>Not sure if that'll be sufficient. My serial numbers (according to
>'lshw' on Linux):

Hey, that's pretty cool, I didn't know about lshw before. It doesn't 
come with my SuSE 10.0 system, but it is available under Gentoo.

I tried on my Shuttle SN25P box, and it didn't report serial numbers for 
anything except the onboard Ethernet.

In general, the OP isn't going to get anything like a universally-usable 
serial number, apart from Ethernet MAC addresses.

By the way, lshw seems to think there's a second CPU on my box, but it's 
marked as "DISABLED" and has no capabilities. Is it really there, or 
just a figment of someone's imagination? :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading specific lines of a file

2006-07-16 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Fredrik
Lundh wrote:

> Bill Pursell wrote:
> 
>> Some might argue that this is not really doing
>> it in Python.  In fact, I would argue that!  But if
>> you're at a command prompt and you want to
>> see line 7358, it's much easier to type
>> % sed -n 7358p
>> than it is to write the python one-liner.
> 
> 'sed' is not recognized as an internal or external command,
> operable program or batch file.

You're not using Windows, are you?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading specific lines of a file

2006-07-16 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Yi Xing
wrote:

> I want to read specific lines of a huge txt file (I know the line #).
> Each line might have different sizes. Is there a convenient and fast
> way of doing this in Python? Thanks.

file("myfile.txt").readlines()[LineNr]

Convenient, yes. Fast, no. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coding style

2006-07-17 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Bob Greschke wrote:

> I'd go even one step further.  Turn it into English (or your favorite
> non-computer language):
> 
> 1. While list, pop.
> 
> 2. While the length of the list is greater than 0, pop.
> 
> Which one makes more sense?  Guess which one I like.  CPU cycles be
> damned.
> :)

One of my rules is, always program like the language actually has a Boolean
type, even if it doesn't. That means, never assume that arbitrary values
can be interpreted as true or false, always put in an explicit comparison
if necessary so it's obvious the expression is a Boolean.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Object Persistence Using a File System

2006-07-18 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Chris Spencer wrote:

> I've been looking for a method of transparent, scalable, and
> human-readable object persistence...

Don't do object persistence. What is an object? It's a combination of code
and data. Code structure is internal to your program--it has no business
being reflected in external data that may be saved to a persistent medium,
transmitted over an external channel or whatever. Otherwise when you
refactor your code, that external data no longer becomes readable without
major backward-compatibility hacks.

Use data abstraction instead: define a high-level data structure that is
independent of implementation details of your code. When you look at the
major data-interchange formats in use today--such as XML, ODF, MPEG,
WAV--there's a reason why none of them are built on object persistence.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coding style

2006-07-19 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Bruno Desthuilliers
wrote:

> Lawrence D'Oliveiro wrote:
>> In message <[EMAIL PROTECTED]>, Bob Greschke
>> wrote:
>> 
>> 
>>>I'd go even one step further.  Turn it into English (or your favorite
>>>non-computer language):
>>>
>>>1. While list, pop.
>>>
>>>2. While the length of the list is greater than 0, pop.
>>>
>>>Which one makes more sense?  Guess which one I like.  CPU cycles be
>>>damned.
>>>:)
>> 
>> 
>> One of my rules is, always program like the language actually has a
>> Boolean type, even if it doesn't.
> 
> Python has a boolean type.

A _proper_ boolean type would _have_ to be used in conditionals.

>> That means, never assume that arbitrary values
>> can be interpreted as true or false,
> 
> There's nothing to assume, and nothing arbitrary in it. It's all clearly
> defined in whole letters in the language references.

Not simply enough.

>> always put in an explicit comparison
>> if necessary so it's obvious the expression is a Boolean.
> 
> The fact that the expression is used in the context of a if statement is
> clearly enough to denote a boolean expression.

Which is an inconsistent use of the term "boolean" compared to your
statement above that "Python has a boolean type", is it not?

> Explicitly testing against a boolean is uselessly redundant...

Not sure this has anything with what I was saying.

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


Re: Coding style

2006-07-19 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Georg Brandl wrote:

> Lawrence D'Oliveiro wrote:
>> In message <[EMAIL PROTECTED]>, Bob Greschke
>> wrote:
>> 
>>> I'd go even one step further.  Turn it into English (or your favorite
>>> non-computer language):
>>> 
>>> 1. While list, pop.
>>> 
>>> 2. While the length of the list is greater than 0, pop.
>>> 
>>> Which one makes more sense?  Guess which one I like.  CPU cycles be
>>> damned.
>>> :)
>> 
>> One of my rules is, always program like the language actually has a
>> Boolean type, even if it doesn't. That means, never assume that arbitrary
>> values can be interpreted as true or false, always put in an explicit
>> comparison if necessary so it's obvious the expression is a Boolean.
> 
> You can do that, but it's not considered Pythonic. And it might be
> ineffective.
> 
> Other than in PHP, Python has clear rules when an object of a builtin type
> is considered false (i.e. when it's empty). So why not take advantage of
> this?

Because the clearest rule of all is that True is true, and False is false,
and that's all I want to have to remember.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mysqldb problem

2006-07-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, liupei
wrote:

> when I set mysql some fields collate utf8_bin, and then fetch these
> fields is array.array,not the string I expected

Can you post some example code?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to know if socket is still connected

2006-07-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Grant Edwards wrote:

> If the server has closed the connection, then a recv() on the
> socket will return an empty string "", and a send() on the
> socket will raise an exception.

Would that still apply when trying to send an empty string?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking File permissions

2006-07-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Anoop
wrote:

> Please tell me how to check the existence of a file and the read
> permission to the file using python script

Without knowing what your precise needs are, the best way is to open the
file and try to read from it. If that succeeds, then you've got read
access.

Checking permissions as a separate step from opening the file exposes your
code to a race condition where the permissions may be OK during the initial
check, but then change to deny access before the subsequent open.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Semantics of propagated exceptions

2006-07-21 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>,
Thomas Lotze wrote:

> Suppose you have a function f which, as part of its protocol, raises some
> standard exception E under certain, well-defined circumstances. Suppose
> further that f calls other functions which may also raise E. How to best
> distinguish whether an exception E raised by f has the meaning defined by
> the protocol or just comes from details of the implementation?

You can't. All the information necessary to identify the exception must be
in the exception object itself. If you want to distinguish between
exceptions raised by F and those raised by other functions called by F,
then they must be different exceptions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to threads. How do they work?

2006-07-21 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, gel
wrote:

> I am attempting to understand threads to use in a network app which I
> am writing.

It is written, somewhere in the philosophy of *nix programming, that threads
are a performance hack, to be avoided wherever possible. Use processes in
preference to threads.
-- 
http://mail.python.org/mailman/listinfo/python-list


Linux Kernel Testing--Why Python

2006-07-21 Thread Lawrence D'Oliveiro
Just came across this article
 from the
Ottawa Linux Symposium, which mentions (among other things) Martin Bligh's
presentation on the automated testing system used for the Linux kernel:

The test system is written in Python, and he discussed at length why
Python was chosen as the language for the system. He also spent some
time showing the audience test output from the system, and discussed why
other languages were not suitable for the test system.

He described Python as a language that meets the requirements for the
task because it is a language that is easy to modify and maintain, that
is not write-only, that has exception handling, is powerful but not
necessarily fast, is easy to learn, and has wide libraries of modules to
leverage.

He described Perl as a write-only language, and said that while people
can do amazing things with the shell, it is not appropriate for the
purpose. He said with a grin that he has a lot of respect for what
people can do in the shell, but none for choosing to do it that way in
the first place.

One thing he particularly likes about Python, he said, is its usage of
indentation. Unlike other languages, Bligh noted, Python is read by the
computer the same way as it is read by a person, resulting in fewer
bugs.

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


Re: Nested function scope problem

2006-07-21 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Justin 
Azoff wrote:

> Simon Forman wrote:
>> That third option seems to work fine.
> 
> Well it does, but there are still many things wrong with it
> 
> if len(tok) > 0:
> should be written as
> if(tok):

I prefer the first way. Besides, your way is sub-optimal.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to threads. How do they work?

2006-07-21 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Grant Edwards wrote:

> On 2006-07-21, Lawrence D'Oliveiro <[EMAIL PROTECTED]>
> wrote:
>> In message <[EMAIL PROTECTED]>, gel
>> wrote:
>>
>>> I am attempting to understand threads to use in a network app which I
>>> am writing.
>>
>> It is written, somewhere in the philosophy of *nix programming, that
>> threads are a performance hack, to be avoided wherever possible. Use
>> processes in preference to threads.
> 
> I've never understood the aversion people seem to have to
> threads.

Perhaps because with threads, data is shared by default. Whereas with
processes, it is private by default, and needs to be explicitly shared if
you want that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python newbie needs constructive suggestions

2006-07-21 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

>   b) give up on using an anonymous function and create a named "successor"
>   function with "def",

This is what you have to do. For some reason mr van Rossum has this aversion
to anonymous functions, and tries to cripple them as much as possible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to threads. How do they work?

2006-07-22 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Dennis Lee Bieber
wrote:

> On Sat, 22 Jul 2006 17:19:22 +1200, Lawrence D'Oliveiro
> <[EMAIL PROTECTED]> declaimed the following in
> comp.lang.python:
> 
>> 
>> Perhaps because with threads, data is shared by default. Whereas with
>> processes, it is private by default, and needs to be explicitly shared if
>> you want that.
> 
> Or just that the "name" "thread" was a late-comer for some of us...
> 
> The Amiga had "tasks" at the lowest level (these were what the core
> OS library managed -- that core handled task switching, memory
> allocation, and IPC [event flags, message ports]). "Processes" were
> scheduled by the executive, but had additional data -- like stdin/stdout
> and environment variables... all the stuff one could access from a
> command line. Or, confusing for many... Processes were "DOS" level,
> Tasks were "OS" level.

Or for a more up-to-date example, how about the Linux way, where "processes"
and "threads" are just two points on a spectrum of possibilities, all
controlled by options to the clone(2) system call.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Isn't there a better way?

2006-07-22 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, T wrote:

> 
> I am using an optparse to get command line options, and then pass them
> to an instance of another class:
> 
> 
> 
> # Class that uses optparse.OptionParser
> foo = Parse_Option()
> 
> # Class that does the real work
> bar = Processor()
> 
> bar.index = foo.options.index
> bar.output  = foo.options.output
> bar.run()
> 
> 
> 
> This works, but it feels hokey or unnatural to "pass" data from one
> class to another.  Isn't there a better way???

I don't see the problem. If you're calling a number of different routines in
the Processor class, all accessing the same data, then it makes perfect
sense to only pass it once.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Isn't there a better way?

2006-07-23 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Bruno Desthuilliers
wrote:

> Lawrence D'Oliveiro a écrit :
>
>> If you're calling a number of different routines in
>> the Processor class, all accessing the same data, then it makes perfect
>> sense to only pass it once.
> 
> Actually they are not "passed".

I think I'm going to plonk you.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Isn't there a better way?

2006-07-24 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steve
Holden wrote:

> Lawrence D'Oliveiro wrote:
>> In message <[EMAIL PROTECTED]>, Bruno Desthuilliers
>> wrote:
>> 
>> 
>>>Lawrence D'Oliveiro a écrit :
>>>
>>>
>>>>If you're calling a number of different routines in
>>>>the Processor class, all accessing the same data, then it makes perfect
>>>>sense to only pass it once.
>>>
>>>Actually they are not "passed".
>> 
>> 
>> I think I'm going to plonk you.
> 
> And the rest of comp.lang.python has to know about this because ... ?

Some of them might be worth plonking as well?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to force a thread to stop

2006-07-24 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

> Python has no threadicide method, and its absence is not an
> oversight. Threads often have important business left to do, such
> as releasing locks on shared data; killing them at arbitrary times
> tends to leave the system in an inconsistent state.

Perhaps another reason to avoid threads and use processes instead?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: micro authoritative dns server

2006-07-25 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

> I just want to know if anyone could help me in writing a code for
> minimal authoritative dns server.

You'll probably need to start by reading and understanding RFC1034 and
RFC1035.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subprocess quote problem

2006-08-19 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Adriano
Monteiro wrote:

> "Failed to open input file "/home/adriano/umit/test/targets" for reading
> QUITTING!"

Which is not the same as saying:

  "Failed to open input file /home/adriano/umit/test/targets for reading
  QUITTING!"

Spot the difference?

> command = ['nmap', '-T', 'Aggressive', '-n', '-F', '-iL',
> '"/home/adriano/umit/test/targets"']

Why exactly where you putting quotes within quotes in the path? That kind of
thing is only necessary when typing things on the shell command line, to
prevent the shell itself misinterpreting things, like putting word breaks
in the wrong places or having wrong behaviours triggered by special
characters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the ascii code of Chinese characters?

2006-08-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Fredrik
Lundh wrote:

> Gerhard Fiedler wrote:
> 
>>> No. ASCII characters range is 0..127 while Unicode characters range is
>>> at least 0..65535.
>> 
>> Actually, Unicode goes beyond 65535.
> 
> you may want to look up "at least" in a dictionary.

Maybe you need to do the same for "actually".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Permission Denied

2006-08-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, AlbaClause wrote:

> Then, to execute the file from from the shell prompt, I had to create a
> 'bin' directory in my home folder, cuz I didn't want to litter
> my /usr/local/bin folder with useless Python scripts.

Executable files can be kept anywhere, you don't need a special directory
for them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatic import PEP

2006-10-06 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Robert
Kern wrote:

> Lawrence D'Oliveiro wrote:
>> In message <[EMAIL PROTECTED]>,
>> Connelly Barnes wrote:
>> 
>>> The main point of autoimp is to make usage of the interactive Python
>>> prompt more productive by including "from autoimp import *" in the
>>> PYTHONSTARTUP file.
>> 
>> The main problem I have with your idea is that any kind of import
>> statement with wildcards in it automatically starts my bogosity meter
>> flashing its "RED ALERT" sign and clanging all its alarm bells.
> 
> "from ... import *" was *designed* for interactive use, which is exactly
> what Connelly is suggesting. It's not a bad thing in that context.

But there is nothing in the language that constrains its use to that
context, is there?

Clang, clang...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Makin search on the other site and getting data and writing in xml

2006-10-06 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Paul
Boddie wrote:

> Various sites forbid wget and friends as a rule, understandably ...

No, that is not understandable.

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


Re: Recursive descent algorithm able to parse Python?

2006-10-06 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Diez B. Roggisch wrote:

> I have to admit that I have difficulties to compare LR(k) to recursive
> descent, but the fact that the latter contains backtracking makes it at
> least more powerful than LL(k)

LR(k) is more powerful than LL(k).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A critique of cgi.escape

2006-10-07 Thread Lawrence D'Oliveiro
Another useful function is this:

def JSString(Str) :
"""returns a JavaScript string literal that evaluates to Str. Note
I'm not worrying about non-ASCII characters for now."""
Result = []
for Ch in Str :
if Ch == "\\" :
Ch = ""
elif Ch == "\"" :
Ch = "\\\""
elif Ch == "\t" :
Ch = "\\t"
elif Ch == "\n" :
Ch = "\\n"
#end if
Result.append(Ch)
#end for
return "\"" + "".join(Result) + "\""
#end JSString

This can be used, for instance in

sys.stdout.write \
  (
"window.setTimeout(%s, 1000)\n"
%
JSString("alert(%s)" % JSString("Hi There!"))
  )

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


Re: Making sure script only runs once instance at a time.

2006-10-07 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Tim
Williams wrote:

> On 29/09/06, Matthew Warren <[EMAIL PROTECTED]> wrote:
>> I have found that in real usage of other programs within the company that
>> use lockfiles, it sometimes causes a bit of troubleshooting time when it
>> stops working due to a stale lockfile.. This especially happens when the
>> program is killed, the lockfile remains and causes minor annoyance (to
>> somebody who knows that is, more annoyance to somebody who doesn't).
> 
> Then they were checking for the wrong thing :)  Chcking for a lock
> file's existance is prone to the above problem.

My script deals with this
.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: People's names (was Re: sqlite3 error)

2006-10-07 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steve
Holden wrote:

> John Machin wrote:
>
> [lots of explanation about peculiarities of people's names]
>
> While I don't dispute any of this erudite display of esoteric
> nomenclature wisdom the fact remains that many (predominantly Western)
> databases do tend to use first and last name (in America often with the
> addition of a one- or two-character "middle initial" field).

Just because most Western designers of databases do it wrong doesn't mean
that a) you should do it wrong, or b) they will continue to do it wrong
into the future, as increasing numbers of those designers come from Asian
and other non-Western backgrounds.

> So, having distilled your knowledge to its essence could you please give
> me some prescriptive advice about what I *should* do? :-)

Has anyone come up with a proper universal table design for storing people's
names?

Certainly "first name" and "last name" are the wrong column names to use. I
think "family name" and "given names" would be a good start. For the
Icelanders, Somalians and the Muslims, their father's name goes in
the "family name" field, which makes sense because all their siblings (of
the same sex, at least) would have the same value in this field.

I wonder if we need another "middle" field for holding the "bin/binte" part
(could also hold, e.g. "Van" for those names that use this).

There would also need to be a flag field to indicate the canonical ordering
for writing out the full name: e.g. family-name-first, given-names-first.
Do we need something else for the Vietnamese case?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error handling in user input: is this natural or just laborious

2006-10-07 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, James Stroud
wrote:

> Patently. Tabs should be reserved for tables, for which tabs were named.
> If they were meant to be used for indenting, they would have been
> named "indenters". 

Really? I thought they were for tabulators
.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error handling in user input: is this natural or just laborious

2006-10-07 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, sam
wrote:

> i'm still in the early stages, and am trying to code something simple
> and interactive to get the percentages of the portfolio in the five
> different investment categories. i thought i'd get in with the error
> handling early so if someone types in something wrong (like a word), or
> the numbers don't add up to 100%, the error would be caught immediately
> and the user sent back to the start of the loop. granting that there
> may be better ways of doing this, if i decide that i do want to do it
> like this (i.e. a single error requires all data to be re-entered, not
> unreasonable for only five items) ...

One obvious thing is to remove repetitiveness from the code by collecting
the different cases in a data table. E.g.

data = {}
input_control = \
[
{
"key" : "cash",
"description" : "cash percentage",
"type" : int,
"describe_type" : "number",
},
{
"key" : "bond",
"description" : "bond portfolio",
"type" : int,
"describe_type" : "number",
},
{
"key" : "blue",
"description" : "blue-chip percentage",
"type" : int,
"describe_type" : "number",
},
{
"key" : "tech",
"description" : "tech stocks percentage",
"type" : int,
"describe_type" : "number",
},
{
"key" : "dev",
"description" : "developing countries percentage",
"type" : int,
"describe_type" : "number",
},
]

while True :
index = 0
while index != len(input_control) :
control = input_control[index]
try :
data[control["key"]] = \
control["type"](raw_input(
"Please enter a %s index for the portfolio: "
%
control["description"]
))
index += 1
except ValueError :
print "That is not a %s." % control["describe_type"]
#end try
#end while
if sum([data[k] for k in data]) == 100 :
break
print "Those numbers do not sum to 100. Please start again."
#end while

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


Re: Names changed to protect the guilty

2006-10-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, John
Machin wrote:

> 
> Steven D'Aprano wrote:
>> On Fri, 06 Oct 2006 18:29:34 -0700, John Machin wrote:
>>
>> >
>> > MonkeeSage wrote:
>> >> On Oct 6, 8:02 pm, "MonkeeSage" <[EMAIL PROTECTED]> wrote:
>> >> > it is clearer to you to make the condition explicit ("blah not
>> >> > False"),
>> >>
>> >> "blah not False" -> "blah is False"
>> >
>> > Whichever way your team wants to interpret it, d00d.
>> >
>> > Please consider whether you should be writing "(blah is False) is
>> > True", that would be more explicit.
>>
>> Puh-lease! Get it right!
>>
>> It should be "((blah is False) is True) is True".
>>
> 
> Yes, but it stops after one more iteration. "What I tell you three
> times is true" -- the Bellman, "The Hunting of the Snark", by Lewis
> Carroll.

But that was only said once, wasn't it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kde Taskbar

2006-10-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, David Boddie
wrote:

> I'd be interested in an example of how to use knotify via DCOP.

Found a tutorial here .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: People's names (was Re: sqlite3 error)

2006-10-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, John
Machin wrote:

> Two problems so far:
> (1) If you then assume that you should print the phone directory in
> order of family name, that's not appropriate in some places e.g.
> Iceland; neither is addressing Jon Jonsson as "Mr Jonsson", and BTW it
> can be their mother's name e.g. if she has more fame or recognition
> than their father.

Your bringing up the phone directory is a good point. That's probably the
most widely-consulted list of people's names around, so it's worthwhile
following whatever conventions are laid out in each country/region's phone
books. (There's also the electoral roll, I suppose, but I would assume that
follows the same sorts of conventions as the phone book.)

> (2) Arabic names: you may or may not have their father's name. You
> might not even have the [usually only one] given name. For example: the
> person who was known as Abu Musab al-Zarqawi: this means "father of
> Musab, the man from Zarqa [a city in Jordan]". You may have the family
> name as well as the father's and grandfather's given name. You can have
> the occupation, honorifics, nicknames. For a brief overview, read this:
> http://en.wikipedia.org/wiki/Arabic_names

The question for me is: which part of his name would he share in common with
his brothers and sisters? That's the part I would call the "family name".

One might raise the issue of using names to trace genealogies, origins etc,
but that's not my concern here. I'm just trying to come up with a way to
represent names of individuals, in such a way that they can easily be found
(as in, for example, the local phone book).

>> I wonder if we need another "middle" field for holding the "bin/binte"
>> part (could also hold, e.g. "Van" for those names that use this).
> 
> Not a good idea, IMHO. Consider "Nguyen Van Tran" vs 'Rembrandt van
> Rijn". Would you peel the Da off Da Costa but not the D' off
> D'Oliveiro? What do you do with the bod who fills in a form as Dermot
> O'Sullivan one month and Diarmaid Ó Súilleabháin the next?

The obvious question is, what does the local phone book do? How do the Dutch
phone books deal with all the "vans", and the Irish ones with all the "O"
or "O'"s? Do they put them under V and O respectively, or do they ignore
that part and look at the rest of the family name (which would make mor
sense to me)?

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

Re: testing machine responsiveness

2006-10-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Tim Arnold wrote:

> try:
> s.connect((cpu,7))
> except:
> return 0
> try:
> s.send('test')
> s.recv(128)
> s.close()
> return 1
> except:
> return 0

Call me nervous, but I like to make my "except" clauses as specific as
possible, to catch only the errors I'm expecting. This is to minimize the
chance of some hidden bug sneaking through and causing the wrong behaviour.

> 
> try:
> rup = os.popen('rup %s | sort -n -t, -k4 | grep day' %
> (self.asString))
> except OSError:
> return self.asList

So if the rup call fails, you're returning a plain list of all the
hostnames? Won't this cause the following parsing to fail?

If you're going to trigger a failure, isn't it better for it to happen as
close as possible to the actual cause? In other words, take out the
try/except block above and let the os.popen call itself directly signal an
exception on failure.

Disclaimer: I've never actually used rup. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Asychronous execution *with* return codes?

2006-10-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>,
utabintarbo wrote:

> Justin wrote:
>> If you're on a POSIX system, you could use the usual fork/exec/wait:
>> 
> Sorry. Win32. We are only allowed spoons - no sharp objects. :-P

How about installing Cygwin, then, and running under that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI Tutorial

2006-10-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steve
Holden wrote:

> Credit card numbers should be encrypted in the database, of course, but
> they rarely are (even by companies whose reputations imply they ought to
> know better).

How would encryption help? They'd still have to be decrypted to be used.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI Tutorial

2006-10-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Clodoaldo
Pinto Neto wrote:

> 2006/10/4, Tim Chase <[EMAIL PROTECTED]>:
>
>> The code is very dangerous...allowing any ol' schmoe to run
>> arbitrary code on your server.  At the barest of minimums, I'd
>> plaster the code with warnings that this is a Very Dangerous
>> Thing(tm) to do.
> 
> I though the danger was so obvious that i didn't bother. Now i have
> issued a warning.

I wonder whether warnings are enough. People are still going to copy and
paste the dodgy code from your tutorial into their site. The only way
around this is to offer good, robust code to begin with.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: changing a file's permissions

2006-10-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Max
Erickson wrote:

> James <[EMAIL PROTECTED]> wrote:
>
>> So my question is: how does one change a file's permissions
>> inside of python?
> 
> Assuming you want to operate on the output file:
> 
> import os
> os.chmod(path, 755)

Shouldn't that be

os.chmod(path, 0755)

? Only 755 decimal is unlikely to be a meaningful mode...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do this?

2006-10-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Duncan Booth wrote:

> Corrado Gioannini <[EMAIL PROTECTED]> wrote:
> 
>> I often do things like this:
>> 
>>   sql = a_complex_select_sql % (id_foo, value_bar, ...)
>>   cursor.execute(sql)
>> 
>> inside the body of a function (or a class method), where
>> a_complex_select_sql is a string, containing several %s, %d ecc.,
>> that is defined globally (or somewhere else in the class).
>> 
> I hope you have a good reason why you don't do:
> 
>   cursor.execute(a_complex_select_sql, (id_foo, value_bar, ...))
> 
> instead.

I use the above when I can, when I can't I fall back on
,
.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Why do this?

2006-10-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Tim
Golden wrote:

> [Matthew Warren]
> | But nowadays, I see things like this all over the place;
> | 
> | print("There are %s ways to skin a %s" % (number, furryanimal))
> 
> The outermost brackets are (at the moment) unnecessary in python,
> altho' print is slated for replacement by a function in Python 3.0
> at which point they'll be necessary.

Why bother? What would then be the advantage of using print over
sys.stdout.write?

I thought the existing print statement was a convenience for interactive
use, newbie tutorials and the like. If it's going to become a function, why
not use the function that's already there?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do this?

2006-10-09 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Duncan Booth wrote:

> Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote:
> 
>> I use the above when I can, when I can't I fall back on
>><http://groups.google.co.nz/[EMAIL PROTECTED]>,
>><http://groups.google.co.nz/[EMAIL PROTECTED]>.
> 
> Yes, so you said, but you never came up with a convincing use case where
> that function was better than using the parameterised queries.

First of all, the parametrization doesn't handle wildcards, as we discussed
previously.

Secondly, it's less convenient for cases where a dynamic query is being
built. I previously gave the SQLStringList example. If that's not enough,
here's another (simple) one:

Conditions = []
if Name != None :
Conditions.append("name = %s" % SQLString(Name))
#end if
if Address != None :
Conditions.append("address = %s" % SQLString(Address))
#end if
if PhoneNr != None :
Conditions.append("phone_nr = %s" % SQLString(PhoneNr))
#end if
Query = "select * from table"
if len(Conditions) != 0 :
Query += " where " + " and ".join(Conditions)
#end if
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: People's names (was Re: sqlite3 error)

2006-10-09 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Hendrik van
Rooyen wrote:

> "Lawrence D'Oliveiro" <[EMAIL PROTECTED]> wrote:
> 
> 8<
> 
>> I wonder if we need another "middle" field for holding the "bin/binte"
>> part (could also hold, e.g. "Van" for those names that use this).
> 
> NO! - I think of my surname as "van Rooyen" - its only a string with a
> space in it - and its peculiar in that the first letter is not
> capitalised
> 
> And I am sure that the people called "von Kardorff" would not agree
> either...

So do the Dutch phone books have a lot of entries under V, then?

It just seems less efficient to me, that's all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI Tutorial

2006-10-09 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steve
Holden wrote:

> Lawrence D'Oliveiro wrote:
>> In message <[EMAIL PROTECTED]>, Steve
>> Holden wrote:
>> 
>> 
>>>Credit card numbers should be encrypted in the database, of course, but
>>>they rarely are (even by companies whose reputations imply they ought to
>>>know better).
>> 
>> How would encryption help? They'd still have to be decrypted to be used.
> 
> Indeed they would, but with proper key management the probability that
> they can be stolen from a database in their plaintext form is rather
> lower. Just last week a police employee in my class told us of an
> exploit where a major credit card copmany's web site had been hacked
> using a SQL injection vulnerability. This is usually done with the
> intent of gaining access to credit card data.

If they can do that, it doesn't seem much of a step to compromise the code
that decrypts the credit card data, as well. Keeping it encrypted, when the
key needs to be kept at the same (in)security level, is just
security-through-obscurity.
-- 
http://mail.python.org/mailman/listinfo/python-list


So what would Python be?

2006-06-03 Thread Lawrence D'Oliveiro


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


Re: Large Dictionaries

2006-06-05 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Scott David Daniels <[EMAIL PROTECTED]> wrote:

>For example, time timsort (Python's internal sort) on pre-sorted
>data; you'll find it is handled faster than random data.

But isn't that how a reasonable sorting algorithm should behave? Less 
work to do if the data is already sorted?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: summarize text

2006-06-05 Thread Lawrence D'Oliveiro
... sorry, I thought you said "summarize Proust".

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


Re: Large Dictionaries

2006-06-08 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Tim Peters" <[EMAIL PROTECTED]> wrote:

>For example, the O(N log N) heapsort is unreasonable compared to the
>O(N**2) bubblesort by that reasoning (pre-sorted is actually a bad
>case for heapsort, but a good case for bubblesort)?  O(N log N)
>sorting algorithms helped by pre-existing order are uncommon, unless
>they do extra work to detect and exploit pre-existing order.

Shellsort works well with nearly-sorted data. It's basically a smarter 
version of bubblesort with much improved efficiency. It's also very 
compact to implement.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Large Dictionaries

2006-06-08 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Iain King" <[EMAIL PROTECTED]> wrote:

>Lawrence D'Oliveiro wrote:
>> In article <[EMAIL PROTECTED]>,
>>  Scott David Daniels <[EMAIL PROTECTED]> wrote:
>>
>> >For example, time timsort (Python's internal sort) on pre-sorted
>> >data; you'll find it is handled faster than random data.
>>
>> But isn't that how a reasonable sorting algorithm should behave? Less
>> work to do if the data is already sorted?
>
>An already sorted list can be pathological for Quicksort, depending on
>how you code it.

I did say "reasonable". :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to generate all permutations of a string?

2006-06-22 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Girish Sahani" <[EMAIL PROTECTED]> wrote:

>  I want to generate all permutations of a string.

def permute(Seq) :
"""generator which yields successive permutations of the elements
of Seq."""
if len(Seq) == 0 :
yield ()
else :
for i in range(0, len(Seq)) :
for rest in permute(Seq[:i] + Seq[i + 1:]) :
yield (Seq[i],) + rest
#end for
#end for
#end if
#end permute
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cycles between package imports

2006-06-22 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Martin Blais" <[EMAIL PROTECTED]> wrote:

>On 18 Jun 2006 05:25:14 -0700, John Roth <[EMAIL PROTECTED]> wrote:
>
>> The general rule is: don't do that. It doesn't work, and the
>> hoops you have to go through to force it to work are so
>> complex and bizzare that they're not worth it.  Redesign
>> the modules so you don't have cyclic dependencies.
>
>This is a matter completely aside the question.

No it isn't. I agree with John Roth.

>Whether it's worth it
>or not depends on the specific case --not included in the example--
>and in the case where it shows up in my code, removing the cycle
>actually made sense (it does, most of the time, but not always).

See, even you are unable to come up with an example where a cyclic 
import makes sense.

In general, the complications they introduce are simply not worth it. 
This was discovered decades ago, during the development of languages 
like Ada and Modula-2 which could do automatic initialization and 
finalization of library modules arranged by the compiler/linker system.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popen2 question

2006-06-25 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 David Bear <[EMAIL PROTECTED]> wrote:

>I'm using popen2 and getting an extra 1 at the end of my output. I didn't
>see where this was explained in the docs so I clearly don't understand the
>behavior. My code is simple.
>
>(input, output) = os.popen2('whackyperlprogram')
>results = output.read()
>rc = output.close()
>print results

What if, for comparison, you try running a trivial program that produces 
no output:

(input, output) = os.popen2('/bin/true')
results = output.read()
rc = output.close()
print results

Do you still get the "1" at the end?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python taught in schools?

2006-06-26 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Alex Martelli) wrote:

>... let's try some google searches and see the number of million hits...:

But how reliable are those estimates of numbers of hits, anyway? More 
than once I've got a page showing something like "Results 1 - 10 of 
about 36 hits", only to find that there were no more pages after the 
second one. If it could get estimates so wrong with such small numbers, 
how can you trust the large ones?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python taught in schools?

2006-06-26 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Mirco Wahab <[EMAIL PROTECTED]> wrote:

>C++ programming requires you to massively invest your thinking
>first into the setup of your build environment ...

I don't understand why. It's easy enough to build small programs with a 
single g++ command.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python taught in schools?

2006-06-26 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Mirco Wahab <[EMAIL PROTECTED]> wrote:

>Thus spoke Lawrence D'Oliveiro (on 2006-06-26 09:21):
>
>> In article <[EMAIL PROTECTED]>,
>>  Mirco Wahab <[EMAIL PROTECTED]> wrote:
>> 
>>>C++ programming requires you to massively invest your thinking
>>>first into the setup of your build environment ...
>> 
>> I don't understand why. It's easy enough to build small programs with a 
>> single g++ command.
>
>Think about beeing a young guy with a
>windows pc at home.
>
>To make sense of your 45 min C++
>class, you need to practice the
>stuff at home for sure, I'd guess.
>
>Now go ahead! What would you do?

Download a Linux distro with a complete GCC, Emacs, GDB etc. Then go 
wild.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python taught in schools?

2006-06-26 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Gary Duzan) wrote:

>   I understand that the school switched [from C++] to Java a short
> time later,  which is some improvement, but still has a good bit of
> baggage.

Java started out trying to avoid most of the complexities of C++, but 
ended up having to reintroduce many of them anyway.

>p.s. Then sock them with ML or Haskell to weed out the weak ones. ;-)
> Then if they survive Occam, throw Java at them, so they'll
> know what they are missing but can still get a job...

And yet, because they didn't start with Java, they'll still have the 
ability to think. Which is bound to annoy PHBs out in the "real" world 
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Having problems with strings in HTML

2006-06-26 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Kiana Toufighi <[EMAIL PROTECTED]> wrote:

>print '''
>href="http://bbc.botany.utoronto.ca/ntools/cgi-bin/ntools_treeview_word.cgi?inp
>ut=&max=2&values_off=no&remove_bracket=no&show_line_nr=yes&show_link_out=yes&de
>cimal_places=10&show_classification=yes&db=arabidopsis&selection=any%20term&mod
>e=&mode_nos=&yellow_blue=yes&local_file_name=%(OUT_FILE_NAME)s&show_instruction
>s=no&expt_link=NASCArrays&max_adjust=2&view_size=large&highlight=%(HI_LITE_FILE
>_NAME)s">GraphicalOutput
> ''' % {'OUT_FILE_NAME': OUT_FILE_NAME, 'HI_LITE_FILE_NAME': 
>HI_LITE_FILE_NAME}

By the way, you _do_ realize that your "&" characters should be escaped 
as "&", don't you?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Execute Commands on Remote Computers over Network

2006-06-26 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "dylpkls91" <[EMAIL PROTECTED]> wrote:

>I have been researching this topic and come up with some code to make
>it work. It uses SSL and requires the 3rd party package Paramiko (which
>requires PyCrypto).

Why not just spawn an invocation of SSH?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Having problems with strings in HTML

2006-06-28 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Richard Brodie" <[EMAIL PROTECTED]> wrote:

>"Sion Arrowsmith" <[EMAIL PROTECTED]> wrote in message 
>news:[EMAIL PROTECTED]
>
>>>By the way, you _do_ realize that your "&" characters should be escaped
>>>as "&", don't you?
>>
>> No they shouldn't. They part of the url, which is (IIRC) a CDATA
>> attribute of the A element, not PCDATA.
>
>It is CDATA but ampersands still need to be escaped. 

I believe it's common for CGI argument-parsing routines to accept ";" as 
a synonym for "&" as the argument separator. Certainly the code I use 
does.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Select in Python

2006-06-29 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Gary Herron <[EMAIL PROTECTED]> wrote:

>If you want select to start blocking again, you must read all bytes from
>stdin whenever select says there are bytes to be read.

To add to this, it is a good idea to read the select_tut(2) man page, 
particularly the "SELECT LAW" section. There's a lot of dos and don'ts 
there on how to avoid common bugs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Execute Commands on Remote Computers over Network

2006-06-29 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "dylpkls91" <[EMAIL PROTECTED]> wrote:

>Lawrence D'Oliveiro wrote:
>> In article <[EMAIL PROTECTED]>,
>>  "dylpkls91" <[EMAIL PROTECTED]> wrote:
>>
>> >I have been researching this topic and come up with some code to make
>> >it work. It uses SSL and requires the 3rd party package Paramiko (which
>> >requires PyCrypto).
>>
>> Why not just spawn an invocation of SSH?
>
>Can you explain what this means, and how I could do it in Python?

SSH is the standard means of remotely executing commands on one *nix 
system from another <http://www.openssh.com/>. It is included with all 
self-respecting *nix systems these days. You can set up a trust 
relationship between particular accounts on two systems, so one can 
connect to the other without a password. All communication is encrypted 
to lock out eavesdroppers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Passing a Cookie with httplib

2006-06-29 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

>I would like to
>hard code the cookie in the code so it works every time:   
>
>i.e. cookie = 'auth=buster%3A12345678901234567890exZ9rzMqgtxa5A'.  
>
>conn=httplib.HTTPConnection(WP_SERVER)
>conn.request('GET',WP_PATH % uservalue)

According to , 
you can pass additional "body" and "headers" args to 
HTTPConnection.request. How about trying something like this in place of 
the last line above:

Headers = {"Cookie" : 
"auth=buster%3A12345678901234567890exZ9rzMqgtxa5A"}
conn.request('GET',WP_PATH % uservalue, None, Headers)
-- 
http://mail.python.org/mailman/listinfo/python-list


Python docs bug

2006-06-29 Thread Lawrence D'Oliveiro
One long-standing irritation I have with the table of contents for the 
Python Library Reference , is that 
there is one very important section, "String Methods" 
, which does not appear 
there. That's because it is section 2.3.6.1, and the table of contents 
only goes to 3 levels.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interprocess communication on multi-user machine

2006-06-30 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Michael Butscher <[EMAIL PROTECTED]> wrote:

>Normally any user could connect to an open socket on a machine 
>regardless which user established the socket (the user's program, to be 
>precise). 

That's not true. On *nix systems, a socket is a file, and is subject to 
the usual file ownership and protection mechanisms.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interprocess communication on multi-user machine

2006-06-30 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Nick Maclaren) wrote:

>In article <[EMAIL PROTECTED]>,
>Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes:
>|> In article <[EMAIL PROTECTED]>,
>|>  Michael Butscher <[EMAIL PROTECTED]> wrote:
>|> 
>|> >Normally any user could connect to an open socket on a machine 
>|> >regardless which user established the socket (the user's program, to be 
>|> >precise). 
>|> 
>|> That's not true. On *nix systems, a socket is a file, and is subject to 
>|> the usual file ownership and protection mechanisms.
>
>I am afraid that BOTH answers are badly wrong!
>
>Sockets are often accessed via special files, but are not files.

They are files. They are not _regular_ files.

>They may also be accessed by port numbers, for example.

UNIX sockets have no ports.

>Secondly, even when they are accessed via files, FIFOs generally
>do NOT use the usual file ownership and protection mechanisms to
>control access.

I wasn't talking about FIFOs. Even if I was, they _are_ still subject to 
regular file permissions (on Linux, at least).

>While any user can attempt to open any socket accessed by port
>number...

UNIX sockets have no ports.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interprocess communication on multi-user machine

2006-07-01 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Nick Maclaren) wrote:

>In article <[EMAIL PROTECTED]>,
>Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes:
>|> >
>|> >Sockets are often accessed via special files, but are not files.
>|> 
>|> They are files. They are not _regular_ files.
>
>Yes, I know about UNIX-domain sockets, but even when they give the
>appearance of being files, 90% of the time that is the API only,
>and the underlying facility is very different.

Irrelevant. The userland API requires accessing a file, which is subject 
to standard *nix file ownerships and protections.

>Dammit, processes
>are not files just because they happen to have a /proc entry under
>many systems!

They are files. They have all the semantics of files. Under Linux they 
are in fact directories, but those are still files.

They are not files with blocks allocated on some physical disk 
partition, but that doesn't make them any the less files.

>|> I wasn't talking about FIFOs. Even if I was, they _are_ still subject to 
>|> regular file permissions (on Linux, at least).
>
>They aren't on most Unices - Linux is not UNIX, you know :-)

I'm not aware of any *nix system worthy of the name where they are not. 
The "everything-is-a-file" concept is deeply ingrained into the whole 
*nix philosophy.

>I shall not respond further on this.

One can hope...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb not updating rows

2006-07-01 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Bowen" <[EMAIL PROTECTED]> wrote:

>In article <[EMAIL PROTECTED]>, Benjamin Niemann <[EMAIL PROTECTED]> 
>wrote:
>
>>Another side note: don't build your queries using (dumb) string formatting,
>>let the MySQLdb module do it for you.
>
>Thanks for that tip, it's a simple script that I am experimenting on,
>planning to build a custon gui for my database. It is defin[i]tely
>something for me to note in the future.

Best get into the habit of doing careful quoting NOW, not "in the 
future". Otherwise you will inadvertently leave yourself open to an SQL 
injection attack at some point in the future.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: slow non-blocking reads

2006-07-01 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Mark Dufour" <[EMAIL PROTECTED]> wrote:

>any thoughts about why this runs extremely slowly?

Because both processes are chewing up most of your CPU each waiting for 
the other to do something.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sys.stdin and two CTRL-Ds

2006-07-01 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 John Machin <[EMAIL PROTECTED]> wrote:

>-u unbuffers sys.stdout 
>and sys.stderr (and makes them binary, which wouldn't be a good idea on 
>a Windows box).

Why not?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I do it using python?? about xterm and telnet

2006-07-02 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "valpa" <[EMAIL PROTECTED]> wrote:

>I'm a net admin for about 20 unix servers, and I need to frequently
>telnet on to them and configure them.
>It is a tiring job to open a xterm and telnet, username, password to
>each server.

Do you need to replicate identical configurations to all the servers?

If so, perhaps you're approaching this the wrong way. A better solution 
might be to look at replicating the config files directly to all 
machines (using rsync, scp etc), rather than editing them in situ on 
every single one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I do it using python?? about xterm and telnet

2006-07-02 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "placid" <[EMAIL PROTECTED]> wrote:

>Jim Segrave wrote:
>
>> Don't use telnet. it's clumsy and has security issues.
>
>if youre behind a firewall then it shouldnt matter.

Still not a good idea.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sys.stdin and two CTRL-Ds

2006-07-02 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 John Machin <[EMAIL PROTECTED]> wrote:

>On 2/07/2006 3:48 PM, Lawrence D'Oliveiro wrote:
>> In article <[EMAIL PROTECTED]>,
>>  John Machin <[EMAIL PROTECTED]> wrote:
>> 
>>> -u unbuffers sys.stdout 
>>> and sys.stderr (and makes them binary, which wouldn't be a good idea on 
>>> a Windows box).
>> 
>> Why not?
>
>If binary, '\n' would appear as LF alone rather than CR LF.

Why should that matter? I thought Windows (the NT line) was 
POSIX-compliant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sys.stdin and two CTRL-Ds

2006-07-03 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 John Machin <[EMAIL PROTECTED]> wrote:

>On 3/07/2006 4:45 PM, Lawrence D'Oliveiro wrote:
>
>> I thought Windows (the NT line) was 
>> POSIX-compliant.
>
>What on earth gave you that idea?

<http://fuckinggoogleit.com/?query=windows+nt+posix>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I do it using python?? about xterm and telnet

2006-07-03 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "valpa" <[EMAIL PROTECTED]> wrote:

>I don't care about security issue by now :), because every one in my
>compony know the username/password.

Then why bother with a password at all?
-- 
A: Skid-marks in front of the hedgehog.
Q: What's the difference between a dead hedgehog on the road, and a dead 
top-poster on the road?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turning a callback function into a generator

2006-07-03 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Kirk McDonald <[EMAIL PROTECTED]> wrote:

>I want to somehow, in some way, provide an iteration interface to this 
>function. Thoughts?

Run it in a separate thread/process?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: slow non-blocking reads

2006-07-05 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Mark Dufour" <[EMAIL PROTECTED]> wrote:

>interestingly, leaving out the fcntl stuff makes it work much faster.

No surprises there...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange i/o delay problem in socket

2006-07-07 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

>while in most cases, the time needed for a handler thread to read the
>request line from the socket is below 1 millisecond, there are some
>cases this time is over severl thousand (or even higher) milliseconds.
>I'm just wondering what could be the possible cause(s) of this ? btw,
>this happens more often when there are large number of clients, but
>will also happen ocassionally when the number of client is very
>small

It could just be occasional packet loss over your physical network--i.e. 
something outside your control.

Not sure how you'd test this, except by running a packet sniffer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Detecting 64bit vs. 32bit Linux

2006-07-10 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 dwelch91 <[EMAIL PROTECTED]> wrote:

>I need to detect whether the operating system I am running on (not the 
>Python version) is 64bit or 32bit. One requirement is that I need to 
>include support for non-Intel/AMD architectures.

The standard C way would be to check sizeof(void *).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running multiple versions of Python on the same host..

2006-07-10 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Cowmix" <[EMAIL PROTECTED]> wrote:

>What is the best way to run multiple version of Python on the same
>system?

You could use chroot. Ask if you want more details.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Detecting 64bit vs. 32bit Linux

2006-07-11 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Robin Becker <[EMAIL PROTECTED]> wrote:

>Michael Yanowitz wrote:
>..
>> 
>>> I need to detect whether the operating system I am running on (not the 
>>> Python version) is 64bit or 32bit. One requirement is that I need to 
>>> include support for non-Intel/AMD architectures.
>> 
>> The standard C way would be to check sizeof(void *).
>so on those old ARM RISC OSes with 32 bit arithmetic would I get sizeof(void 
>*) 
>== 4 when the address bus was 26 bits wide?

And the original 68000-based Macs where you would get the same 
sizeof(void *), but the address bus was only 24 bits wide. Nevertheless, 
you were supposed to pretend that addresses were a full 32 bits in size. 
The programs that didn't got into trouble later.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new string method in 2.5 (partition)

2006-09-22 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Gabriel
Genellina wrote:

> ... a python string has both a length *and* a null terminator (for
> ease of interfacing C routines ...

How does that work for strings with embedded nulls? Or are the C routines
simply fooled into seeing a truncated part of the string?
-- 
http://mail.python.org/mailman/listinfo/python-list


"re" vs "sre"?

2006-09-23 Thread Lawrence D'Oliveiro
I learned about Python regular expressions from the Web documentation
. This describes a module named "re".
Then I saw some code written by a colleague, and he was using a module
named "sre". I checked my Python 2.4.3 installation, and sure enough, I
have a module named "sre" as well as "re". Curious, I fired up an
interactive Python session, and looked to see what the docstrings were for
these modules. And for the "re" module, the help says:

re - Minimal "re" compatibility wrapper.  See "sre" for documentation.

and "sre" seems to have the more complete set of docstrings.

So which one should we be using?
-- 
http://mail.python.org/mailman/listinfo/python-list


A critique of cgi.escape

2006-09-23 Thread Lawrence D'Oliveiro
The "escape" function in the "cgi" module escapes characters with special
meanings in HTML. The ones that need escaping are '<', '&' and '"'.
However, cgi.escape only escapes the quote character if you pass a second
argument of True (the default is False):

>>> cgi.escape("the \"quick\" &  fox")
'the "quick" &  fox'
>>> cgi.escape("the \"quick\" &  fox", True)
'the "quick" &  fox'

This seems to me to be dumb. The default option should be the safe one: that
is, escape _all_ the potentially troublesome characters. The only time you
can get away with NOT escaping the quote character is outside of markup,
e.g.


unescaped "quotes" allowed here


Nevertheless, even in that situation, escaped quotes are acceptable.

So I think the default for the second argument to cgi.escape should be
changed to True. Or alternatively, the second argument should be removed
altogether, and quotes should always be escaped.

Can changing the default break existing scripts? I don't see how. It might
even fix a few lurking bugs out there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and checked exceptions

2006-09-23 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Kay
Schluehr wrote:

> A new cookbook recipe suggesting two decorators @throws and @catches
> for treatment of checked exceptions in Python:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498131
> 
> This might be of practical interest for some and theoretical interest
> for others - in particular those who know checked ex as a language
> feature of Java.

The trouble with having to declare every possible exception that a function
might throw is that it rapidly turns into a complete mess. That's why such
declarations are optional in C++, and only semi-mandatory in Java.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Isn't bool __invert__ behaviour "strange"?

2006-09-23 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Bjoern Schliessmann wrote:

> In my C++ code,
> it happens so often that I forget or overread a "!". And if I want
> to understand my functions later on, my brain quite wrinkles
> looking at parentheses, !s, &&s and ||s.

Which is why C++ allows "not", "and" and "or".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Isn't bool __invert__ behaviour "strange"?

2006-09-23 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>,
MonkeeSage wrote:

> I don't really see anything wrong with creating a custom class for
> evaluating those kinds of logical statements. It does make the code for
> statements more concise and easy to follow (with less binding
> ambiguity).

Why not express everything in Conjunctive Normal Form?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "re" vs "sre"?

2006-09-23 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Peter Otten wrote:

> Lawrence D'Oliveiro wrote:
> 
>> I learned about Python regular expressions from the Web documentation
>> <http://docs.python.org/lib/lib.html>. This describes a module named
>> "re". Then I saw some code written by a colleague, and he was using a
>> module named "sre". I checked my Python 2.4.3 installation, and sure
>> enough, I have a module named "sre" as well as "re". Curious, I fired up
>> an interactive Python session, and looked to see what the docstrings were
>> for these modules. And for the "re" module, the help says:
>> 
>> re - Minimal "re" compatibility wrapper.  See "sre" for
>> documentation.
>> 
>> and "sre" seems to have the more complete set of docstrings.
>> 
>> So which one should we be using?
> 
> Here's what Python 2.5 has to say on the matter:
>>>> import sre
> __main__:1: DeprecationWarning: The sre module is deprecated, please
> import re.

That's good. Does "help(re)" still say it's a "compatibility wrapper"?
-- 
http://mail.python.org/mailman/listinfo/python-list


QuoteSQL

2006-09-23 Thread Lawrence D'Oliveiro
Why doesn't MySQLdb provide a function like this:

def QuoteSQL(Str, DoWild) :
"""returns a MySQL string literal which evaluates to Str. Needed
for those times when MySQLdb's automatic quoting isn't good enough."""
Result = []
for Ch in str(Str) :
if Ch == "\0" :
Ch = "\\0"
elif Ch == "\010" :
Ch = "\\b"
elif Ch == "\011" :
Ch = "\\t"
elif Ch == "\012" :
Ch = "\\n"
elif Ch == "\015" :
Ch = "\\r"
elif Ch == "\032" :
Ch = "\\z"
elif Ch == "'" or Ch == "\"" or Ch == "\\" :
Ch = "\\" + Ch
elif DoWild and (Ch == "%" or Ch == "_") :
Ch = "\\" + Ch
#end if
Result.append(Ch)
#end for
return "\"" + "".join(Result) + "\""
#end QuoteSQL

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


Re: QuoteSQL

2006-09-23 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Anders J. Munch
wrote:

> Lawrence D'Oliveiro wrote:
>> Why doesn't MySQLdb provide a function like this:
>> 
>> def QuoteSQL(Str, DoWild) :
>> """returns a MySQL string literal which evaluates to Str. Needed
>> for those times when MySQLdb's automatic quoting isn't good
>> enough."""
> 
> Presumably because you're expected to use placeholders.  When is that
> not good enough?

Here's an example:

def QuoteSQLList(TheList) :
"""returns a MySQL list containing the items of TheList, suitable
for use in an "in" clause."""
return \
"(" + ", ".join([QuoteSQL(Str, False) for Str in TheList]) + ")"
#end QuoteSQLList

>> elif Ch == "'" or Ch == "\"" or Ch == "\\" :
>> Ch = "\\" + Ch
> 
> Always sad to see an SQL DBMS willfully violate the SQL standard.

Why is that a violation of SQL?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A critique of cgi.escape

2006-09-23 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Fredrik
Lundh wrote:

> Lawrence D'Oliveiro wrote:
> 
>> So I think the default for the second argument to cgi.escape should be
>> changed to True. Or alternatively, the second argument should be removed
>> altogether, and quotes should always be escaped.
> 
> you're confused: cgi.escape(s) is designed to be used for ordinary text,
> cgi.escape(s, True) is designed for attributes.

What works for attributes also works for ordinary text.

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


Re: A critique of cgi.escape

2006-09-23 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Jon Ribbens wrote:

> In article <[EMAIL PROTECTED]>, Fredrik
> Lundh wrote:
>> Lawrence D'Oliveiro wrote:
>>>
>>> So I think the default for the second argument to cgi.escape should be
>>> changed to True. Or alternatively, the second argument should be removed
>>> altogether, and quotes should always be escaped.
>> 
>> you're confused: cgi.escape(s) is designed to be used for ordinary text,
>> cgi.escape(s, True) is designed for attributes.  if you use the code the
>> way it's intended to be used, it works perfectly fine.
> 
> He's not confused, he's correct; the author of cgi.escape is the
> confused one.

Thanks for backing me up. :)

> > One thing that is flat-out wrong, by the way, is that cgi.escape() 
> does not encode the apostrophe (') character. This is essentially
> identical to the quote character in HTML, so any code which escaping
> one should always be escaping the other.

I must confess I did a double-take on this. But I rechecked the HTML spec
(HTML 4.0, section 3.2.2, "Attributes"), and you're right--single quotes
ARE allowed as an alternative to double quotes. It's just I've never used
them as quotes. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   7   8   9   10   >