Re: Prefered install method?

2007-01-25 Thread Gabriel Genellina

At Friday 26/1/2007 04:27, Tina I wrote:


So my question is; What is the preferred/ common way to install a python
application so it's not really distro specific? And are there any good
resources on this on the web?


distutils, included in the standard Python library. You surely have 
the docs installed, anyway you can read it online at 
http://docs.python.org/dist/dist.html


For the simplest case (your app only contains python modules) just 
write a setup.py file on the top directory of you application:


from distutils.core import setup
setup(name='appname',
version='1.0',
py_modules=['foo', 'bar'],
)

and execute: python setup.py sdist


--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: how to unistall a Python package?

2007-01-25 Thread Colin J. Williams
With Windows, a few packages, eg. PythonWin, also modify the registry. 
numpy, the elaboration of numarray/numeric, and PythonWin have 
RemoveXXX.exe in C:\Python25.

I don't know whether this is the standard approach.  There doesn't seem 
to be a reference to Removal in the distutils document.

Colin W.

Wang Shuhao wrote:
> Third party packages are put into $PYTHONHOME\Lib\site-packages after been 
> installed, so to uninstall them, just go there and delete the directory 
> contains all files of your package.
> 
> 
> - Original Message - 
> From: "siggi" <[EMAIL PROTECTED]>
> Newsgroups: comp.lang.python
> To: 
> Sent: Thursday, January 25, 2007 10:02 PM
> Subject: how to unistall a Python package?
> 
> 
>> Hi all,
>>
>> installing a package with 'setup.py' is easy. But how do I uninstall the
>> package, once I want to get rid of it again?
>>
>> Thanks,
>>
>> siggi
>>
>>
>>
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
>>

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


Re: The reliability of python threads

2007-01-25 Thread Hendrik van Rooyen
 "Carl J. Van Arsdall" <[EMAIL PROTECTED]> wrote:

> Right, I wasn't coming here to get someone to debug my app, I'm just 
> looking for ideas.  I constantly am trying to find new ways to improve 
> my software and new ways to reduce bugs, and when i get really stuck, 
> new ways to track bugs down.  The exception won't mean much, but I can 
> say that the error appears to me as bad data.  I do checks prior to 
> performing actions on any data, if the data doesn't look like what it 
> should look like, then the system flags an exception.
> 
> The problem I'm having is determining how the data went bad.  In 
> tracking down the problem a couple guys mentioned that problems like 
> that usually are a race condition.  From here I examined my code, 
> checked out all the locking stuff, made sure it was good, and wasn't 
> able to find anything.  Being that there's one lock and the critical 
> sections are well defined, I'm having difficulty.  One idea I have to 

Are you 100% rock bottom gold plated guaranteed sure that there is
not something else that is also critical that you just haven't realised is?

This stuff is never obvious before the fact - and always seems stupid
afterward, when you have found it.  Your best (some would say only)
weapon is your imagination, fueled by scepticism...

> try and get a better understanding might be to check data before its 
> stored.  Again, I still don't know how it would get messed up nor can I 
> reproduce the error on my own. 
> 
> Do any of you think that would be a good practice for trying to track 
> this down? (Check the data after reading it, check the data before 
> saving it)

Nothing wrong with doing that to find a bug - not as a general 
practice, of course - that would be too pessimistic.

In hard to find bugs - doing anything to narrow the time and place
of the error down is fair game - the object is to get you to read
some code that you *know works* with new eyes...

I build in a global boolean variable that I call trace, and when its on
I do all sort of weird stuff, giving a running commentary (either by
print or in some log like file) of what the programme is doing, 
like read this, wrote that, received this, done that here, etc.
A bare useful minimum is a "we get here" indicator like the routine
name, but the data helps a lot too.

Compared to an assert, it does not stop the execution, and you
could get lucky by cross correlating such "traces" from different
threads. - or better, if you use a queue or a pipe for the "log", 
you might see the timing relationships directly.

But this in itself is fraught with danger, as you can hit file size 
limits, or slow the whole thing down to unusability.

On the other hand it does not generate the volume that a genuine 
trace does, it is easier to read, and you can limit it to the bits that
you are currently suspicious of.

Programming is such fun...

hth - Hendrik



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


Re: Which BASTARD involved in Valerie Plame case? FINALLY EXPOSED

2007-01-25 Thread thermate
Libby trial pulls back White House curtain

Friday, January 26, 2007
By Dana Milbank, The Washington Post

WASHINGTON -- Memo to Tim Russert: Dick Cheney thinks he controls you.

This delicious morsel about the "Meet the Press" host and the vice
president was part of the extensive dish that Cathie Martin served up
yesterday, when the former Cheney communications director took the
stand in the perjury trial of former Cheney chief of staff I. Lewis
"Scooter" Libby.

Flashed on the courtroom computer screens were her notes from 2004
about how Mr. Cheney could respond to allegations that the Bush
administration had played fast and loose with evidence of Iraq's
nuclear ambitions. Option 1: "MTP-VP," she wrote, then listed the pros
and cons of a vice presidential appearance on the Sunday NBC television
show. Under the "pro" column, she wrote: "control message."

"I suggested we put the vice president on 'Meet the Press,' which was a
tactic we often used," Ms. Martin testified. "It's our best format."

It is unclear whether the first week of the trial will help or hurt Mr.
Libby or the administration. But the trial has already pulled back the
curtain on the White House's PR techniques and confirmed some of the
darkest suspicions of the reporters upon whom they are used.

Relatively junior White House aides run roughshod over members of the
president's Cabinet. Bush aides charged with speaking to the public and
the media are kept out of the loop on some of the most important
issues. And bad news is dumped before the weekend for the sole purpose
of burying it.

With a candor that is frowned upon at the White House, Ms. Martin
explained the use of late-Friday statements. "Fewer people pay
attention to it late on Friday," she said. "Fewer people pay attention
when it's reported on Saturday."

Ms. Martin --perhaps unaware of the suspicion that such machinations
caused in the press corps -- lamented that her statements at the time
were not regarded as credible. She testified that, as the controversy
swelled in 2004, reporters ignored her denials and continued to report
that it was Mr. Cheney's office that sent former Ambassador Joseph
Wilson to Niger to investigate allegations of Iraq's nuclear
acquisitions. "They're not taking my word for it," she recalled telling
a colleague.

Ms. Martin, who now works on the president's communications staff, said
she was frustrated that reporters wouldn't call for comment as the
controversy swelled. She said she had to ask CIA spokesman Bill Harlow
which reporters were working on stories about the flap. "Often,
reporters would stop calling us," she testified.

This prompted quiet chuckles among the two dozen reporters sitting in
court to cover the trial. Whispered one: "When was the last time you
called the vice president's office and got anything other than a 'no
comment'?"

At length, Ms. Martin explained how she, Mr. Libby and then-deputy
national security adviser Stephen Hadley worked late into the night
writing a statement to be issued by CIA boss George Tenet in 2004, in
which he would take blame for the bogus claim in Mr. Bush's State of
the Union address that Iraq was seeking nuclear material in Africa.

After "delicate" talks, Mr. Tenet agreed to say the CIA "approved" the
claim, and "I am responsible" -- but even that disappointed Ms. Martin,
who had wanted Mr. Tenet to say, "We did not express any doubt about
Niger."

During her testimony, Ms. Martin, a Harvard Law School graduate married
to FCC Chairman Kevin Martin and a close friend of Bush counselor Dan
Bartlett, seemed uncomfortable, shifting in her chair, squinting at her
interrogators, stealing quick glances at the jury and repeatedly
touching her cheek, ear, nose, lips and scalp.

Ms. Martin shed light on the mystery of why then-White House press
secretary Scott McClellan promised, falsely, that Mr. Libby was not
involved in outing CIA operative Valerie Plame Wilson, the former
ambassador's wife. After Mr. McClellan had vouched for Bush strategist
Karl Rove's innocence, Mr. Libby asked Ms. Martin, "Why don't they say
something about me?"

"You need to talk to Scott," Ms. Martin advised.

On jurors' monitors were images of Ms. Martin's talking points -- some
labeled "on the record," and others "deep background." She walked the
jurors through how the White House coddles friendly writers and freezes
out others. To deal with the Wilson controversy, she hastily arranged a
Cheney lunch with conservative commentators. And when New York Times
columnist Nicholas Kristof first wrote about the Niger affair, she
explained, "We didn't see any urgency to get to Kristof" because "he
frankly attacked the administration fairly regularly."

Under questioning from prosecutor Patrick Fitzgerald, Ms. Martin
described how Mr. Hadley tried to keep White House spokesmen ignorant
about the Niger controversy.

But Ms. Martin, encouraged by Mr. Libby, secretly advised the vice
president and his top aide on how to respond. She put "Meet the 

Prefered install method?

2007-01-25 Thread Tina I
Another noob question:
I have written my first linux application that might actually be of 
interest to others. Just for fun I also wrote an install script that put 
the files in the common directories for my distro (Debian). That is in 
/usr/local/. (This particular program can be run directly from the 
user's /home but as a learning experience I want to do it the 'coorect' way)

Now, I don't know if that is the way to do it with python applications. 
I also don't know if a custom install script is the norm. I have seen 
some use of makefiles and tried to find something about it but the 
manual for GNUMake really assume you are familiar with/ using C which 
I'm not. I have googled a lot for this but can't really find anything 
aimed for someone just learning programming with Python.

So my question is; What is the preferred/ common way to install a python 
application so it's not really distro specific? And are there any good 
resources on this on the web?

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


Re: Module for SVG?

2007-01-25 Thread Jean-François Piéronne
Sebastian Bassi a écrit :
> Hello,
> 
> I found http://www2.sfk.nl/svg as a Python module for writing SVG.
> Last update was in 2004 and I am not sure if there is something
> better.
> Any recommendation for generating SVG graphics?

I have ported to Python the Ruby SVG graph generation library
http://www.germane-software.com/software/SVG/SVG::Graph/
some examples:
http://www.germane-software.com/software/SVG/SVG::Graph/screenshots.html

If you have some interest let me know.


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


problems with pyzeroconf and linux

2007-01-25 Thread Simo Hosio

Hi all,
I am trying to get pyzeroconf (http://sourceforge.net/projects/pyzeroconf) 
running on my machine but having trouble... Running the Zeroconf.py file 
seems to register the service, but is unable to find it.

(same situation than in 
http://www.nabble.com/pyzeroconf-on-linux...-t481215.html, but differenet 
cause, I'm sure..)

"""
Multicast DNS Service Discovery for Python, version 0.12
1. Testing registration of a service...
Registering service...
Registration done.
2. Testing query of service information...
Getting ZOE service: None
Query done.
3. Testing query of own service...
Getting self: None
Query done.
4. Testing unregister of service information...
Unregister done.
"""

Running ethereal reveals that there are no responses to the 2) and 
3)...The queries are certainly there. I'm runnin this with Ubuntu Dapper in 
a WLAN network. I am not too familiar with networking in Linux environment, 
so if anyone has any help on how to get it running, I would appreciate. :)


Best Regards,
Simo Hosio
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: doctest problem with null byte

2007-01-25 Thread Tim Peters
[Stuart D. Gathman]
> I am trying to create a doctest test case for the following:
>
> def quote_value(s):
> """Quote the value for a key-value pair in Received-SPF header
> field if needed.  No quoting needed for a dot-atom value.
>
> >>> quote_value(r'abc\def')
> '"abcdef"'
> >>> quote_value('abc..def')
> '"abc..def"'
> >>> quote_value('')
> '""'
> >>> quote_value('-all\x00')
> '"-allx00"'
> ...
> 
> However, doctest does *not* like the null byte in the example (yes,
> this happens with real life input):
> **
> File "/home/stuart/pyspf/spf.py", line 1453, in spf.quote_value
> Failed example:
> quote_value('-all')
> Exception raised:
> Traceback (most recent call last):
>   File
>   "/var/tmp/python2.4-2.4.4c1-root/usr/lib/python2.4/doctest.py", 
>  line 1248, in __run
> compileflags, 1) in test.globs
> TypeError: compile() expected string without null bytes
> **
> 
> How can I construct a test cast for this?

As the docs say, doctest examples are parsed /twice/:  once when Python 
compiles the module and creates string objects, and again when doctest 
extracts and passes example substrings to the compile() function (which 
you can see in your traceback).

The first time, the \x00 in the

 quote_value('-all\x00')

portion of your docstring got changed into an honest-to-goodness NUL 
byte.  Passing that to compile() can't work.

To alleviate that, and the "leaning toothpick syndrome" in your other 
examples, a simple approach is to make your docstring a raw string 
(stick the letter 'r' in front of the opening triple-quote).

For example, this works fine:

def f():
r"""
>>> len("\\")
1
>>> ord("\x00")
0
"""

Because it's a raw string, Python does /not/ change the

\x00

portion into a NUL byte when it compile the module.  Instead the 
docstring continues to contain the 4-character substring:

\x00

and that's what compile() needs to see.

To perform the same test without using a raw string requires slamming in 
more backslashes (or other ad-hoc escaping tricks):

def g():
"""
>>> len("")
1
>>> ord("\\x00")
0
"""
-- 
http://mail.python.org/mailman/listinfo/python-list


Which BASTARD involved in Valerie Plame case? FINALLY EXPOSED

2007-01-25 Thread thermate
http://www.latimes.com/news/nationworld/nation/la-na-libby26jan26,1,2730931.story?coll=la-headlines-nation

Aide testifies Cheney helped effort to discredit Wilson
By Richard B. Schmitt, Times Staff Writer
5:27 PM PST, January 25, 2007

WASHINGTON -- Vice President Dick Cheney and his former chief of staff,
I. Lewis "Scooter" Libby, were personally and actively involved in an
effort to spin news coverage and discredit a critic of the Iraq war
even before the fact that his wife was a CIA operative became public, a
senior White House official testified Thursday.

In the first insider account of how top officials reacted when
questions began to be raised about the intelligence used to justify the
war, Catherine J. Martin said that at one point Cheney dictated a
detailed list of talking points to be used by Libby and others in
making calls to reporters. Martin was Cheney's top media aide at the
time and is now deputy White House director of communications for
policy and planning.

Martin testified as a prosecution witness at Libby's trial on charges
of obstructing an investigation into how the name of a CIA operative
became public. The operative, Valerie Plame, is the wife of former U.S.
envoy Joseph C. Wilson IV. Wilson, who had written a government report
questioning White House claims that Iraq had sought nuclear weapons
material from the government of Niger -- a report that the White House
sought to discredit.

At the time Libby was questioned by federal agents, a grand jury was
investigating how Plame's identity was leaked to reporters.

Martin said she learned that Plame worked for the CIA after Libby
directed her to call the agency to get more information about a
fact-finding trip Wilson had taken to Niger in February 2002. Martin
said she quickly reported the information about Plame to Libby and
Cheney.

Martin's statements buttressed the testimony of two former government
officials who said earlier this week that they received urgent calls
from Libby in June 2003 asking about Wilson and the trip. Martin was
the third prosecution witness to tell the jury that she had told Libby
that Wilson's wife worked at the CIA before it was publicly revealed in
a syndicated column by Robert Novak on July 14, 2003.

Libby had told federal agents that he had first learned from
journalists that Plame was a CIA agent.

On the third day of the Libby trial, Martin offered a rare glimpse
behind the secrecy that has surrounded senior officials of the Bush
administration involved in making and managing Iraq war policy. She
described details of a White House media strategy, hatched at the
highest levels, which sought to rebut charges that Bush had misled the
public in his 2003 State of the Union.

In making the case for war, the president had asserted that Saddam
Hussein was seeking nuclear material in Africa. Wilson had found the
claim baseless and had asserted that Cheney had apparently authorized
his fact-finding mission.

Martin said Cheney personally dictated talking points to be used in
answering news media questions about Wilson's allegation that he had
authorized a trip to Niger. The talking points included information
from a secret National Intelligence Estimate.

The vice president ordered media aides to start tracking news coverage
closely, while Libby was directed to contact reporters.

At one point, Cheney gave a note card to Libby with information to give
to a Time magazine reporter covering the case, while Cheney and Libby
were traveling on Air Force Two on the way back from the christening of
an air craft carrier for Ronald Reagan in Virginia.

Martin also described how she discussed with Libby media "options" to
rebut Wilson that included a strategic "leak" to a handful of
reporters.

But Martin said that neither Cheney nor Libby had suggested that the
identity of Plame be divulged as part of the game plan. She said that
she had no knowledge of either actually doing so.

"I recall the vice president telling me to keep track of this story,
and keep track of the commentators who were continuing to write on this
story and talk about us," Martin testified. "We were paying attention
to 'Hardball' with Chris Matthews because he had been talking about it
a lot."

She described the reaction inside the administration as questions began
to be raised, starting in May 2003. At that time, The New York Times
described the Wilson trip to Niger but did not name him. The article
said the administration had engaged in a "campaign of wholesale deceit"
and suggested that Cheney was directly involved.

Martin said that Libby asked her to call the then-chief public affairs
officer at the CIA, William Harlow, to find out about the trip by the
then-mysterious former envoy.

"So I was saying, 'Who sent him? Who is this guy?' " Martin testified.
"I remember Bill Harlow saying his name was Joe Wilson, he was a charge
in Baghdad, and his wife works over here." Martin said she promptly
went to see Cheney and Libby with the news.

Wilson

Re: Python does not play well with others

2007-01-25 Thread John Nagle
Paul Rubin wrote:
> John Nagle <[EMAIL PROTECTED]> writes:
> 
>>That's the problem.  We now have four SSL implementations for
>>Python, none of which let you do all the things OpenSSL can do.
> 
> 
> I'm aware of some OpenSSL wrappers plus TLSlite.  Am I missing a
> couple more?  I guess maybe the OpenSSL wrappers also work on GnuTLS.
> 
> 
>>Can you build the built-in SSL package without building all of
>>Python?  
> 
> 
> I thought there was no built-in SSL package-- it just calls OpenSSL.

 "import SSL" brings in a .dll or .so object called "_ssl.pyd".
This contains C glue code which connects Python to the
C-based OpenSSL library.  That's the component which needs work.
Its source code is at

   http://svn.python.org/view/python/trunk/Modules/_ssl.c

 Part of the problem is that the build of _ssl.pyd
is too integrated into the main Python build to work on easily.
You can't just build and test a new SSL module and give it to others
to test.  You have to rebuild the whole Python system, and
people who want to test the modified module need to run a
custom Python build.

 SSL is somewhat integrated into the socket module internally,
although from the code I don't see that this is absolutely
necessary.  The build machinery for SSL is in

   http://svn.python.org/view/python/trunk/setup.py

 After looking at that for a while, and the directory
structure, it looks like the Python directory layout and
build system makes the assumption that anything in the
standard distribution is built as part of the basic
Python build.  The module itself could be separated from
the trunk build; Python will run without it.   It's the
build process and directory structure which ties it up.

 As far as I can tell, there's no concept in the
Python build system of a module that's built separately
but ships with the standard Python distribution.  Is
that correct?

 So now I understand why the standard SSL module doesn't
get fixed, and why there are three or four alternative
re-implementations of it.  It's easier to replace than
to repair.

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


Re: assertions to validate function parameters

2007-01-25 Thread Steven D'Aprano
On Thu, 25 Jan 2007 16:54:05 +, Matthew Wilson wrote:

> Lately, I've been writing functions like this:
> 
> def f(a, b):
> 
> assert a in [1, 2, 3]
> assert b in [4, 5, 6]
> 
> The point is that I'm checking the type and the values of the
> parameters.

If somebody passes in a == MyNumericClass(2), which would have worked
perfectly fine except for the assert, your code needlessly raises an
exception.

Actually that's a bad example, because surely MyNumericClass(2) would
test equal to int(2) in order to be meaningful. So, arguably, testing that
values fall within an appropriate range is not necessarily a bad idea, but
type-testing is generally bad.

Note also that for real code, a bare assert like that is uselessly
uninformative:

>>> x = 1
>>> assert x == 3
Traceback (most recent call last):
  File "", line 1, in ?
AssertionError


This is better:

>>> assert x == 3, "x must be equal to three but is %s instead" % x
Traceback (most recent call last):
  File "", line 1, in ?
AssertionError: x must be equal to three but is 1 instead


This is even better still:

>>> if x != 3:
... raise ValueError("x must be equal to three but is %s instead" % x)
...
Traceback (most recent call last):
  File "", line 1, in ?
ValueError: x must be equal to three but is 1 instead


And even better still is to move that test out of your code and put it
into unit tests (if possible).


 
> I'm curious how this does or doesn't fit into python's duck-typing
> philosophy.

Doesn't fit, although range testing is probably okay.


> I find that when I detect invalid parameters overtly, I spend less time
> debugging.

Yes, probably. But you end up with less useful code:

def double(x):
"""Return x doubled."""
assert x == 2.0 and type(x) == float
return 2*x

Now I only need to test one case, x == 2.0. See how much testing I don't
have to do? *wink*

There's a serious point behind the joke. The less your function does, the
more constrained it is, the less testing you have to do -- but the less
useful it is, and the more work you put onto the users of your function.
Instead of saying something like

a = MyNumericClass(1)
b = MyNumericClass(6)
# more code in here...
# ...
result = f(a, b)


you force them to do this:

a = MyNumericClass(1)
b = MyNumericClass(6)
# more code in here...
# ... 
# type-cast a and b to keep your function happy
result = f(int(a), int(b))
# and type-cast the result to what I want
result = MyNumericClass(result)

And that's assuming that they can even do that sort of type-cast without
losing too much information.


> Are other people doing things like this?  Any related commentary is
> welcome.

Generally speaking, type-checking is often just a way of saying "My
function could work perfectly with any number of possible types, but I
arbitrarily want it to only work with these few, just because."

Depending on what you're trying to do, there are lots of strategies for
avoiding type-tests: e.g. better to use isinstance() rather than type,
because that will accept subclasses. But it doesn't accept classes that
use delegation.

Sometimes you might have a series of operations, and you want the lot to
either succeed or fail up front, and not fail halfway through (say, you're
modifying a list and don't want to make half the changes needed). The
solution to that is to check that your input object has all the methods
you need:

def f(s):
"""Do something with a string-like object."""
try:
upper = s.upper
split = s.split
except AttributeError:
raise TypeError('input is not sufficiently string-like')
return upper()

Good unit tests will catch anything type and range tests will catch, plus
a whole lot of other errors, while type-testing and range-testing will
only catch a small percentage of bugs. So if you're relying on type- and
range-testing, you're probably not doing enough testing.


-- 
Steven.

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


Re: Pyparsing - Dealing with a Blank Value

2007-01-25 Thread Paul McGuire
On Jan 25, 7:13 pm, "Steve" <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I've picked up thePyParsingmodule and am trying to figure out how to
> do a simple parsing of some HTML source code.  My specific problem is
> dealing with an  element that is blank.
>

I'd also suggest use the makeHTMLTags helper module for the TR and TD
tags:

trStart,trEnd = makeHTMLTags("TR")
tdStart,tdEnd = makeHTMLTags("TD")

makeHTMLTags includes a much more robust definition than just
Literal(""), including recognition of attributes and tolerance of
upper/lower case.

-- Paul

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


Re: Pyparsing - Dealing with a Blank Value

2007-01-25 Thread Paul McGuire
On Jan 25, 7:13 pm, "Steve" <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I've picked up thePyParsingmodule and am trying to figure out how to
> do a simple parsing of some HTML source code.  My specific problem is
> dealing with an  element that is blank.
>

>
> Any assistance would be greatly appreciated!
>
> Steve

Just define a default value to be returned for MultiItem if the
Optional expression is not found:

MultiItem = Optional(OneOrMore(dataItem),default="")

Define default to be whatever string you choose.

-- Paul

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


I made a mistake in selecting America as a land of Freedom, EINSTEIN

2007-01-25 Thread thermate
I made a mistake in selecting America as a land of Freedom, EINSTEIN

 "Insanity: Doing the same thing over and over again, and expecting
 different results".-Albert Einstein

 "It is my conviction that killing under the cloak of war is nothing
 but an act of murder." -Albert Einstein

 "I came to America because of the great, great freedom which I heard
 existed in this country. I made a mistake in selecting America as a
 land of freedom, a mistake I cannot repair in the balance of my
 lifetime."
 Albert Einstein, 1947

On Jan 25, 7:05 pm, [EMAIL PROTECTED] wrote:
> http://www.gnn.tv/threads/22972/Bush_Ignores_True_Cost_of_Iraq_war
>
> Bush Ignores True Cost of Iraq war
> Asset H12937 Posted By GWHunta
>
> In his State of the Union address, President Bush makes the case for
> his plan to escalate the war in Iraq. He paints the potential costs of
> pulling out of Iraq in stark colors. But he won't say much about the
> real costs of staying in and escalating.
>
> We should never forget the incalculable cost of the war-the lives and
> the limbs of U.S. soldiers. As of this month, more than 3,000 U.S.
> soldiers have died and 22,800 been wounded in this war. An estimated
> 35,000 Iraqi civilian lives were lost last year. A staggering
> percentage have been displaced from their homes. The U.S. casualties
> bring terrible grief to their families and friends, but the loss must
> sober and sadden us all.
>
> In addition, this country pays very steep economic costs-what
> economists call "opportunity costs"-the costs of what is not done
> with the scarce financial resources we are devoting to war in Iraq. The
> price is particularly apparent as the president prepares to introduce a
> budget calling for cuts in child care, in education, in health care,
> and more.
> [end excerpt]
> Click here to read the rest of the article
> GWHunta
> R258778
> 9 hours ago
> GWHunta
>
> When people speak to you about a preventive war, you tell them to go
> and fight it. After my experience, I have come to hate war.
> ~Dwight D. Eisenhower
>
> The most successful war seldom pays for its losses.
> ~Thomas Jefferson
>
> Sometimes no Peace,
> ~GWHunta
> BetterRed
> R258787
> 8 hours ago
> BetterRed
>
> "Insanity: Doing the same thing over and over again, and expecting
> different results".-Albert Einstein
>
> "It is my conviction that killing under the cloak of war is nothing
> but an act of murder." -Albert Einstein
>
> "I came to America because of the great, great freedom which I heard
> existed in this country. I made a mistake in selecting America as a
> land of freedom, a mistake I cannot repair in the balance of my
> lifetime."
> Albert Einstein, 1947
> mikecimerian
> R258790
> 8 hours ago
> mikecimerian
>
> Two billion a week ... and Katrina victims still pay mortgage on
> wrecked houses ...
> GWHunta
> R258793
> 7 hours ago
> GWHunta
>
> 15 billion a month for the "war on terror."
>
> Not including interest on these "borrowed" funds and the health
> care costs and disability payments for the veterans fretruning from
> these "wars."
>
> Also not included are the economic and social costs of the programs
> that go unfunded because war is becoming the primary function of the
> U.S. federal gov't.
>
> The costs associated with the war in Iraq continue to escalate along
> with the violence.
>
> Sometimes no Peace,
> johnnycivil
> R258821
> 5 hours ago
> johnnycivil
>
> Okay, lets be real. Iraq has always been a staging ground for Iran. In
> Iraq and Afghanistan we have the foundation for a strong move agaist
> the meat in our murder sandwich. When we straddle Saudi Arabia to
> Afghanistan we will control 70% of the easily extracable oil. Pretty or
> ugly the Cheney gang are correct, own that own the nations. When
> control is locked in they will say that is what drove China to attack
> us, leading to the depopulating war our fearful masters always opt for.
> Have a nice day.
> nobinPoddywodder
> R258872
> 33 minutes ago
> nobinPoddywodder
>
> Why do crackerjax hate Iraq so much? Why do they hate the shia's and
> the kurds and try and deny them majority rule? Why do crackerjax try
> and deny Iraqis the right to democracy?
>
> Far leftists have argued many times over the past 3 years, that Iraq
> would be better off under saddam, a veiled attempt at saying sunni
> minority rule. Of course the far left doesn't care if minority rule
> in Iraq would continue. Not only minority rule, but minority rule of a
> brutal dictators. Perhaps the far left should ask Shias and Kurds
> whether saddam was better.
>
> Ok, so Iraq is a prop in your socialist revolution. Ok, the Iraqi war
> offers some hope, albeit a slim one, that such a catastrophe could
> trigger a socialist revolution in the West.
>
> But this antic of the far left of pretending to actually care about
> Iraqis by destroying its democracy is getting a bit tired. Pretty weird
> social science if you ask me. The far left is protecting I

Re: Http listener

2007-01-25 Thread Gabriel Genellina

At Thursday 25/1/2007 23:32, [EMAIL PROTECTED] wrote:


Am trying to find any resources that helps me to do write the Http
Listener..


Use SimpleHTTPServer; see its source code for an example.


--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Bush Ignores True Cost of Iraq war

2007-01-25 Thread thermate
http://www.gnn.tv/threads/22972/Bush_Ignores_True_Cost_of_Iraq_war

Bush Ignores True Cost of Iraq war
Asset H12937 Posted By GWHunta

In his State of the Union address, President Bush makes the case for
his plan to escalate the war in Iraq. He paints the potential costs of
pulling out of Iraq in stark colors. But he won't say much about the
real costs of staying in and escalating.

We should never forget the incalculable cost of the war-the lives and
the limbs of U.S. soldiers. As of this month, more than 3,000 U.S.
soldiers have died and 22,800 been wounded in this war. An estimated
35,000 Iraqi civilian lives were lost last year. A staggering
percentage have been displaced from their homes. The U.S. casualties
bring terrible grief to their families and friends, but the loss must
sober and sadden us all.

In addition, this country pays very steep economic costs-what
economists call "opportunity costs"-the costs of what is not done
with the scarce financial resources we are devoting to war in Iraq. The
price is particularly apparent as the president prepares to introduce a
budget calling for cuts in child care, in education, in health care,
and more.
[end excerpt]
Click here to read the rest of the article
GWHunta
R258778
9 hours ago
GWHunta

When people speak to you about a preventive war, you tell them to go
and fight it. After my experience, I have come to hate war.
~Dwight D. Eisenhower

The most successful war seldom pays for its losses.
~Thomas Jefferson

Sometimes no Peace,
~GWHunta
BetterRed
R258787
8 hours ago
BetterRed

"Insanity: Doing the same thing over and over again, and expecting
different results".-Albert Einstein

"It is my conviction that killing under the cloak of war is nothing
but an act of murder." -Albert Einstein

"I came to America because of the great, great freedom which I heard
existed in this country. I made a mistake in selecting America as a
land of freedom, a mistake I cannot repair in the balance of my
lifetime."
Albert Einstein, 1947
mikecimerian
R258790
8 hours ago
mikecimerian

Two billion a week ... and Katrina victims still pay mortgage on
wrecked houses ...
GWHunta
R258793
7 hours ago
GWHunta

15 billion a month for the "war on terror."

Not including interest on these "borrowed" funds and the health
care costs and disability payments for the veterans fretruning from
these "wars."

Also not included are the economic and social costs of the programs
that go unfunded because war is becoming the primary function of the
U.S. federal gov't.

The costs associated with the war in Iraq continue to escalate along
with the violence.

Sometimes no Peace,
johnnycivil
R258821
5 hours ago
johnnycivil

Okay, lets be real. Iraq has always been a staging ground for Iran. In
Iraq and Afghanistan we have the foundation for a strong move agaist
the meat in our murder sandwich. When we straddle Saudi Arabia to
Afghanistan we will control 70% of the easily extracable oil. Pretty or
ugly the Cheney gang are correct, own that own the nations. When
control is locked in they will say that is what drove China to attack
us, leading to the depopulating war our fearful masters always opt for.
Have a nice day.
nobinPoddywodder
R258872
33 minutes ago
nobinPoddywodder

Why do crackerjax hate Iraq so much? Why do they hate the shia's and
the kurds and try and deny them majority rule? Why do crackerjax try
and deny Iraqis the right to democracy?

Far leftists have argued many times over the past 3 years, that Iraq
would be better off under saddam, a veiled attempt at saying sunni
minority rule. Of course the far left doesn't care if minority rule
in Iraq would continue. Not only minority rule, but minority rule of a
brutal dictators. Perhaps the far left should ask Shias and Kurds
whether saddam was better.

Ok, so Iraq is a prop in your socialist revolution. Ok, the Iraqi war
offers some hope, albeit a slim one, that such a catastrophe could
trigger a socialist revolution in the West.

But this antic of the far left of pretending to actually care about
Iraqis by destroying its democracy is getting a bit tired. Pretty weird
social science if you ask me. The far left is protecting Iraq by
preventing it from modernizing and preventing it from extending
Capitalism and world economic integration.

"No War for oil" is a code word meaning, don't modernize Iraq and
don't bring Capitalsm and free foreign investment there.

Again I say, why not ask Iraqis what type of system they want.

Or for example, when iraqi terrorism against the government of Iraq is
almost entirely a sunni phenomena, the far left call the Maliki
government stooges and traitors, as if to say that the 80% of Iraq that
is either Shia or Kurd is somehow does not represent Iraq, yet a small
handful of sunni thugs, assisted by sunni Islamists from other
countries somehow do. According to the far left the sunnis who have
hitherto ruled Iraq with brutality should continue to do so. Why? Just
beca

Http listener

2007-01-25 Thread elrondrules
Hi

Am new to python and I am trying to do the following:

1. Write a Http Listener (listening on a particular port) that
subscribes to a process.
2. This process posts events as xml docs.
3. Parse the xml docs as and when they are posted.

Am trying to find any resources that helps me to do write the Http
Listener.. 
any starting pointers would be helpful

thx

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


How do I build python with debug info? (and python module load questions)

2007-01-25 Thread sndive
I want to step into PyImport_ImportModule("my_foo") that's failing
despite the my_foo.py
being in the current directory. (PyRun_SimpleFileEx works on the exact
same file).
How would I run configure to build libpython with -g?

I wonder if I should just keep using PyRun_SimpleFileEx.

I want to be able to call arbitrary functions in the imported
file/module
using PyRun_SimpleString("import my_foo\nmy_foo.bar(whatever)")
after the file is loaded.

There is no '' in sys.path, I assume that should not affect
PyImport_ImportModule
to look in the current directory first. Does it?

Thank you!

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


Lython

2007-01-25 Thread faulkner
I have Lython!
I want to make sure that anybody else who wants it can access it, so,
unless Mr. Egan objects, I'm hosting it here:
http://home.comcast.net/~faulkner612/programming/python/lython.zip
I had to patch it a bit because the number of arguments to
compiler.ast.Function.__init__ changed between 2.3 and 2.4, when
decorators were introduced. I haven't tested it on 2.5 because the last
time I upgraded python, my gentoo died.
I also took the liberty of adding some features such as primitive
interactivity, a '-c code' option, a '-h' option, an rc file
'~/.lythonrc.ly', and a '-o file' option which dumps bytecode to file.
I've slated developing support for *args, **kwargs, default arguments,
+= and -= etc., reader macros ala common lisp, classes,
try...except...finally, and raise.

For the curious, here are some other implementations of lisp in python:
http://ibiblio.org/obp/py4fun/lisp/lisp.html
http://hkn.eecs.berkeley.edu/~dyoo/python/pyscheme/
http://www.xs4all.nl/~yduppen/site/psyche.html
http://www.biostat.wisc.edu/~annis/creations/PyLisp/

These implementations are great, but Lython has macro capabilities,
generates python byte code, and demonstrates the use of spark, a
fantastic parsing package.

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


doctest problem with null byte

2007-01-25 Thread Stuart D. Gathman
I am trying to create a doctest test case for the following:

def quote_value(s):
"""Quote the value for a key-value pair in Received-SPF header field
if needed.  No quoting needed for a dot-atom value.

>>> quote_value(r'abc\def')
'"abcdef"'
>>> quote_value('abc..def')
'"abc..def"'
>>> quote_value('')
'""'
>>> quote_value('-all\x00')
'"-allx00"'
...

However, doctest does *not* like the null byte in the example (yes, this
happens with real life input):
**
File "/home/stuart/pyspf/spf.py", line 1453, in spf.quote_value
Failed example:
quote_value('-all')
Exception raised:
Traceback (most recent call last):
  File "/var/tmp/python2.4-2.4.4c1-root/usr/lib/python2.4/doctest.py",
line 1248, in __run
compileflags, 1) in test.globs
TypeError: compile() expected string without null bytes
**

How can I construct a test cast for this?

-- 
  Stuart D. Gathman <[EMAIL PROTECTED]>
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.

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


Help extracting info from HTML source ..

2007-01-25 Thread s. d. rose
Hello All.
  I am learning Python, and have never worked with HTML.  However, I would 
like to write a simple script to audit my 100+ Netware servers via their web 
portal.

  I was reading Chapter 8 of Dive into Python, which deals with this topic. 
In the web portal of the server, there is a section similar to this:

  -->  clients and http://eugenia.blogsome.com/?s=ipkall";>clever services. <--

which I took from SlashDot, but what I'm talking about is using the word 
'services' to represent the link to eugenia.blogsome.com.

What I'd like to do is save the two pieces of info relative to the server 
name.  Probably in a dictionary, such as server1[link] to the page on 
eugenia.blogsome.com and server1[description] to 'services'.

I've used the example from Dive into Python to get the actual link in the 
source of the HTML, but I don't know how to get the text that is the 
hyperlink.

So in the portal, I've got a link 'Scheduled Server Reboot' going to say 
/ScheduledTasks/ID3/ on Server1, using similar to above clipped HTML 
source code.

Can someone please help me?  Sure, I could manually go to each server, but I 
wouldn't learn anything.  I've learned some, but also have real deadlines, 
so I eagerly hope for any assistance & instruction.

Thank you!
-Dave
Shelton, CT 



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


Re: stop script w/o exiting interpreter

2007-01-25 Thread Miki
Hello Alan,

> I'm fairly new to Python and I've lately been running a script at
> the interpreter while working on it.  Sometimes I only want to
> run the first quarter or half etc.  What is the "good" way to do this?
If you want to exit from the program then "raise SystemExit" is what
you want.
If you want to enter the debugger, you can do:

from pdb import set_trace

...
set_trace() # Stop and execute debugger here.
...

HTH,
--
Miki
http://pythonwise.blogspot.com

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


Re: Getting started with Crystal Reports...little help in the far court.

2007-01-25 Thread Carl Trachte
Marc,

I've been able to get some Business Objects COM functionality in
Business Objects 6.5 (the logging in functionality I have to do through a
call to an Excel VBA macro; otherwise things appear to work for what I'm
doing).

Unfortunately, I don't have experience with Python in Business Objects
XI or Crystal Reports.  I did have to play with makepy on a couple Business
Objects files to get something useful.  I believe I eventually struck
paydirt with busobj.exe (but don't quote me on it - it's been a while).

This information probably isn't terribly useful.  The best advice I can
give is to try the respective Crystal Reports and Business Objects XI
executable files with makepy.  If there's no joy there, start working with
the dll's and see if they yield something that works.

Hopefully someone with a bit more win32 or BO XI experience will chime
in.  In the meantime, good luck.

Carl T.

"Mudcat" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I am not that familiar with Crystal Reports, but having read some other
> posts I know that the way to integrate the API with Python is through
> the COM interface provide by win32all.
>
> However, I have been unable to find any other information on how to get
> started. I've used the COM interface before in integrating Excel and a
> couple of other things. So I am familiar with how that works. But there
> are at least 40 options dealing with Crystal and Business Objects. I
> have no idea which makepy file to create or which one provides the
> functionality I need.
>
> I'm not looking to do much. All I'm really trying to do is provide one
> application where a list of crystal reports can be selected and ran in
> series. Right now we have a lot of reports that all have to be run
> manually (takes a while). So I think all I need api access to is server
> selection, parameter selection, and output formats.
>
> Any pointers in the right direction would be helpful.
>
> Thanks,
> Marc
>


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


Re: Pyparsing - Dealing with a Blank Value

2007-01-25 Thread Gabriel Genellina

At Thursday 25/1/2007 22:13, Steve wrote:


I've picked up the PyParsing module and am trying to figure out how to
do a simple parsing of some HTML source code.  My specific problem is
dealing with an  element that is blank.


Sorry for not answering your question exactly, but I'd use 
BeautifulSoup instead, it works even if the HTML is not well formed.



--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: ANN: Dejavu 1.5.0RC1

2007-01-25 Thread fumanchu
On Jan 25, 10:10 am, "olive" <[EMAIL PROTECTED]> wrote:
> Do you consider a StorageManagers for Oracle ?

Yes, and in fact, I already have a ticket for it:
http://projects.amor.org/dejavu/ticket/59. I've downloaded Oracle 10.2g
XE and played with it a little, but hit some snags right away due to
its different interface. I think now that I've done a Firebird backend,
I'll be a little better able to tackle an Oracle adapter. But I don't
use Oracle every day, so any help is most welcome.


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

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


Re: difflib qualm

2007-01-25 Thread Gabriel Genellina

At Thursday 25/1/2007 21:49, Larry Bates wrote:

Gabriel Genellina wrote:
> At Wednesday 24/1/2007 23:05, Sick Monkey wrote:
>
>> I am trying to write a python script that will compare 2 files which
>> contains names (millions of them).
>>
>> More specifically, I have 2 files (Files1.txt and Files2.txt).
>> Files1.txt contains 180 thousand names and Files2.txt contains 34
>> million names.

Put the big list of names in a database and create soundex keys for the names
and make the soundex keys an index so you can search quickly.  Databases
are really good at storing data that is searchable via an index.  If 
you REALLY

need speed you can consider an in-memory database.

Create soundex keys for each name in your small list and query the database
with this key into the table in the DB that is indexed on soundex keys.
If you get a hit, the key is sufficiently "alike" to be a candidate.  I'll
leave the remainder to you.  Perhaps there is other information that will
help determine if there is a match?


Soundex is only good for English words, and it's almost useless for 
non-English names, so it must be used with caution if used at all.



--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: Right-Justifying Numeric Output

2007-01-25 Thread Gabriel Genellina

At Thursday 25/1/2007 19:34, Rich Shepard wrote:


> assuming max size = 10
>
> #with spaces
>>> '% 10d' % 11
> '11'
> #with zeros
>>> '%010d' % 11
> '11'

   Thank you very much! I didn't see this in any of my Python books or on the
Web.


http://docs.python.org/lib/typesseq-strings.html


--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Pyparsing - Dealing with a Blank Value

2007-01-25 Thread Steve
Hi All,

I've picked up the PyParsing module and am trying to figure out how to
do a simple parsing of some HTML source code.  My specific problem is
dealing with an  element that is blank.



from pyparsing import *
import sys


integer = Word("0123456789")

trStart = Literal("").suppress()
trEnd = Literal("").suppress()

tdStart = Literal("").suppress()
tdEnd = Literal("").suppress()

#dataItem = Word(alphas)
BlankItem = Word('')
dataItem = Word(alphanums + " " + "," + ":") # works with spaces in
data
MultiItem = Optional(OneOrMore(dataItem))

TestLine = ['GroupYearCity',
   'AAA1992Los Angeles',
   'BBB2007Santa Cruz',
   '2001Santa Cruz']

htmlLine = trStart + tdStart + MultiItem.setResultsName('status') +
tdEnd + tdStart + MultiItem.setResultsName('year') + tdEnd + tdStart +
MultiItem.setResultsName('title') + tdEnd + trEnd


for CurrentLine in TestLine:
  print 'Line = ', CurrentLine

  for srvrtokens,startloc,endloc in htmlLine.scanString( CurrentLine ):
  print 'tokens = %s  %d  %d \n' % (srvrtokens, startloc,endloc)


Output :

Line =  GroupYearCity
tokens = ['Group', 'Year', 'City']  0  49

Line =  AAA1992Los Angeles
tokens = ['AAA', '1992', 'Los Angeles']  0  54

Line =  BBB2007Santa Cruz
tokens = ['BBB', '2007', 'Santa Cruz']  0  53


*** Blank 1st element - only shows 2 elements  - need 3 elements to be
consistent ***

Line =  2001Santa Cruz
tokens = ['2001', 'Santa Cruz']  0  50


Any assistance would be greatly appreciated!

Steve

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


Re: My python programs need a GUI, wxPython or PyQt4?

2007-01-25 Thread Sean Schertell
That's really exciting! Thanks for the tip.

Sean



On Jan 25, 2007, at 9:42 AM, Robert Kern wrote:

> Sean Schertell wrote:
>> Not to totally hijack the thread -- but since you're all talking
>> about best GUI frameworks. Any thoughts on the best looking framework
>> for OS X only? Is there any way to write little Python apps that will
>> launch in OS X using OS X widgets?
>
> Use PyObjC. You have full access to the Cocoa framework.
>
>   http://pyobjc.sourceforge.net/
>
> --  
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a  
> harmless enigma
>  that is made terrible by our own mad attempt to interpret it as  
> though it had
>  an underlying truth."
>   -- Umberto Eco
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list

  DataFly.Net  
Complete Web Services
http://www.datafly.net

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


Re: The reliability of python threads

2007-01-25 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> What makes you think Paddy indicated he wouldn't try to solve the problem?
> Here's what he wrote:
> 
> What I'm proposing is that if, for example, a process stops running
> three times in a year at roughly three to four months intervals , and it
> should have stayed up; then restart the server sooner, at aa time of
> your choosing, whilst taking other measures to investicate the error.

Well, ok, that's better than just rebooting every so often and leaving
it at that, like the firmware systems he cited.

> I see nothing wrong with trying to minimize the chances of a problem

I think a measure to minimize the chance of some problem is only valid
if there's some plausible theory that it WILL decrease the chance of
the problem (e.g. if there's reason to think that the problem is
caused by a very slow resource leak, but that hasn't been suggested).
That's the part that I'm missing from this story.

One thing I'd certainly want to do is set up a test server under a
much heavier load than the real server sees, and check whether the
problem occurs faster.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module for SVG?

2007-01-25 Thread Gabriel Genellina

At Thursday 25/1/2007 16:46, [EMAIL PROTECTED] wrote:


Depending on the size of your project, the xist library from living
logic is supporting svg xml:
http://www.livinglogic.de/Python/xist/
http://www.livinglogic.de/Python/xist/ns/svg/

We've used it successfully, but later on came back to simply use the
standard dom creation tools in python to reduce dependencies.


I ended using a similar approach. You only need a few functions to 
generate those long string attribute values, the remaining is standard XML.



--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: difflib qualm

2007-01-25 Thread Larry Bates
Gabriel Genellina wrote:
> At Wednesday 24/1/2007 23:05, Sick Monkey wrote:
> 
>> I am trying to write a python script that will compare 2 files which
>> contains names (millions of them).
>>
>> More specifically, I have 2 files (Files1.txt and Files2.txt). 
>> Files1.txt contains 180 thousand names and Files2.txt contains 34
>> million names.
>>
>> I have a script which will analyze these two files and store them into
>> 2 different lists (fileList1 and fileList2 respectivly).  I have
>> imported the diflib library and after the lists are created, matching
>> on the following criteria " " for diflib -> (just the names that are
>> similar between the two files).
>>
>> This works perfectly for hundreds of names but is taking forever for
>> millions of them; thus not really efficient.
>>
>> Does anyone have any idea on how to get this more efficient? 
>> (speaking of Time and RAM)
>>
>> Any advice would be greatly appreciated.   (NOTE:  I have been trying
>> to study multithreading, but have not really grasp the concept.  So I
>> may need some examples.)
> 
> When you say "names" you mean people's names? So you want to match, say,
> Levenshtein Vladimir to Lebenstain V.? And you only have the names to
> match?
> Not a good candidate for difflib. See this paper:
> Record Linkage: A Machine Learning Approach, A Toolbox, and A Digital
> Government Web Service (2003)
> Mohamed G. Elfeky, Vassilios S. Verykios, Ahmed K. Elmagarmid, Thanaa M.
> Ghanem, Ahmed R. Huwait.
> http://citeseer.ist.psu.edu/elfeky03record.html
> and you can get other pointers from the Levenshtein distance article in
> Wikipedia and http://en.wikipedia.org/wiki/Fuzzy_string_searching
> 
> 

One approach:

Put the big list of names in a database and create soundex keys for the names
and make the soundex keys an index so you can search quickly.  Databases
are really good at storing data that is searchable via an index.  If you REALLY
need speed you can consider an in-memory database.

Create soundex keys for each name in your small list and query the database
with this key into the table in the DB that is indexed on soundex keys.
If you get a hit, the key is sufficiently "alike" to be a candidate.  I'll
leave the remainder to you.  Perhaps there is other information that will
help determine if there is a match?

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


Re: The reliability of python threads

2007-01-25 Thread skip

Paul> I dunno about Nick, I'm saying it's best to assume that it's
Paul> Poisson and do whatever is necessary to diagnose and fix the bug,
Paul> and that the voodoo measure you're proposing is not all that
Paul> likely to help and it will take years to find out whether it helps
Paul> or not (i.e. restarting after 3 months and going another 3 months
Paul> without a failure proves nothing).

What makes you think Paddy indicated he wouldn't try to solve the problem?
Here's what he wrote:

What I'm proposing is that if, for example, a process stops running
three times in a year at roughly three to four months intervals , and it
should have stayed up; then restart the server sooner, at aa time of
your choosing, whilst taking other measures to investicate the error.

I see nothing wrong with trying to minimize the chances of a problem rearing
its ugly head while at the same time trying to investigate its cause (and
presumably solve it).

Skip

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


Re: MIME text attachment question

2007-01-25 Thread Gabriel Genellina

At Thursday 25/1/2007 08:41, Neal Becker wrote:


I want to send a file (plain text) as an attachment.

I'm using MIMEText.  This attaches text OK, but I would like to have a
filename attached to it, so that the recipient could save it without having
to specify a filename.


part = MIMEText("Hello world!")
part.add_header('Content-Disposition', 'attachment', filename='x.txt')




--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Bush, yank bastards kicked by india in their arse Re: *POLL* How many sheeple believe in the 911 fairy tale and willing to accept an Orwellian doublespeak and enslavement world ?

2007-01-25 Thread thermate
Russia to build nuclear power plants in India

http://www.tribuneindia.com/2007/20070126/main1.htm

India, Russia for axis with China
Rajeev Sharma
Tribune News Service

New Delhi, January 25
India and Russia today supported their trilateral axis with China, but
opposed Beijing's January 11 testing of an anti-satellite missile
saying that they were against militarisation of space.

President Putin went on to the extent of saying that some powers (read
the USA) were trying to militarise space. "We should not let the
genie out of the bottle. That is our position," Mr Putin said at a
joint press interaction with Prime Minister Manmohan Singh after their
formal talks.

As Russian President Vladimir Putin held the seventh Indo-Russian
summit with Prime Minister Manmohan Singh at Hyderabad House here this
afternoon, it was clear that the two giant countries'
decades-old-strategic ties were taken to a significantly higher level.

The UPA government took care to give signals about its clever
diplomatic balancing vis a vis the USA and Russia and treated the Putin
visit on a par with the March 2006 visit to India by President George
W. Bush. This was demonstrated by the fact that the Prime Minister
received Mr Putin at the airport. This is only the fourth time during
his two and a half-year-long tenure that Prime Minister Manmohan Singh
has cast aside the protocol to receive a foreign dignitary at the
airport.

As expected the summit talks threw up a substantive outcome in such
diverse fields as civilian, nuclear energy, space, defence, science,
advanced technology, energy, trade and culture. The two sides today
signed nine bilateral documents and adopted two more. This is over and
above the two arms deals India and Russia had signed yesterday (i) for
licensed production of Russian aircraft engines in India, and (ii) the
joint development of a new transport plane.

An important highlight in the bilateral documents signed between the
two countries was India's inclusion to GLONASS, the Russian Global
Navigation Satellite System. Now, India will have access to signals and
radio frequency of GLONASS, which is an effective alternative to the
American Global Positioning Satellite System (GPS) and the embryonic
Galileo system of the European Union.



On Jan 16, 6:44 pm, [EMAIL PROTECTED] wrote:
> Below is a post repeated with interesting information. But the main
> purpose of this post is to find out how many sheeple still believe in
> the 911 fairy tale of 19 hijackers that was to be USED BY THE EVIL
> CRIMINALS TO "change the world forever" BUT IT WONT. Are we going to
> PERMIT some evil criminals in the government positions to make an
> Orwellian world of enslavement and doublespeak for us and our children
> ?
>
> 
> Journal of 911 studies:http://www.journalof911studies.com/
> =
> $1 Million Challenge/REWARD Details regarding 
> 9/11:http://reopen911.org/Contest.htm
> =
> Background info:http://st911.org/
> =
> REPUBLICANS are ANTICHRIST-FASCIST Bastards, Herbert Bush, Ronald
> Reagan and NOW Mark Foley, VIDEO 
> EVIDENCEhttp://video.google.com/videoplay?docid=359924937663867563&q=conspira...http://www.voxfux.com/features/bush_child_sex_coverup/franklin.htm
> There are two main suspects in the child ring were Craig Spence and
> Lawrence E. King Jr. Below are some pictures of them. Both were
> involved in the Republican party. King sang the National athem at two
> republican national conventions during the 1980s. He served time in
> jail for bank fraud and is now living somewhere on the east coast.
> Spence was an important Republican lobbyist, who feared that, because
> he knew something very dark, implicating the very most powerful man in
> America, George H. W. Bush, that he would be killed by the CIA at his
> murder would be made to look like a suicide. He was later found dead in
> a hotel room - the CIA connected coroner declared the bizarre death
> -suicide. Several of his partners went to jail for being involved in
> the adult part of the homosexual sex ring. Democrats were also involved
> in this as well, so don't expect them to expose the sex ring.
>
> =
> HOW 9/11 actually may have happened , WE HAVE BEEN MADE FOOLS OF THE
> CENTURY by the media
> From:
> American Patriot Friends Network
>
> http://www.apfn.org/apfn/WTC_STF.htm
>
> The only thing to be afraid is cowardice itself. The news is spreading
> like a jungle fire.
> In your workplace, send email to everyone and anonymously about this
> site and other top sites
>
> Make a free email account:www.gmail.com
> =
> Holocaust Victims Accuse
> Product #: 

Re: Rendering text question (context is MSWin UI Automation)

2007-01-25 Thread Boris Borcic
Chris Mellon wrote:
>> Maybe. In any case, color separation solves my (sub)problem : the blue layer
>> from the wx generated model matches the green layer from the app's window, 
>> pixel
>> for pixel (at least with antialiasing and cleartype on, while writing black 
>> on
>> white).
>>
> 
> That's... extremely interesting.

Difficult to believe, you mean :) Well, you are right, somehow I mixed up layer 
colors; in the end I compare just the blue layers and it does what I wanted.

Cheers, BB

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


Re: Question about docutils

2007-01-25 Thread Damjan
>> I'm using docutils 0.4.
>> Is it possible to define special custom 'tags' (or something) that will
>> invoke my own function? The function would then return the real content
>> in the ReST document.
> 
> I -think- this is what you're looking for:
> http://docutils.sourceforge.net/docs/howto/rst-roles.html
> 
> Hope it helps.

Thanks, it looks to be exactly what I need... I'm reading it now, and will
try to implement it.


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


Re: Possible bug in Python 2.5? (Was Re: pdb in python2.5)

2007-01-25 Thread R. Bernstein
"Rotem" <[EMAIL PROTECTED]> writes:

> Hi,
> 
> I noticed that pydb.pm() also fails in python2.5 when invoked on that
> same example (seems like also trying to access a nonexistent
> attribute/variable).
> 
> Is this known to you as well/was it fixed?

Doesn't do that for me for Python 2.5 on both pydb 1.20 (last released
version) and the current CVS. See below. If you think the problem is
not on your end and want to file a bug report, please do. But note

  * comp.lang.python is not the place to file bug reports
  * more detail is needed that what's been given so far

$ cat /tmp/t1.py
from __future__ import with_statement
import threading

def f():
l = threading.Lock()
with l:
print "hello"
raise Exception("error")
print "world"

try:
f()
except:
   import pydb
   pydb.pm()
$ python /tmp/t1.py
hello
(/tmp/t1.py:9):  f
(Pydb) where
-> 0 f() called from file '/tmp/t1.py' at line 9
## 1 () called from file '/tmp/t1.py' at line 15
(Pydb) show version
pydb version 1.20.
(Pydb) quit
$ python /tmp/t1.py 
hello
(/tmp/t1.py:15):  
(Pydb) where
## 0 f() called from file '/tmp/t1.py' at line 8
-> 1 () called from file '/tmp/t1.py' at line 15
(Pydb) show version
pydb version 1.21cvs.
(Pydb) quit
$ 


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


Re: Catching floating point errors from linked C code

2007-01-25 Thread John Pye
Hi John

I think you're right, and I need to place FPE 'brackets' around my
code.

The thing that was confusing me was that python has division by zero
exceptions (for which I assumed fenv.h was being used), but when from
python I reach down into my SWIG code and do a 1/0, no SIGFPE is
thrown.

I will experiment with the _controlfp stuff (and linux equivs) and see
how it goes. Thanks for your help.

Cheers
JP


On Jan 25, 5:12 pm, John Nagle <[EMAIL PROTECTED]> wrote:
> John Pye wrote:
> > Hi John,
>
> > On Jan 25, 3:43 pm, John Nagle <[EMAIL PROTECTED]> wrote:
>
> >>Python is probably running with floating point exceptions disabled,
> >>but you can enable them in your C code, and restoring the floating
> >>point mode when you leave, if you want.  This is probably
> >>only worth doing under a debugger, because otherwise you just end
> >>up with an aborted instance of Python.
>
> > So as far as you know, Python doesn't switch stuff like
> > feenableexcept(FE_EXCEPT_ALL)? Does Python use the 
> > internally, or are all its FPEs detected by explicit checks beforehand?
> > I have no idea what state Python leaves the FPU in, but whatever
> the state is, you can read it, set your own state, and restore
> the previous state before returning to Python.
>
> The last time I had to do this, I used
>
> unsigned int oldstate = // make almost all FPU errors fatal
> _controlfp ((~_EM_INVALID) & _CW_DEFAULT, _MCW_EM);
> ...
> _controlfp(oldstate);   // restore old state
>
> on Windows 2000.
> 
> John Nagle

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


[ANN] markup.py 1.6

2007-01-25 Thread Daniel Nogradi
The new 1.6 release of markup.py is available for download:

http://sourceforge.net/project/showfiles.php?group_id=161108

What is it?

Markup.py is an intuitive, lightweight, easy-to-use, customizable and
pythonic HTML/XML generator.

Where is the documentation?

http://markup.sourceforge.net/

Why is it called markup.py and not markup?

This way it's easier to search for it online and also shows that it's
a single module. Also note that the former Markup project of Edgewall
changed its name to Genshi in the meantime.

Please send comment/feedback/bugs/etc to [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stop script w/o exiting interpreter

2007-01-25 Thread Paul Rubin
"Alan Isaac" <[EMAIL PROTECTED]> writes:
> I'm fairly new to Python and I've lately been running a script at
> the interpreter while working on it.  Sometimes I only want to
> run the first quarter or half etc.  What is the "good" way to do this?

If it's single threaded then just call sys.exit().  If you don't know
what single threaded means, your program is definitely single threaded.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pdf to text

2007-01-25 Thread Dieter Deyke
tubby writes:

> David Boddie wrote:
>
>> The pdftotext tool may do what you want:
>>
>>   http://www.foolabs.com/xpdf/download.html
>>
>> Let us know how you get on with it.
>>
>> David
>
> Perhaps I'm just using pdftotext wrong? Here's how I was using it:
>
> f = filename
>
> try:
> sout = os.popen('pdftotext "%s" - ' %f)
> data = sout.read().strip()
> print data
> sout.close()
>
> except Exception, e:
> print e

I am using pdftotext on Windows with cygwin on a regular basis without
any problem.

Your program above should read:

   sout = os.popen('pdftotext "%s" - ' % (f,))

--
Dieter Deyke

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
-- 
http://mail.python.org/mailman/listinfo/python-list


stop script w/o exiting interpreter

2007-01-25 Thread Alan Isaac
I'm fairly new to Python and I've lately been running a script at
the interpreter while working on it.  Sometimes I only want to
run the first quarter or half etc.  What is the "good" way to do this?

Possible ugly hacks include:

- stick an undefined name at the desired stop point
- comment out the last half

I do not like these and assume that I have overlooked the obvious.

Thanks,
Alan Isaac


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


Re: pdf to text

2007-01-25 Thread Lee Harr

> Perhaps I'm just using pdftotext wrong? Here's how I was using it:
>

>  sout = os.popen('pdftotext "%s" - ' %f)


If you are having trouble with popen (not unlikely)
how about just writing to a temporary file and 
reading the text from there?

I've used pdftotext several times in the past few
weeks (but not on windows). It was a major
time saver for me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fast Imaging for Webserver

2007-01-25 Thread Prateek
Thanks for all the responses so far..

The 'imaging' app that I mentioned is actually serving as a library for
a bunch of other apps.
A typical scenario is icon processing. The source image *could* be
large (in this case it was 128x128 PNGA)

Think of it as a Mac Finder/Win Explorer style view (grid + imagelist)
where you're showing a bunch of data in icon form (16x16). For small
amounts of data, everything is ok... but as soon as I get to 600-700
items, the page takes forever to load. The obvious solution is
pagination but I'm doing some aggregate analysis on the data (like a
frequency distribution) where if I were to paginate the data, i'd lose
the client-side sorting ability (I'd have to sort server side which is
a whole other can of worms).

I'm gonna take Paul's advice and report as soon as I can. One other
alternative is to save this information on the filesystem (as temp
files) and route all future requests via the static file processing
mechanism (which can be handled by Apache)... do you think that is a
good idea?

Prateek

On Jan 25, 3:11 pm, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:
> "Prateek" wrote:
> > Hi. I'm creating a web-application using CherryPy 2.2.1. My application
> > needs to process images (JPG/PNG files) to
>
> > 1) create thumbnails (resize them)
> > 2) overlay them on a custom background (a simple frame)
> > 3) Overlay 'badges' (small 16x16 images) on top of the final thumbnail
>
> > I am using PIL 1.1.5 which I have custom compiled on my development
> > machine (MacBook Pro 2.33Ghz Core Duo)..
> > I am using im.thumbnail for step 1 and im.paste for steps 2 and 3.
>
> > The problem is that this thing is just way too slow.
> > For ab -n 1000 -C session_id=2f55ae2dfefa896f67a80f73045aadfa4b4269f1
> >http://localhost:8080/imaging/icon/def/128/255(where def is the name
> > of the image - default in this case - 128 is the size in pixels and 255
> > is the background color), I am getting:
>
> > Document Path:  /imaging/icon/def/128/255
> > Document Length:14417 bytes
>
> > Concurrency Level:  1
> > Time taken for tests:   18.664 seconds
> > Complete requests:  1000
> > Failed requests:0
> > Broken pipe errors: 0
> > Total transferred:  1468 bytes
> > HTML transferred:   14417000 bytes
> > Requests per second:53.58 [#/sec] (mean)
> > Time per request:   18.66 [ms] (mean)
> > Time per request:   18.66 [ms] (mean, across all concurrent
> > requests)
> > Transfer rate:  786.54 [Kbytes/sec] received
>
> > FYI: This request returns a PNG image (image/png) and not html
>
> > My understanding is that the problem is either with the CherryPy setup
> > (which is likely because even in other cases, i don't get much more
> > than 65 requests per second) or PIL itself (even though I'm caching the
> > background images and source images)without knowing more about what kind of 
> > source images you're using, the
> amount of data they represent etc, it's not entirely obvious to me that 50+
> images per second on a single server is that bad, really.  unless the source
> images are rather tiny, that's plenty of pixels per second to crunch.
>
> are you really receiving more than 450 source images per day per
> server?
> 
> 

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


Re: Right-Justifying Numeric Output

2007-01-25 Thread Tobiah

>   Thank you very much! I didn't see this in any of my Python books or on 
> the

I like to look at the printf docs for any C compiler.  On Unix,
man 3 printf


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

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


Re: Right-Justifying Numeric Output

2007-01-25 Thread Rich Shepard
On Thu, 25 Jan 2007, hg wrote:

> assuming max size = 10
>
> #with spaces
>>> '% 10d' % 11
> '11'
> #with zeros
>>> '%010d' % 11
> '11'

   Thank you very much! I didn't see this in any of my Python books or on the
Web.

Rich

-- 
Richard B. Shepard, Ph.D.   |The Environmental Permitting
Applied Ecosystem Services, Inc.|  Accelerator(TM)
 Voice: 503-667-4517  Fax: 503-667-8863
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Right-Justifying Numeric Output

2007-01-25 Thread hg
Rich Shepard wrote:

>I have this print statement in a function:
> 
> print '%2d   $%11.2f  $%10.2f  $%9.2f  $%9.2f' %(nper, pv, diff, ten,
> bonus)
> 
> and I would like to have the output right justified in the specified
> field. My trials using .rjust(n) have produced that string in the output,
> not the intended results. Is there a way of right justifying numeric
> output?
> 
> Thanks,
> 
> Rich
> 
> --
> Richard B. Shepard, Ph.D.   |The Environmental Permitting
> Applied Ecosystem Services, Inc.|  Accelerator(TM)
>  Voice: 503-667-4517  Fax:
> 503-667-8863

assuming max size = 10

#with spaces 
>> '% 10d' % 11
'11'
#with zeros
>>'%010d' % 11
'11'

hg

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


Right-Justifying Numeric Output

2007-01-25 Thread Rich Shepard
   I have this print statement in a function:

print '%2d   $%11.2f  $%10.2f  $%9.2f  $%9.2f' %(nper, pv, diff, ten, bonus)

and I would like to have the output right justified in the specified field.
My trials using .rjust(n) have produced that string in the output, not the
intended results. Is there a way of right justifying numeric output?

Thanks,

Rich

-- 
Richard B. Shepard, Ph.D.   |The Environmental Permitting
Applied Ecosystem Services, Inc.|  Accelerator(TM)
 Voice: 503-667-4517  Fax: 503-667-8863
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pdf to text

2007-01-25 Thread tubby
David Boddie wrote:

> The pdftotext tool may do what you want:
> 
>   http://www.foolabs.com/xpdf/download.html
> 
> Let us know how you get on with it.
> 
> David

Perhaps I'm just using pdftotext wrong? Here's how I was using it:

f = filename

try:
 sout = os.popen('pdftotext "%s" - ' %f)
 data = sout.read().strip()
 print data
 sout.close()

except Exception, e:
 print e
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pdf to text

2007-01-25 Thread tubby
David Boddie wrote:
> The pdftotext tool may do what you want:
> 
>   http://www.foolabs.com/xpdf/download.html
> 
> Let us know how you get on with it.

I have used this tool. However, I need PDF read ability on Windows and 
Linux and in the future Macs. pdftotext works great on Linux, but poorly 
on Windows (100% sustained CPU usage, etc).

Thank you for the suggestion. I'll keep hammering away at a simple 
Python solution to this. Over the years, I have come to loath Adobe's 
Portable Document Format!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pdf to text

2007-01-25 Thread David Boddie
On Thursday 25 January 2007 22:05, tubby wrote:

> I know this question comes up a lot, so here goes again. I want to read
> text from a PDF file, run re searches on the text, etc. I do not care
> about layout, fonts, borders, etc. I just want the text. I've been
> reading Adobe's PDF Reference Guide and I'm beginning to develop a
> better understanding of PDF in general, but I need a bit of help... this
> seems like it should be easier than it is.

It _seems_ that way. ;-)

One of the more promising suggestions for a way to solve this came
up in a comp.lang.python thread last year:

http://groups.google.com/group/comp.lang.python/msg/cb6c97a44ce4cbe9?dmode=source

Basically, if you have access to the pdftotext command on a system
that supports xpdf, you should be able to get something reasonable
out of a PDF file.

> I know the text is compressed... that it would have stream and endstream
> makers and BT (Begin Text) and ET (End Text) and that the uncompressed
> text is enclosed in parenthesis (this is my text). Has anyone here done
> this in a simple fashion? I've played with the pyPdf library some, but
> it seems overly complex for my needs (merge PDFs, write PDFs, etc). I
> just want a simple PDF text extractor.

The pdftotext tool may do what you want:

  http://www.foolabs.com/xpdf/download.html

Let us know how you get on with it.

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


Re: pdf to text

2007-01-25 Thread Nils Oliver Kröger
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

have a look at the pdflib (www.pdflib.com). Their Text Extraction
Toolkit might be what you are looking for, though I'm not sure whether
you can use it detached from the pdflib itself.

hth

Nils

tubby schrieb:
> I know this question comes up a lot, so here goes again. I want to read 
> text from a PDF file, run re searches on the text, etc. I do not care 
> about layout, fonts, borders, etc. I just want the text. I've been 
> reading Adobe's PDF Reference Guide and I'm beginning to develop a 
> better understanding of PDF in general, but I need a bit of help... this 
> seems like it should be easier than it is. Here's some code:
> 
> import zlib
> 
> fp = open('test.pdf', 'rb')
> bytes = []
> while 1:
>  byte = fp.read(1)
>  #print byte
>  bytes.append(byte)
>  if not byte:
>  break
> 
> for byte in bytes:
> 
>  op = open('pdf.txt', 'a')
> 
>  dco = zlib.decompressobj()
> 
>  try:
>  s = dco.decompress(byte)
>  #print >> op, s
>  print s
>  except Exception, e:
>  print e
> 
>  op.close()
> 
> fp.close()
> 
> I know the text is compressed... that it would have stream and endstream 
> makers and BT (Begin Text) and ET (End Text) and that the uncompressed 
> text is enclosed in parenthesis (this is my text). Has anyone here done 
> this in a simple fashion? I've played with the pyPdf library some, but 
> it seems overly complex for my needs (merge PDFs, write PDFs, etc). I 
> just want a simple PDF text extractor.
> 
> Thanks

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFuSPozvGJy8WEGTcRAnY0AJ0VZez3XRbLm/JXZKhn/rgHP0R3qwCfWAnT
EupBECHab2kG33Rmnh+xf74=
=INM5
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible bug in Python 2.5? (Was Re: pdb in python2.5)

2007-01-25 Thread Rotem
Hi,

I noticed that pydb.pm() also fails in python2.5 when invoked on that
same example (seems like also trying to access a nonexistent
attribute/variable).

Is this known to you as well/was it fixed?

On Jan 25, 9:15 pm, [EMAIL PROTECTED] (R. Bernstein) wrote:
> I'd like to change my assessment of whether the problem encountered is
> a pdb bug or not. It could be a bug in Python. (Right now it is only
> known to be a bug in version 2.5.)
>
> For a given traceback t, the question is whether t.tb_frame.f_lineno
> can ever be different from t.tb_lineno.
>
> Still, for now in pydb CVS, I've worked around this by checking.
>
> [EMAIL PROTECTED] (R. Bernstein) writes:
> > "Rotem" <[EMAIL PROTECTED]> writes:
>
> > > Hi,
>
> > > Maybe I'm repeating a previous post (please correct me if I am).
>
> > > I've tried the following code in python 2.5 (r25:51908, Oct  6 2006,
> > > 15:22:41)
> > > example:
>
> > > from __future__ import with_statement
> > > import threading
>
> > > def f():
> > > l = threading.Lock()
> > > with l:
> > > print "hello"
> > > raise Exception("error")
> > > print "world"
>
> > > try:
> > > f()
> > > except:
> > >import pdb
> > >pdb.pm()
>
> > > This fails because pdb.pm() attempts to access sys.last_traceback which
> > > is not assigned.
>
> > Recent releases of pydb (http://bashdb.sf.net/pydb) don't suffer this
> > problem. (But see below.)
>
> > > Trying:
> > > pdb.post_mortem(sys.exc_traceback)
>
> > > Yields the following:
> > > > test.py(9)f()
> > > -> print "world"
> > > (Pdb)
>
> > > the 'w' command yields a similar output, which implies that the
> > > exception was thrown from the wrong line.
> > > the traceback module is better, yielding correct results (displays line
> > > 8 instead of 9).
>
> > > Has anyone encountered this behavior?
>
> > Yes, this seems to be a bug in pdb. It is using the traceback's f_line
> > instance variable rather than the tb_lineno instance variable. I guess
> > these two values are usually the same. In fact, I haven't been able to
> > come up with a Python 2.4 situtation where they are different. (If
> > someone can, I'd appreciate it if you'd send me a small example so I
> > can put it in the pydb regression tests.) Even in 2.5, it's kind of
> > hard to get a case where they are different. If I remove the "with",
> > the problem goes away.
>
> > It was also bug in pydb, but I've just committed in CVS the fix for
> > this
>
> > > is pdb broken?
>
> > Best as I can tell pdb isn't all that well maintained. (Had it been, I
> > probably wouldn't have devoted the time to pydb that I have been.)
>
> > > I get similar results for larger/more complex pieces of code.
> 
> > > Thanks in advance,
> 
> > > Rotem

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


Re: selective logger disable/enable

2007-01-25 Thread Gary Jefferson
Gary Jefferson wrote:
> So maybe I don't have all this figured out quite as well as I thought.
> What I really want to do is set an environment variable, MYDEBUG, which
> contains a list of wildcarded logger names, such as "a.*.c a.d" (which
> becomes ['a.*.c', 'a.d'], and then selectively crank the loglevel up to
> DEBUG for those that match.
>
> In order to do that, I think I need something kind of like filters, but
> for logger name... I'm not seeing how to do this, even after playing
> with variations of test15, 18, and 21.
>
> What I do have working at the moment is passing a list of non-wildcard
> logger names, i.e., doing the wildcard expansion manually such as
> "['a.b.c', 'a.c.c', 'a.f.c', 'a.d'].  Is there anyway to automate this
> dynamically?
>
> BTW, I do understand that 'a.d' is essentially equivalent to 'a.d.*',
> but I'm dealing with a hierarchy that doesn't always tidy up like that.
>  For example, I have top.network.server.http, top.network.server.smtp,
> top.network.client.http, and top.network.client.smtp.  Obviously, if I
> only want server or client DEBUG msgs, this is easy.  And sometimes
> that's exactly what I want.  Other times, I want only smtp DEBUG msgs,
> and the hierarchy won't help me get that (unless I break it for just
> getting client or server msgs), etc.  So I would really like to figure
> out how to do 'a.*.c'.
>
> Any ideas?
>
> Thanks again,
> Gary


Okay, I think I'm back on track again: I can do regex comparisons
against the name field of the LogRecord instance handed to me by
filter().

Gary

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


Fwd: asyncore.dispatcher.handle_read

2007-01-25 Thread Indy
-- Forwarded message --
From: Indy <[EMAIL PROTECTED]>
Date: Jan 25, 2007 11:27 PM
Subject: Re: asyncore.dispatcher.handle_read
To: Jordan <[EMAIL PROTECTED]>


OK, problem fixed. Thanks anyway :-)

On 25 Jan 2007 10:08:01 -0800, Jordan <[EMAIL PROTECTED]> wrote:
> That was not entirely helpful, it's way more likely a mistake you made
> in subclassing dispatcher than a problem within asycore itself (that
> ended up sounding a lot more mean/angry than intended, sorry ¬_¬ ),
> you really need to show us what changes you made to asyncore.dispatcher
> if you want help.  Good luck.
>
> Cheers,
> Jordan
>
> On Jan 25, 12:18 pm, Indy <[EMAIL PROTECTED]> wrote:
> > Greetings.
> >
> > I am writing an asynchronous server, and I use the standard library's
> > module asyncore.
> > I subclass asyncore.dispatcher. handle_accept works just right, that
> > is, when a client socket makes a request to connect to my server
> > socket, things that I set in handle_accept definition, happen. So, it
> > is OK. But, the problem is that handle_read does not work as expected.
> > Things I set in handle_read definition, do not happen when a client
> > socket sends me data. Why? Is this a known problem? Please, can you
> > help me?
> > Thanks a lot, in advance.
> >
> > Best regards,
> > Aristotelis Mikropoulos
> >
> > --
> > Programs must be written for people to read, and only incidentally for
> > machines to execute.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
Programs must be written for people to read, and only incidentally for
machines to execute.


-- 
Programs must be written for people to read, and only incidentally for
machines to execute.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: logging module and doctest

2007-01-25 Thread Gary Jefferson
Peter Otten wrote:
> Peter Otten wrote:
>
> > Gary Jefferson wrote:
> >
> >> I've written a logging.filter and would like to use doctest on it
> >> (using a StreamHandler for stdout), but this doesn't seem possible.
> >> Output from the logger seems to disappear (running the doctest strings
> >> through the interpreter as-is yields expected results).  I assume this
> >> is because doctest does something with logging.
> >
> > It redirects stdout to a StringIO subclass to capture the output.
> >
> >> Is there any way to make these work together?
> >
> > Using the StreamHandler with something like
> >
> > class WrapStdOut(object):
> > def __getattr__(self, name):
> > return getattr(sys.stdout, name)
> >
> > instead of sys.stdout directly should work.
>
> Or create the StreamHandler inside your doctest where sys.stdout is already
> redirected.
>
> Peter

I was creating the StreamHandler inside doctest.  Turns out, however,
that I hadn't imported 'sys', and so it didn't work.  Its a little
strange that this didn't result in an error, but there you have it.

Thanks for the tip that led me to discover this.

Gary

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


Re: Python does not play well with others

2007-01-25 Thread Jarek Zgoda
Harry George napisał(a):

> You experience isn't shared by everyone.  Some of us find Python the
> most functional and portable of the candidates you mention.

The point on MySQLdb is rather common, many people who used it with
SQLObject will confirm. Fortunately for MySQLdb, the MySQL on its own is
much worse. Fortunately for us, the MySQLdb library is not a part of
Python distribution, so Python can not be blamed for its deficiencies. ;)

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The reliability of python threads

2007-01-25 Thread Nick Maclaren

In article <[EMAIL PROTECTED]>,
"Paddy" <[EMAIL PROTECTED]> writes:
|> 
|> No, you should think of the service that needs to be up. You seem to be
|> talking about how it can't be fixed rather than looking for ways to
|> keep things going. A little learning is fine but "it can't
|> theoretically be fixed" is no solution.

I suggest that you do invest in a little learning and look up Poisson
processes.

|> Keep your eye on the goal and your more likely to score!

And, if you have your eye on the wrong goal, you would generally be
better off not scoring :-)


Regards,
Nick Maclaren.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The reliability of python threads

2007-01-25 Thread Paul Rubin
"Paddy" <[EMAIL PROTECTED]> writes:
> > But you're proposing cargo cult programming.
> i don't know that term.

http://en.wikipedia.org/wiki/Cargo_cult_programming

> What I'm proposing is that if, for example, a process stops running
> three times in a year at roughly three to four months intervals ,
> and it should have stayed up; then restart the server sooner, at aa
> time of your choosing,

What makes you think that restarting the server will make it less
likely to fail?  It sounds to me like there's zero evidence of that,
since you say "roughly three or four month intervals" and talk about
threading and race conditions.  If it's failing every 3 months, 15
days and 2.43 hours like clockwork, that's different, sure, restart it
every three months.  But the description I see so far sounds like a
random failure caused by some events occurring with low enough
probability that they only happen on average every few months of
operation.  That kind of thing is very common and is often best
diagnosed by instrumenting the hell out of the code.

> > There is no reason whatsoever to expect that restarting the server
> > now and then will help the problem in the slightest.
> Thats where we most likely differ.

Do you think there is a reason to expect that restarting the server
will help the problem in the slightest?  I realize you seem to expect
that, but you have not given a REASON.  That's what I mean by cargo
cult programming.

> Whilst you sit agreeing on how many fairys can dance on the end of a
> pin or not Your company could be loosing customers. You and Nick seem
> to be saying it *must* be Poisson, therefore we can't do...

I dunno about Nick, I'm saying it's best to assume that it's Poisson
and do whatever is necessary to diagnose and fix the bug, and that the
voodoo measure you're proposing is not all that likely to help and it
will take years to find out whether it helps or not (i.e. restarting
after 3 months and going another 3 months without a failure proves
nothing).

> I'm sorry, but your argument reminds me of when Western statistical
> quality control first met with the Japanese Zero defects methodologies.
> We had argued ourselves into accepting a certain amount of defective
> cars getting out to customers as the result of our theories. The
> Japanese practices emphasized *no* defects were acceptable at the
> customer, and they seemed to deliver better made cars.

I don't see your point.  You're the one who wants to keep operating
defective software instead of fixing it.

> "at random" - "every few months"
> Me thinking it happens "every few months" allows me to search for a
> fix.  If thinking it happens "at random" leads you to a brick wall,
> then switch!

But you need evidence before you can say it happens every few months.
Do you have, say, a graph of the exact dates and times of failure, the
number of requests processed so far, etc.?  If it happened at some
exact or almost exact uniform time interval or precisely once every
1.273 million requests or whatever, that tells you something.  But the
earlier description didn't sound like that.  Restarting the server is
not much better than carrying a lucky rabbit's foot.
-- 
http://mail.python.org/mailman/listinfo/python-list


pdf to text

2007-01-25 Thread tubby
I know this question comes up a lot, so here goes again. I want to read 
text from a PDF file, run re searches on the text, etc. I do not care 
about layout, fonts, borders, etc. I just want the text. I've been 
reading Adobe's PDF Reference Guide and I'm beginning to develop a 
better understanding of PDF in general, but I need a bit of help... this 
seems like it should be easier than it is. Here's some code:

import zlib

fp = open('test.pdf', 'rb')
bytes = []
while 1:
 byte = fp.read(1)
 #print byte
 bytes.append(byte)
 if not byte:
 break

for byte in bytes:

 op = open('pdf.txt', 'a')

 dco = zlib.decompressobj()

 try:
 s = dco.decompress(byte)
 #print >> op, s
 print s
 except Exception, e:
 print e

 op.close()

fp.close()

I know the text is compressed... that it would have stream and endstream 
makers and BT (Begin Text) and ET (End Text) and that the uncompressed 
text is enclosed in parenthesis (this is my text). Has anyone here done 
this in a simple fashion? I've played with the pyPdf library some, but 
it seems overly complex for my needs (merge PDFs, write PDFs, etc). I 
just want a simple PDF text extractor.

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


Re: Python does not play well with others

2007-01-25 Thread Paul Rubin
John Nagle <[EMAIL PROTECTED]> writes:
> That's the problem.  We now have four SSL implementations for
> Python, none of which let you do all the things OpenSSL can do.

I'm aware of some OpenSSL wrappers plus TLSlite.  Am I missing a
couple more?  I guess maybe the OpenSSL wrappers also work on GnuTLS.

> Can you build the built-in SSL package without building all of
> Python?  

I thought there was no built-in SSL package-- it just calls OpenSSL.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not play well with others

2007-01-25 Thread John Nagle
Paul Rubin wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> 
>>I haven't had a need to do anything with OpenSSL from Python; all
>>that takes place in the Apache server 
> 
> 
> That's a reasonable approach for a typical server-side web
> application, but there are other types of Python apps that can also
> want to use SSL.  It's a pain to have to deal with OpenSSL at all, and
> I hope that TLSLite (a very incomplete SSL implementation written in
> pure Python) one day becomes complete and does all the stuff that JSSE
> does.

That's the problem.  We now have four SSL implementations for
Python, none of which let you do all the things OpenSSL can do.

The fact that people keep writing new ones, instead of fixing the
existing ones, indicates a problem with the development process.

Can you build the built-in SSL package without building all of
Python?  That in itself would be useful.  Then the thing could
be worked on without too much pain.  The built-in SSL package
basically works, although it doesn't check anything.  It just
doesn't get at enough OpenSSL functionality.

I think the right way out of this mess is to 1) break
out the SSL module so it can be built separately by the
usual "python setup.py build" process, 2) add more
access functions to the built-in SSL C glue module, 3) bring over
such Python parts of M2Crypto as are useful and make them
work with the built-in SSL module, and 4) get rid of SWIG.

If somebody will do 1), I'll take a look at 2).

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


Re: The reliability of python threads

2007-01-25 Thread Paddy


On Jan 25, 8:00 pm, Paul Rubin  wrote:
> "Paddy" <[EMAIL PROTECTED]> writes:
> > No, you should think of the service that needs to be up. You seem to be
> > talking about how it can't be fixed rather than looking for ways to
> > keep things going.
> But you're proposing cargo cult programming.
i don't know that term. What I'm proposing is that if, for example, a
process stops running three times in a year at roughly three to four
months intervals , and it should have stayed up; then restart the
server sooner, at aa time of your choosing, whilst taking other
measures to investicate the error.
> There is no reason
> whatsoever to expect that restarting the server now and then will help
> the problem in the slightest.
Thats where we most likely differ. The problem is only indirecctly the
program failing. the customer wants reliable service. Which you can get
from unreliable components. It happens all the time in firmware
controlled systems that periodically reboot themselves as a matter of
course.
> Nick used the fancy term Poisson
> process but it just means that the probability of failure at any
> moment is independent of what's happened in the past, like the
> spontaneous radioactive decay of an atom.  It's not like a mechanical
> system where some part gradually gets worn out and eventually breaks,
> so you can prevent the failure by replacing the part every so often.
Whilst you sit agreeing on how many fairys can dance on the end of a
pin or not Your company could be loosing customers. You and Nick seem
to be saying it *must* be Poisson, therefore we can't do...
>
> > A little learning is fine but "it can't theoretically be fixed" is
> > no solution.The best you can do is identify the unfixable situations 
> > precisely and
> work around them.  Precision is important.
I'm sorry, but your argument reminds me of when Western statistical
quality control first met with the Japanese Zero defects methodologies.
We had argued ourselves into accepting a certain amount of defective
cars getting out to customers as the result of our theories. The
Japanese practices emphasized *no* defects were acceptable at the
customer, and they seemed to deliver better made cars.
>
> The next best thing is have several servers running simultaneously,
> with failure detection and automatic failover.
Yah, finally. I can work with that
>
> If a server is failing at random every few months, trying to prevent
> that by restarting it every so often is just shooting in the dark.
"at random" - "every few months"
Me thinking it happens "every few months" allows me to search for a
fix.
If thinking it happens "at random" leads you to a brick wall, then
switch!

> Think of your server stopping now and then because there's a power
> failure, where you get power failures every few months on the average.
> Shutting down your server once a month, unplugging it, and plugging it
> back in will do nothing to prevent those outages.  You need to either
> identify and fix whatever is causing the power outages, or install a
> backup generator.

Yep. I also know that a mad bloke entering the server room with a
hammer every three to four months is also not likely to be fixed by
restarting the server every two months ;-)

- Paddy.

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


Re: running applications in python

2007-01-25 Thread Daniel
2007-01-25 18:28:44
lee <[EMAIL PROTECTED]> wrote in message
<[EMAIL PROTECTED]>

> how can i run or open a windows application from the python 
prompt?for
> e.g.mediaplayer opening,folder acess etc

Here's another way of doing it:
import os 
TheCommandIwantTorun = '"C:\Program\Windows Media Player\wmplayer.
exe"' #saves the command to a string 
os.system(TheCommandIwantTorun) #runs TheCommandIwantTorun in the 
command prompt (windows)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not play well with others

2007-01-25 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> I haven't had a need to do anything with OpenSSL from Python; all
> that takes place in the Apache server 

That's a reasonable approach for a typical server-side web
application, but there are other types of Python apps that can also
want to use SSL.  It's a pain to have to deal with OpenSSL at all, and
I hope that TLSLite (a very incomplete SSL implementation written in
pure Python) one day becomes complete and does all the stuff that JSSE
does.

> (possibly with some mod_rewrite rules to ensure that certain pages
> are only hit from https and so forth).

Normally you'd do that SSLRequireSSL or SSLRequire, if that matters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The reliability of python threads

2007-01-25 Thread Paul Rubin
"Paddy" <[EMAIL PROTECTED]> writes:
> No, you should think of the service that needs to be up. You seem to be
> talking about how it can't be fixed rather than looking for ways to
> keep things going.

But you're proposing cargo cult programming.  There is no reason
whatsoever to expect that restarting the server now and then will help
the problem in the slightest.  Nick used the fancy term Poisson
process but it just means that the probability of failure at any
moment is independent of what's happened in the past, like the
spontaneous radioactive decay of an atom.  It's not like a mechanical
system where some part gradually gets worn out and eventually breaks,
so you can prevent the failure by replacing the part every so often.

> A little learning is fine but "it can't theoretically be fixed" is
> no solution.

The best you can do is identify the unfixable situations precisely and
work around them.  Precision is important.

The next best thing is have several servers running simultaneously,
with failure detection and automatic failover.  

If a server is failing at random every few months, trying to prevent
that by restarting it every so often is just shooting in the dark.
Think of your server stopping now and then because there's a power
failure, where you get power failures every few months on the average.
Shutting down your server once a month, unplugging it, and plugging it
back in will do nothing to prevent those outages.  You need to either
identify and fix whatever is causing the power outages, or install a
backup generator.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not play well with others

2007-01-25 Thread [EMAIL PROTECTED]
On Jan 25, 12:17 pm, John Nagle <[EMAIL PROTECTED]> wrote:
> My main concern is with glue code to major packages.  The connections
> to OpenSSL, MySQL, and Apache (i.e. mod_python) all exist, but have major
> weaknesses.  If you're doing web applications, those are standard pieces
> which need to work right.  There's a tendency to treat those as abandonware
> and re-implement them as event-driven systems in Twisted.

In the real world I've worked on Python web apps at my last 3 jobs, and
they've all used mod_python and either MySQL or Postgres.  I haven't
had a need to do anything with OpenSSL from Python; all that takes
place in the Apache server (possibly with some mod_rewrite rules to
ensure that certain pages are only hit from https and so forth).

I think the impression that everyone's using some sexy new framework
like Django or TurboGears or Pylons on Twisted or lighttpd/wsgi is
pretty misleading, especially when it comes to companies with a
decent-size existing codebase (we're into the "fairly large" range with
about 325,000 lines of Python now--most is independent of the
architecture, but it'd still be an administratively sizeable
change)--the place I'm at currently is considering moving to
apache+wsgi, but that's a smaller change (and one that's been under
consideration for months now).

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


Re: The reliability of python threads

2007-01-25 Thread Paddy


On Jan 25, 7:36 pm, [EMAIL PROTECTED] (Nick Maclaren) wrote:
> In article <[EMAIL PROTECTED]>,"Paddy" <[EMAIL PROTECTED]> writes:|>
> |> > |> Three to four months before `strange errors`? I'd spend some time
> |> > |> correlating logs; not just for your program, but for everything 
> running
> |> > |> on the server. Then I'd expect to cut my losses and arrange to safely
> |> > |> re-start the program every TWO months.
> |> > |> (I'd arrange the re-start after collecting logs but before their
> |> > |> analysis. Life is too short).
> |> >
> |> > Forget it.  That strategy is fine in general, but is a waste of time
> |> > where threading issues are involved (or signal handling, or some types
> |> > of communication problem, for that matter).
> |>
> |> Nah, Its a great strategy. it keeps you up and running when all you
> |> know for sure is that you will most likely be able to keep things
> |> together for three months normally.
> |>
> |> The OP only thinks its a threading problem - it doesn't matter what the
> |> true fix will be, as long as arranging to re-start the server well
> ^
> |> before its likely to go down doesn't take too long, compared to your
>
> |> exploration of the problem, and, of course, you have to be able to
> |> afford the glitch in availability.
>
> Consider the marked phrase in the context of a Poisson process failure
> model, and laugh.  If you don't understand why I say that, I suggest
> finding out the properties of the Poisson process!
>
> Regards,
> Nick Maclaren.
No, you should think of the service that needs to be up. You seem to be
talking about how it can't be fixed rather than looking for ways to
keep things going. A little learning is fine but "it can't
theoretically be fixed" is no solution.
With a program that stays up for that long, the situation will usualy
work out for the better when either software versions are upgraded, or
OS and drivers are upgraded. (Sometimes as a result of the analysis,
sometimes not).

Keep your eye on the goal and your more likely to score!

- Paddy.

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


Re: Module for SVG?

2007-01-25 Thread Boris . Boutillier
Depending on the size of your project, the xist library from living
logic is supporting svg xml:
http://www.livinglogic.de/Python/xist/
http://www.livinglogic.de/Python/xist/ns/svg/

We've used it successfully, but later on came back to simply use the
standard dom creation tools in python to reduce dependencies.

Boris

On Jan 25, 10:58 am, "Sebastian Bassi" <[EMAIL PROTECTED]>
wrote:
> Hello,
>
> I foundhttp://www2.sfk.nl/svgas a Python module for writing SVG.
> Last update was in 2004 and I am not sure if there is something
> better.
> Any recommendation for generating SVG graphics?
> Best,
> SB.

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


Re: The reliability of python threads

2007-01-25 Thread Nick Maclaren

In article <[EMAIL PROTECTED]>,
"Paddy" <[EMAIL PROTECTED]> writes:
|> 
|> > |> Three to four months before `strange errors`? I'd spend some time
|> > |> correlating logs; not just for your program, but for everything running
|> > |> on the server. Then I'd expect to cut my losses and arrange to safely
|> > |> re-start the program every TWO months.
|> > |> (I'd arrange the re-start after collecting logs but before their
|> > |> analysis. Life is too short).
|> >
|> > Forget it.  That strategy is fine in general, but is a waste of time
|> > where threading issues are involved (or signal handling, or some types
|> > of communication problem, for that matter).
|> 
|> Nah, Its a great strategy. it keeps you up and running when all you
|> know for sure is that you will most likely be able to keep things
|> together for three months normally.
|> 
|> The OP only thinks its a threading problem - it doesn't matter what the
|> true fix will be, as long as arranging to re-start the server well
^
|> before its likely to go down doesn't take too long, compared to your
   
|> exploration of the problem, and, of course, you have to be able to
|> afford the glitch in availability.

Consider the marked phrase in the context of a Poisson process failure
model, and laugh.  If you don't understand why I say that, I suggest
finding out the properties of the Poisson process!


Regards,
Nick Maclaren.
-- 
http://mail.python.org/mailman/listinfo/python-list


Possible bug in Python 2.5? (Was Re: pdb in python2.5)

2007-01-25 Thread R. Bernstein
I'd like to change my assessment of whether the problem encountered is
a pdb bug or not. It could be a bug in Python. (Right now it is only
known to be a bug in version 2.5.)

For a given traceback t, the question is whether t.tb_frame.f_lineno
can ever be different from t.tb_lineno.

Still, for now in pydb CVS, I've worked around this by checking.

[EMAIL PROTECTED] (R. Bernstein) writes:

> "Rotem" <[EMAIL PROTECTED]> writes:
> 
> > Hi,
> > 
> > Maybe I'm repeating a previous post (please correct me if I am).
> > 
> > I've tried the following code in python 2.5 (r25:51908, Oct  6 2006,
> > 15:22:41)
> > example:
> > 
> > from __future__ import with_statement
> > import threading
> > 
> > def f():
> > l = threading.Lock()
> > with l:
> > print "hello"
> > raise Exception("error")
> > print "world"
> > 
> > try:
> > f()
> > except:
> >import pdb
> >pdb.pm()
> > 
> > This fails because pdb.pm() attempts to access sys.last_traceback which
> > is not assigned.
> 
> Recent releases of pydb (http://bashdb.sf.net/pydb) don't suffer this
> problem. (But see below.)
> 
> > Trying:
> > pdb.post_mortem(sys.exc_traceback)
> > 
> > Yields the following:
> > > test.py(9)f()
> > -> print "world"
> > (Pdb)
> > 
> > the 'w' command yields a similar output, which implies that the
> > exception was thrown from the wrong line.
> > the traceback module is better, yielding correct results (displays line
> > 8 instead of 9).
> > 
> > Has anyone encountered this behavior? 
> 
> Yes, this seems to be a bug in pdb. It is using the traceback's f_line
> instance variable rather than the tb_lineno instance variable. I guess
> these two values are usually the same. In fact, I haven't been able to
> come up with a Python 2.4 situtation where they are different. (If
> someone can, I'd appreciate it if you'd send me a small example so I
> can put it in the pydb regression tests.) Even in 2.5, it's kind of
> hard to get a case where they are different. If I remove the "with",
> the problem goes away.
> 
> It was also bug in pydb, but I've just committed in CVS the fix for
> this
> 
> 
> > is pdb broken?
> 
> Best as I can tell pdb isn't all that well maintained. (Had it been, I
> probably wouldn't have devoted the time to pydb that I have been.)
> 
> > I get similar results for larger/more complex pieces of code.
> 
> > 
> > Thanks in advance,
> > 
> > Rotem
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do I need Python to run Blender correctly?

2007-01-25 Thread Boris Borcic
[EMAIL PROTECTED] wrote:
 > Also note that only standard modules bundled in the Blender package are
 > available. And extension modules e.g. numpy can't be installed into it.

Not my experience, I've installed and used numpy (or was it Numeric ?) with 
Blender Python a couple years ago.

YMMV, Boris Borcic

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


Re: The reliability of python threads

2007-01-25 Thread Carl J. Van Arsdall
Aahz wrote:
> [snip]
>
> My response is that you're asking the wrong questions here.  Our database
> server locked up hard Sunday morning, and we still have no idea why (the
> machine itself, not just the database app).  I think it's more important
> to focus on whether you have done all that is reasonable to make your
> application reliable -- and then put your efforts into making your app
> recoverable.
>   
Well, I assume that I have done all I can to make it reliable.  This 
list is usually my last resort, or a place where I come hoping to find 
ideas that aren't coming to me naturally.  The only other thing I 
thought to come up with was that there might be network errors.  But 
i've gone back and forth on that, because TCP should handle that for me 
and I shouldn't have to deal with it directly in pyro, although I've 
added (and continue to add) checks in places that appear appropriate 
(and in some cases, checks because I prefer to be paranoid about errors).


> I'm particularly making this comment in the context of your later point
> about the bug showing up only every three or four months.
>
> Side note: without knowing what error messages you're getting, there's
> not much anybody can say about your programs or the reliability of
> threads for your application.
>   
Right, I wasn't coming here to get someone to debug my app, I'm just 
looking for ideas.  I constantly am trying to find new ways to improve 
my software and new ways to reduce bugs, and when i get really stuck, 
new ways to track bugs down.  The exception won't mean much, but I can 
say that the error appears to me as bad data.  I do checks prior to 
performing actions on any data, if the data doesn't look like what it 
should look like, then the system flags an exception.

The problem I'm having is determining how the data went bad.  In 
tracking down the problem a couple guys mentioned that problems like 
that usually are a race condition.  From here I examined my code, 
checked out all the locking stuff, made sure it was good, and wasn't 
able to find anything.  Being that there's one lock and the critical 
sections are well defined, I'm having difficulty.  One idea I have to 
try and get a better understanding might be to check data before its 
stored.  Again, I still don't know how it would get messed up nor can I 
reproduce the error on my own. 

Do any of you think that would be a good practice for trying to track 
this down? (Check the data after reading it, check the data before 
saving it)



-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


Re: The reliability of python threads

2007-01-25 Thread Paddy


On Jan 25, 9:26 am, [EMAIL PROTECTED] (Nick Maclaren) wrote:
> In article <[EMAIL PROTECTED]>,"Paddy" <[EMAIL PROTECTED]> writes:|>
> |> Three to four months before `strange errors`? I'd spend some time
> |> correlating logs; not just for your program, but for everything running
> |> on the server. Then I'd expect to cut my losses and arrange to safely
> |> re-start the program every TWO months.
> |> (I'd arrange the re-start after collecting logs but before their
> |> analysis. Life is too short).
>
> Forget it.  That strategy is fine in general, but is a waste of time
> where threading issues are involved (or signal handling, or some types
> of communication problem, for that matter).

Nah, Its a great strategy. it keeps you up and running when all you
know for sure is that you will most likely be able to keep things
together for three months normally.
The OP only thinks its a threading problem - it doesn't matter what the
true fix will be, as long as arranging to re-start the server well
before its likely to go down doesn't take too long, compared to your
exploration of the problem, and, of course, you have to be able to
afford the glitch in availability.

> There are three unrelated
> killer facts that interact:
>
> Such failures are usually probabilistic ("Poisson process"), and
> so have no "history".
>
> The expected number is usually proportional to the square of the
> activity, sometimes a higher power.
>
> Virtually nothing involved does any routine logging, or even has
> options to log relevant events.
>
> The first means that the strategy of restarting doesn't help.  All
> three mean that current logs are almost never any use.
> 
> Regards,
> Nick Maclaren.

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


Re: Rendering text question (context is MSWin UI Automation)

2007-01-25 Thread Chris Mellon
On 1/25/07, Boris Borcic <[EMAIL PROTECTED]> wrote:
> Chris Mellon wrote:
> > On 1/25/07, Boris Borcic <[EMAIL PROTECTED]> wrote:
> >> Chris Mellon wrote:
>
> >
> > Some quick & dirty wxPython code
> >
> > def getTextBitmap(text, font, fgcolor, bgcolor):
> > dc = wx.MemoryDC()
> > dc.SetFont(font)
> > width, height= dc.GetTextExtent(text)
> > bmp = wx.EmptyBitmap(width, height)
> > dc.SelectObject(bmp)
> > dc.SetBackground(wx.Brush(bgcolor))
> > dc.Clear()
> > dc.SetTextBackground(bgcolor)
> > dc.SetTextForeground(fgcolor)
> > dc.DrawText(text, 0, 0)
> > dc.SelectObject(wx.NullBitmap)
> > return bmp
> >
> >
> > Raw win32 code will look similar but will be much more verbose.
>  Thx again for this base.
> 
>  Quickly testing this, it appears that the result is rendered half a 
>  pixel off in
>  the x-direction. Does this make sense ? Is it possible to position text 
>  with
>  subpixel accuracy ?
> 
> >> In short, wx._gdi_ fights quite hard to enforce what I am trying to avoid 
> >> :( I
> >> might admire its consistency if it extended to treating both axes 
> >> similarly...
> >>
> >
> > I have not recently had a need to examine drawn text output this
> > closely, but I am familiar with the C++ code that implements the
> > drawing and it's a direct wrapping of win32 GDI calls. If it's not
> > matching your source text, then the source may be drawn using a
> > different method or using one of the alternate engines, like GDI+.
>
> Maybe. In any case, color separation solves my (sub)problem : the blue layer
> from the wx generated model matches the green layer from the app's window, 
> pixel
> for pixel (at least with antialiasing and cleartype on, while writing black on
> white).
>

That's... extremely interesting. If it works for you, go for it! If
you're interested in some other things to try, wx.EmptyBitmap takes a
depth parameter you can use to eliminate color.
-- 
http://mail.python.org/mailman/listinfo/python-list


Module for SVG?

2007-01-25 Thread Sebastian Bassi
Hello,

I found http://www2.sfk.nl/svg as a Python module for writing SVG.
Last update was in 2004 and I am not sure if there is something
better.
Any recommendation for generating SVG graphics?
Best,
SB.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: While loop with "or"? Please help!

2007-01-25 Thread Daniel
2007-01-25 11:26:09
[EMAIL PROTECTED] wrote in message
<[EMAIL PROTECTED]>

> Hmm, my while loop with "or" doesn't seem to work as I want it to...

> How do I tell the while loop to only accept "Y" or "y" or "N" or 
"n"
> input from the str(raw_input)?
> 
> Thank's in advance!
> 
> Snippet of code:
> 
> import os
> 
> def buildfinder():
> os.system("CLS")
> GameRoot = os.getenv("GAME_ROOT") + "\\"
> 
> print "Do you want to use " + GameRoot + " as your source
> directory?"
> usr = str(raw_input('Y/N: '))
> return usr
> 
> #Runs the buildfinder function
> usrinp = buildfinder()
> 
> def buildwhiler():
> 
> while usrinp != "y" or "Y" or "N" or "n": PROBLEM
> print "Enter Y or N!"
> usr = str(raw_input('Y/N: '))
> else:
> code continues

Thanks for the help everyone! :)
This forum rules!
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Overloading assignment operator

2007-01-25 Thread Carroll, Barry
> -Original Message-
> From: Gabriel Genellina [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, January 23, 2007 9:24 PM
> To: python-list@python.org
> Subject: Re: Overloading assignment operator
> 
> "Carroll, Barry" <[EMAIL PROTECTED]> escribió en el mensaje
> news:[EMAIL PROTECTED]
> 
> > * ... the assignment operator is used to assign an
> > * object to a name in the current namespace... IOW, you cannot "overload
> > * the assignment operator."
> > (wesley chun)
> This is the key concept, if you want to be able to "see" assignments, you
> should work with a namespace (a dictionary is enough...)
> 
> > * result = property(get_result, set_ result, doc='result of operations')
> >
> > I have tested this using the admittedly simple-minded code snipped
> > below.
<>
> Notice that you can delete ALL those lines of code, leaving a bare:
> 
> class Aclass: passs
> 
> and you will get EXACTLY the same results. In this case -and this are not
> my
> words- properties are a waste of programmer time, processor time and disk
> space.
> Of course properties are very useful, but when you need to do something
> "more" than just storing and retrieving a single value.
> 
> --
> Gabriel Genellina
Greetings:

Gabriel is right, and my definitions of get_result and set_result were 
deficient.  Something like this would have been better:

* def get_result(self):
*do_stuff_before_returning(self)
*return self.__result
*
* def set_result (self, expression):
*do_stuff_before_storing(self, expression)
*self.__result = expression
*

Achim didn't go into the details of his result class(es), so I don't know what 
the do_stuff_* functions would actually do.  

Sorry for the omission.  

Regards,
 
Barry

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


Re: Rendering text question (context is MSWin UI Automation)

2007-01-25 Thread Boris Borcic
Chris Mellon wrote:
> On 1/25/07, Boris Borcic <[EMAIL PROTECTED]> wrote:
>> Chris Mellon wrote:

>
> Some quick & dirty wxPython code
>
> def getTextBitmap(text, font, fgcolor, bgcolor):
> dc = wx.MemoryDC()
> dc.SetFont(font)
> width, height= dc.GetTextExtent(text)
> bmp = wx.EmptyBitmap(width, height)
> dc.SelectObject(bmp)
> dc.SetBackground(wx.Brush(bgcolor))
> dc.Clear()
> dc.SetTextBackground(bgcolor)
> dc.SetTextForeground(fgcolor)
> dc.DrawText(text, 0, 0)
> dc.SelectObject(wx.NullBitmap)
> return bmp
>
>
> Raw win32 code will look similar but will be much more verbose.
 Thx again for this base.

 Quickly testing this, it appears that the result is rendered half a pixel 
 off in
 the x-direction. Does this make sense ? Is it possible to position text 
 with
 subpixel accuracy ?

>> In short, wx._gdi_ fights quite hard to enforce what I am trying to avoid :( 
>> I
>> might admire its consistency if it extended to treating both axes 
>> similarly...
>>
> 
> I have not recently had a need to examine drawn text output this
> closely, but I am familiar with the C++ code that implements the
> drawing and it's a direct wrapping of win32 GDI calls. If it's not
> matching your source text, then the source may be drawn using a
> different method or using one of the alternate engines, like GDI+.

Maybe. In any case, color separation solves my (sub)problem : the blue layer 
from the wx generated model matches the green layer from the app's window, 
pixel 
for pixel (at least with antialiasing and cleartype on, while writing black on 
white).

Best, Boris Borcic


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


Re: Thoughts on using isinstance

2007-01-25 Thread Matthew Woodcraft
Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
> Matthew Woodcraft a écrit :

>> Adding the validation code can make your code more readable, in that
>> it can be clearer to the readers what kind of values are being
>> handled.

> This is better expressed in the docstring. And if it's in the
> docstring, you can't be blamed for misuse.

I certainly agree that the description of the function's requirements on
its parameters is best placed in the docstring.

This is another place where the "don't validate, just try running the
code anyway" approach can cause problems: what should you put in the
docstring?

I don't think anyone would like to be fully explicit about the
requirements: you'd end up having to write things like "A string, or at
least anything that's iterable and hashable and whose elements are
single character strings, or at least objects which have an upper()
method which ...".

So in practice you end up writing "a string", and leave the rest of the
'contract' implicit. But that can lead to difficulties if people working
on the code have different ideas of what that implicit contract is -- is
it "a string, or anything else which works with the current
implementation", or perhaps "you may pass something other than a string
so long as you take responsibility for making it support all the
necessary operations, even if the implementation changes", or is there
some project-wide convention about how much like a string such things
have to be?

I think this kind of vagueness can work well within a lump of code which
is maintained as a piece, but it's good to divide up programs into
components with more carefully documented interfaces. And it's at that
level that I think doing explicit parameter validation can be helpful.


>> If you validate, you can raise an exception from the start of your
>> function with a fairly explicit message. If you don't validate,
>> you're likely to end up with an exception whose message is something
>> like 'iteration over non-sequence', and it might be raised from some
>> function nested several levels deeper in.

> And what is the stack backtrace for, actually ?

I'm not sure that you intended that as a serious question, but I'll
answer it anyway.

In an ideal world, the stack backtrace is there to help me work with
code that I'm maintaining. It isn't there to help me grub around in the
source of someone else's code which is giving me an unhelpful error
message. Just as, in an ideal world, I should be able to determine how
to correctly use someone else's code by reading its documentation rather
than its source.

I think this is a 'quality of implementation' issue. When you start
using Python you pretty rapidly pick up the idea that a message like
'len() of unsized object' from (say) a standard library function
probably just means that you didn't pass the value you intended to; but
that doesn't mean it's a good error message. These things do add up to
make the daily business of programming less efficient.


>> The latter can be harder for the user of your function to debug (in
>> particular, it may not be easy to see that the problem was an invalid
>> parameter to your function rather than a bug in your function itself,
>> or corrupt data elsewhere in the system).

> docstrings and unit-tests should make it clear.

I don't see that either of those things remove the issues I described.


> Now if one want to have to declare everything three times and write
> layers and layers of adapters and wrappers, well, he knows where to
> find Java !-)

Right. But using Python there is a position between 'writing layers and
layers of adapters and wrappers' and 'never validate anything': put
explicit checks in particular functions where they're likely to do most
good.

For example, it's often helpful to explicitly validate if you're going
to store the parameters away and do the actual work with them later on.
Consider what happens if you pass garbage to urllib2.install_opener():
you'll get an obscure error message later on from a urlopen() call,
which will be rather less convenient to investigate than an error from
install_opener() would have been.


>> This might well lead to your program apparently completing
>> successfully but giving the wrong result (which is usually the kind
>> of error you most want to avoid).

> Compared to what C or C++ can do to your system, this is still a
> pretty minor bug - and probably one of the most likely to be detected
> very early

I disagree. What C or C++ will do, very often, is produce a segmentation
fault. That may well turn out to be hard to debug, but it's considerably
more likely to be detected early than a successful exit status with
incorrect output.

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

Re: ANN: Dejavu 1.5.0RC1

2007-01-25 Thread olive
Looks interesting...

Do you consider a StorageManagers for Oracle ?

Olive.

On Jan 24, 11:57 pm, "Robert Brewer" <[EMAIL PROTECTED]> wrote:
> The Dejavu Object-Relational Mapper (version 1.5.0RC1) is now available
> and in the public domain. Get it athttp://projects.amor.org/dejavu,
> or from PyPI:http://www.python.org/pypi/Dejavu/1.5.0RC1.
>
> Dejavu is an Object-Relational Mapper for Python applications. It is
> designed to provide the "Model" third of an MVC application. Dejavu
> avoids making decisions in the framework which are better left to
> developers, and avoids forcing developers to make decisions which are
> better left to deployers. In particular, deployers are allowed to mix
> and match storage mechanisms, including how and when to cache objects in
> memory, making it easier for deployers to tune applications to their
> particular environment.
>
> Dejavu provides:
>
> Modeling Layer
> 1. A base Unit class for persisting objects to storage.
> 2. A base UnitProperty class for persistent object attributes.
> 3. ID Sequencers.
> 4. Associations between Unit classes.
> 5. Unit Engines, Rules, and Collections.
> 6. Aggregation and analysis tools.
>
> Application Layer
> 1. Expressions: pure Python lambda querying. This is perhaps the most
>appealing feature of Dejavu.
> 2. Sandboxes, which serve as Identity Maps, transaction boundaries,
>and per-connection caches.
> 3. An Arena class for application-level data.
>
> Storage Layer
> 1. A base StorageManager class and specification. Unlike many ORMs,
>Dejavu does not require you to have complete control of the back end.
> 2. Specific StorageManagers for:
>a. Microsoft SQL Server/MSDE
>b. Microsoft Access (Jet)
>c. PostgreSQL
>d. MySQL
>e. SQLite
>f. Shelve
>g. Firebird
>h. RAM
>i. Filesystem
>
> What's New in 1.5:http://projects.amor.org/dejavu/wiki/WhatsNewIn15
>
>  * Native ID sequencing.
>  * Distributed transactions and tested isolation levels.
>  * Complete database introspection and auto discovery.
>
>  * New Firebird support.
>  * New RAM Storage Manager.
>  * New psycopg2 support.
>  * New support for using the sqlite3 module built into Python 2.5.
>  * Support for typed and typeless SQLite.
>  * Support for SQLite :memory: databases.
>
>  * Complete numeric precision and scale support.
>  * Native date function support.
>  * Complete M x N type-adaptation.
>  * Bulletproof encoding support.
>  * New 'range' function which returns the closed interval [min(attr),
> ..., max(attr)].
>  * New 'sum' function which returns the sum of all non-None values for
> the given cls.attr.
>  * Multiple and custom Associations.
>  * Improved performance (especially ADO).
>  * New JSON encoder/decoder.
>  * Short config names for Storage Managers.
>  * ADO: New support for the CURRENCY datatype.
>  * ADO: Improved string comparisons using Convert and StrComp.
>
> Upgrading to 1.5:
> Seehttp://projects.amor.org/dejavu/wiki/UpgradeTo1.5
>
> Documentation for 1.5:http://projects.amor.org/docs/dejavu/1.5.0RC1/
>
> Robert Brewer
> System Architect
> Amor Ministries
> [EMAIL PROTECTED]

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


Re: asyncore.dispatcher.handle_read

2007-01-25 Thread Jordan
That was not entirely helpful, it's way more likely a mistake you made
in subclassing dispatcher than a problem within asycore itself (that
ended up sounding a lot more mean/angry than intended, sorry ¬_¬ ),
you really need to show us what changes you made to asyncore.dispatcher
if you want help.  Good luck.

Cheers,
Jordan

On Jan 25, 12:18 pm, Indy <[EMAIL PROTECTED]> wrote:
> Greetings.
>
> I am writing an asynchronous server, and I use the standard library's
> module asyncore.
> I subclass asyncore.dispatcher. handle_accept works just right, that
> is, when a client socket makes a request to connect to my server
> socket, things that I set in handle_accept definition, happen. So, it
> is OK. But, the problem is that handle_read does not work as expected.
> Things I set in handle_read definition, do not happen when a client
> socket sends me data. Why? Is this a known problem? Please, can you
> help me?
> Thanks a lot, in advance.
>
> Best regards,
> Aristotelis Mikropoulos
>
> --
> Programs must be written for people to read, and only incidentally for
> machines to execute.

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


Re: Email attachments

2007-01-25 Thread Facundo Batista
Steve Holden wrote:

> I'm having some trouble getting attachments right for all recipients, 
> and it seems like Apple's mail.app is the pickiest client at the moment. 
> It doesn't handle attachments that both Thunderbird and Outlook find 
> perfectly acceptable.

The following code works ok with Thunderbird and mail.app (at least with
all the mail I usually sent).

A friend of mine reports that he (with mail.app can see that he has an
attachment, open it, etc.)

---

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders

class MailSender:
'''Envia un mail con archivos attached.'''
def __init__(self, server, remitente, to):
self.server = server
self.remitente = remitente 
self.to = to
assert type(self.to)==list

def envia(self, subject, text, files=[]):
assert type(files)==list

msg = MIMEMultipart()
msg['From'] = self.remitente
msg['To'] = COMMASPACE.join(self.to)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject 

msg.attach( MIMEText(text) )

for file in files:
part = MIMEBase('application', "octet-stream")
part.set_payload( open(file,"rb").read() )
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' 
% os.path.basename(file))
msg.attach(part)

smtp = smtplib.SMTP(self.server)
smtp.sendmail(self.remitente, self.to, msg.as_string())
smtp.close()
return

---

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


Re: running applications in python

2007-01-25 Thread Jordan
os.system, os.spawn, the process module, os.popen[1,2,3,4], this is a
pretty basic thing, not trying to be mean, but you should look in the
python docs, this is definitely in there.  Also, the subprocess module
is meant to replace all of those but i haven't looked too closely at it
yet, so the following might not be perfect.

import subprocess as sp
sp.call(['wmplayer.exe', 'some_args_probably_a_movie_name'])

you'll probably need to use the full path for media player, and the
call() function is a simplified command within the subprocess module,
useful if you don't really need to redirect input/output/errors or
other aspects of the opened application.Also, you'll probably want
something more like:  retcode = sp.call(...), so that you can check the
return code to see if it was successful.  Check out the subprocess
module.

Cheers,
Jordan

On Jan 25, 12:28 pm, "lee" <[EMAIL PROTECTED]> wrote:
> how can i run or open a windows application from the python prompt?for
> e.g.mediaplayer opening,folder acess etc

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


Re: Two dimensional lists

2007-01-25 Thread Travis Oliphant
Laszlo Nagy wrote:
>># shouldn't I be able to fill the lists simply by pointing to a location?
>>
>>matrix[a_idx, p_idx] = 0x219 # and so on?
>>  
> 
> Lists are not matrices. For example:
> 
> L = [  [1,2,3], ['a','b','c'], 10 ]
> print L[1][2] # Prints 'c', you will like this syntax but...
> print L[2][5] # TypeError: 10 is not subscriptable
> 
> You can create a function that creates a "list of lists" filled with 
> zeros, and then use this data structure as a matrix.
> 
> BUT! If you need to use matrices filled with numbers, try numarray:
> 
> http://www.stsci.edu/resources/software_hardware/numarray
> 
> Numarray is much more efficient for this task.

It is also out-dated.  For new code users are strongly encouraged to use 
NumPy.  The numarray people are transitioning their own code to use 
NumPy and numarray will cease being supported at some point.

http://numpy.scipy.org

http://www.numpy.org --- sourceforge site.

-Travis

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


Re: Python does not play well with others

2007-01-25 Thread skip

John> My main concern is with glue code to major packages.  The
John> connections to OpenSSL, MySQL, and Apache (i.e. mod_python) all
John> exist, but have major weaknesses.

I have no SSL experience or direct mod_python experience (I do use Myghty
effectively), but I have used MySQLdb extensively in multi-threaded
environments.  There is a Python database API (PEP 249).  As far as I know,
MySQLdb implements this API well.  I have personally never had problems.
Andy Dustman, the author of the package is quite responsive to requests
raised in the mysql-python forums on SourceForge
(http://sourceforge.net/forum/?group_id=22307).  If you have problems with
MySQLdb, bring them up there.  I'm sure Andy will respond.

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


Re: Python does not play well with others

2007-01-25 Thread Paul Rubin
John Nagle <[EMAIL PROTECTED]> writes:
> My main concern is with glue code to major packages.  The connections
> to OpenSSL, MySQL, and Apache (i.e. mod_python) all exist, but have major
> weaknesses.  If you're doing web applications, those are standard pieces
> which need to work right.  There's a tendency to treat those as abandonware
> and re-implement them as event-driven systems in Twisted.  Yet the
> main packages aren't seriously broken.  It's just that the learning curve
> to make a small fix to any of them is substantial, so nobody new takes
> on the problem.

There is an attitude widespread in the Python community, maybe
inherited from Extreme Programming, that when writing some subsystem
it's enough to implement just enough functionality to satisfy the
application's immediate needs.  Then if the application needs more
functionality from the subsystem later, go back and add it.  That's
fairly reasonable when the application and subsystem are being done by
the same people and there's not such a learning curve.  But it's
unwise for libraries.  For all Java's ugliness, when the Java library
developers want to implement some protocol like SSL, they take the
specification for the protocol and they implement it completely.
Python's library modules are very often missing stuff, as you've
pointed out.

In the specific examples of OpenSSL, MySQL, and Apache, the modules
involved aren't even part of the Python stdlib, the way JSSE and JDBC
are part of the Java stdlib (I guess that doesn't apply to Tomcat
though).
-- 
http://mail.python.org/mailman/listinfo/python-list


running applications in python

2007-01-25 Thread lee
how can i run or open a windows application from the python prompt?for
e.g.mediaplayer opening,folder acess etc

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


Re: assertions to validate function parameters

2007-01-25 Thread George Sakkis
On Jan 25, 11:54 am, Matthew Wilson <[EMAIL PROTECTED]> wrote:

> Lately, I've been writing functions like this:
>
> def f(a, b):
>
> assert a in [1, 2, 3]
> assert b in [4, 5, 6]
>
> The point is that I'm checking the type and the values of the
> parameters.
>
> I'm curious how this does or doesn't fit into python's duck-typing
> philosophy.
>
> I find that when I detect invalid parameters overtly, I spend less time
> debugging.
>
> Are other people doing things like this?  Any related commentary is
> welcome.
>
> Matt

Well, duck (or even static for that matter) typing can't help you if
you're checking for specific *values*, not types. The real question is
rather, is f() intended to be used in the "outside world" (whatever
this might be; another program, library, web service, etc.) or is it to
be called only by you in a very controlled fashion ?

In the first case, passing an invalid input is a *user error*, not a
*programming error*. Assertions should be used for programming errors
only to assert invariants, statements which should be correct no matter
what; their violations mean that the code is buggy and should be fixed
asap.

User errors OTOH should be handled by explicit checking and raising
appropriate exceptions, e.g. ValueError or a subclass of it. There are
several reasons for this but a very practical one is that a user can
turn off the assertions by running python with '-O' or '-OO'.
Optimization flags should never change the behavior of a program, so
using assertions for what's part of the normal program behavior
(validating user-provided input) is wrong.

George

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


Re: Two dimensional lists

2007-01-25 Thread Peter Otten
gonzlobo wrote:

> I might get an answer since I didn't call them arrays. :^)
> 
> Ok, I have 2 lists that I need to process individually, then merge
> them into a 2x list and fill with data.
> 
> arinc429 = ['ab', '2b', '0b', '21', 'c1', '61', '11', 'db', '9b', '5b',
> 'eb',
>  '6b', '1b', '6e', '3e']
> iPIDs = [300, 301, 320, 321]
> 
> merged[arinc429, iPIDs]
> 
> # PID & a429 are defined elsewhere
> 
> a_idx = iPIDs.index[PID]
> p_idx = [arinc429.index[a429]
> 
> # shouldn't I be able to fill the lists simply by pointing to a location?
> 
> matrix[a_idx, p_idx] = 0x219 # and so on?

The simplest approach is to go with a dictionary:

>>> matrix = {}
>>> arinc = ['ab', '2b', '0b']
>>> pids = [300, 321]
>>> for x in arinc:
... for y in pids:
... matrix[x, y] = y + int(x, 16) # replace with your actual data 
...
>>> matrix
{('ab', 300): 471, ('2b', 300): 343, ('ab', 321): 492, ('0b', 321): 332,
('2b', 321): 364, ('0b', 300): 311}

Get one entry:

>>> matrix["2b", 321]
364

Get all items along an axis:

>>> [matrix[x, 300] for x in arinc]
[471, 343, 311]

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


Re: Python does not play well with others

2007-01-25 Thread John Nagle
Paul Boddie wrote:
> On 25 Jan, 12:01, "Ben Sizer" <[EMAIL PROTECTED]> wrote:
> 
>> I think that is why many of the SIGs are stagnant, why the standard library
>> has so much fluff yet still lacks in key areas such as multimedia and web
>> development, etc.
> ... I think this is also a good insight into why things are as they are 
> within the core development section of the community, although one can wonder
> what some people actively developing the language are actually doing with it
> if they are satisfied with the state of some of the standard library
> solutions. However, there are lots of factors which motivate people and the
> proliferation (or otherwise) of solutions to common problems: whether one
> develops one's own solutions as separate projects and/or tries to push for a
> consensus, whether one cares about other people using such solutions, whether
> one aspires to contributing to the standard library.
> 
> Over the years, people have tended towards building their own communities
> around their projects rather than attempting to engage the wider Python
> community, and I think a motivation behind that has been the intractability
> of improving parts of the standard library.

Yes.  Working on "frameworks" is perceived as cooler than working
on libraries.  Things like Ruby on Rails, Struts, Zope, and Twisted
get attention.  There are papers and conferences on these things.
It's hard to get people excited about overhauling
the CGI library, or making mod_python work securely in shared-hosting
environments.

The key distinction between a framework and a library is that users
are expected to make their code fit the framework.  In particular,
frameworks aren't expected to play well with each other.  If you need
something from Zope and something from Twisted, you're probably not
going to be able to make it work.  Libraries, on the other hand,
are expected to play well together.  Which means that they have to
handle the hard cases correctly, not just the easy ones.

> True. It also doesn't address the issue of development priorities and their
> role in defining the platform's own standards
...
> I do wonder whether the interests of language/runtime project developers
> eventually become completely aligned with the needs of such projects, making
> things like "multimedia and web development" seem irrelevant, uninteresting
> or tangential. This has worrying implications for the perceived relevance of
> Python with regard to certain kinds of solutions, despite the wealth of
> independently produced libraries available for the language.

Something like that happened to the C++ standards committee.
The committee was captured by the template fanatics, and most new
standards work involves doing computation at compile time via template
expansion.   That's seldom done in production code, yet most of the
standards effort is devoted to making cool template hacks work better.
Meanwhile, real problems, like doing something about memory leaks and buffer
overflows, are ignored by the C++ committee.  As a result, C++ is
being displaced by Java and C#, which don't have elaborate templates but do have
memory safety.

I'm not sure how the Python development community will deal with this
problem.  But what's happened in the C++ standards world has clearly
been very bad for users of the language.  Learn from the mistakes there.

My main concern is with glue code to major packages.  The connections
to OpenSSL, MySQL, and Apache (i.e. mod_python) all exist, but have major
weaknesses.  If you're doing web applications, those are standard pieces
which need to work right.  There's a tendency to treat those as abandonware
and re-implement them as event-driven systems in Twisted.  Yet the
main packages aren't seriously broken.  It's just that the learning curve
to make a small fix to any of them is substantial, so nobody new takes
on the problem.

John Nagle
Animats
-- 
http://mail.python.org/mailman/listinfo/python-list


asyncore.dispatcher.handle_read

2007-01-25 Thread Indy
Greetings.

I am writing an asynchronous server, and I use the standard library's
module asyncore.
I subclass asyncore.dispatcher. handle_accept works just right, that
is, when a client socket makes a request to connect to my server
socket, things that I set in handle_accept definition, happen. So, it
is OK. But, the problem is that handle_read does not work as expected.
Things I set in handle_read definition, do not happen when a client
socket sends me data. Why? Is this a known problem? Please, can you
help me?
Thanks a lot, in advance.

Best regards,
Aristotelis Mikropoulos

-- 
Programs must be written for people to read, and only incidentally for
machines to execute.
-- 
http://mail.python.org/mailman/listinfo/python-list


assertions to validate function parameters

2007-01-25 Thread Matthew Wilson
Lately, I've been writing functions like this:

def f(a, b):

assert a in [1, 2, 3]
assert b in [4, 5, 6]

The point is that I'm checking the type and the values of the
parameters.

I'm curious how this does or doesn't fit into python's duck-typing
philosophy.

I find that when I detect invalid parameters overtly, I spend less time
debugging.

Are other people doing things like this?  Any related commentary is
welcome.

Matt

-- 
A better way of running series of SAS programs:
http://overlook.homelinux.net/wilsonwiki/SasAndMakefiles
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: free variables /cell objects question

2007-01-25 Thread gangesmaster
[Steven]
> My solution is, don't try to have one function do too much. Making a list
> of foos should be a separate operation from making a single foo:

that's exactly what my second example does (as well as my production
code)

[Paul]
> But it does work as expected, if your expectations are based on what
> closures actually do.

yet, i find what closures actually do, to be logically wrong.
moreover, it means the frame object must be kept alive for no reason...
or in my case, two frame objects per foo-function.

> The Python idiom is:
...
> def foo(n=n):

besides of being ugly, the def f(n=n) idiom is very bad,
programatically speaking. what if the user chooses to be a smartass
and call with n = 7? or what if the function's signature is
meaningful? (as it is in my case)

anyway, this talk is not going anywhere.
thanks for the info, and i'll see how i manage to optimize my code
from here.

-tomer

On Jan 25, 4:51 pm, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Thu, 25 Jan 2007 04:29:35 -0800, Paul Rubin wrote:
> > "gangesmaster" <[EMAIL PROTECTED]> writes:
> >> what i see as a bug is this code not working as expected:
>
> >> >>> def make_foos(names):
> >> ... funcs = []
> >> ... for n in names:
> >> ... def foo():
> >> ... print "my name is", n
> >> ... funcs.append(foo)
> >> ... return funcs
>
> > But it does work as expected, if your expectations are based on what
> > closures actually do.
>
> >> i have to create yet another closure, make_foo, so that the name
> >> is correctly bound to the object, rather than the frame's slot:
>
> > The Python idiom is:
>
> >def make_foos(names):
> >funcs = []
> >for n in names:
> >def foo(n=n):
> >print "my name is", n
> >funcs.append(foo)
> >return funcs
>
> > The n=n in the "def foo" creates the internal binding that you need.Hmmm... 
> > I thought that the introduction of nested scopes removed the need
> for that idiom. Its an ugly idiom, the less I see it the happier I am.
>
> And I worry that it will bite you on the backside if your "n=n" is a
> mutable value.
>
> My solution is, don't try to have one function do too much. Making a list
> of foos should be a separate operation from making a single foo:
>
> >>> def makefoo(name):... def foo():
> ... return "my name is " + name
> ... return foo
> ...>>> makefoo("fred")()
> 'my name is fred'
> >>> def makefoos(names):... foos = []
> ... for name in names:
> ... foos.append(makefoo(name))
> ... return foos
> ...>>> L = makefoos(["fred", "wilma"])
> >>> L[0]()
> 'my name is fred'
> >>> L[1]()'my name is wilma'
>
> That makes it easier to do unit testing too: you can test your makefoo
> function independently of your makefoos function, if that's important.
>
> If you absolutely have to have everything in one function:
>
> >>> def makefoos(names):... def makefoo(name):
> ... def foo():
> ... return "my name is " + name
> ... return foo
> ... L = []
> ... for name in names:
> ... L.append(makefoo(name))
> ... return L
> ...>>> L = makefoos(["betty", "barney"])
> >>> L[0]()
> 'my name is betty'
> >>> L[1]()'my name is barney'
>
> Best of all, now I don't have to argue as to which binding behaviour is
> more correct for closures!!! *wink*
> 
> --
> Steven.

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


Re: Using Timing function problem.....

2007-01-25 Thread Jona
Thanks so much! that did it!
you can tell I'm new with python.. lol...
thanks again..
Jonathan

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


Re: Two dimensional lists

2007-01-25 Thread Laszlo Nagy

> # shouldn't I be able to fill the lists simply by pointing to a location?
>
> matrix[a_idx, p_idx] = 0x219 # and so on?
>   
Lists are not matrices. For example:

L = [  [1,2,3], ['a','b','c'], 10 ]
print L[1][2] # Prints 'c', you will like this syntax but...
print L[2][5] # TypeError: 10 is not subscriptable

You can create a function that creates a "list of lists" filled with 
zeros, and then use this data structure as a matrix.

BUT! If you need to use matrices filled with numbers, try numarray:

http://www.stsci.edu/resources/software_hardware/numarray

Numarray is much more efficient for this task.

Best,

   Laszlo

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


Re: Do I need Python to run Blender correctly?

2007-01-25 Thread John Nagle
AKA gray asphalt wrote:
> I downloaded Blender but there was no link for python. Am I on the right 
> track?

Blender doesn't require Python, but if you have Python, you can
write plug-ins for Blender.   Get "The Blender Book"; otherwise
you'll never figure Blender out.

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


Re: ANN: Dejavu 1.5.0RC1

2007-01-25 Thread Michele Cella
On 25 Gen, 09:02, "fumanchu" <[EMAIL PROTECTED]> wrote:
>
> > I am curious ... how this compare to SQLAlchemy?The comparisons could be 
> > endless ;) but here are some of the larger
> differences:
>
>  1. Dejavu uses generic "storage" concepts and syntax, while SQLAlchemy
> prefers database concepts and syntax.
>  2. Dejavu uses Python expressions (lambdas) to query storage, whereas
> SQLAlchemy uses functions and magic attributes:
> * SQLAlchemy: users.select(and_(users.c.age < 40, users.c.name !=
> 'Mary'))
> * Dejavu: recall(users, lambda u: u.age < 40 and u.name != 'Mary')
>  3. SQLAlchemy prefers that you write data classes, table classes and
> the mappers between them. Dejavu only expects you to write a data
> class. New in 1.5: you can auto-generate even the data classes if you
> already have a populated database.
>  4. SQLAlchemy allows you to write more complicated queries (like
> subqueries and aggregate columns). Dejavu doesn't provide those yet
> (slated for 1.6).
>

5. Dejavu supports model evolution (very much like rails's ActiveRecord
migrations)

I will add that I've never been able to (easily) wrap my head around
ORMs like SQLObject and SQLAlchemy, while they are both great pieces of
software and SQLAlchemy is impressively well documented (like every
other things powered by Michael Bayer) they are trying to reinvent an
ad-hoc query language on top of SQL using python that you need to
learn, that's why my favorite Dejavu feature it's the way you build
queries (using common python constructs like lambda) and define models
(using python types like str, unicode... or your own).

I really encourage anyone to check it out, it's not getting the
publicity it deserves but this doesn't mean it's not good at what it
does, and Robert is like a quality assurance. ;-)

Ciao
Michele

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


Re: sqlite user-defined functions & unicode issue

2007-01-25 Thread Gerhard Häring

Ben Wolfson wrote:

I've got a db some of whose elements have been created automatically
from filesystem data (whose encoding is iso-8859-1).  If I try to
select one of those elements using a standard SQL construct, things
work fine:
[...]

How can I get around this?  I really want to be able to search by
regexp, and not just the standard SQL %-pattern.


Looks like SQLite does not want to pass non-UTF8 strings to functions. 
The attached script shows that it does work with unicode and buffer 
(BLOB) parameters, but not with non-UTF8 strings.


Text has to be encoded in UTF-8 in SQLite, it's just not enforced 
usually. Looks like SQLite enforces it here, though. Kind of ...


-- Gerhard
import sqlite3 as sqlite
import re

def func(x):
if x is not None:
return "ok"
else:
return "input data did not arrive"

con = sqlite.connect(":memory:")
con.create_function("func", 1, func)
raw_latin1 = unicode("\x86", "latin1").encode("utf-8")
print raw_latin1
unicode_str = unicode(raw_latin1, "latin1")
as_buffer = buffer(raw_latin1)

def test(input_data):
try:
print "-" * 50
print type(input_data)
print con.execute("select func(?)", (input_data,)).fetchone()[0]
except Exception, e:
print "ERROR", e

test(raw_latin1)
test(unicode_str)
test(as_buffer)
-- 
http://mail.python.org/mailman/listinfo/python-list

  1   2   >