Re: why is bytearray treated so inefficiently by pickle?

2011-12-07 Thread Irmen de Jong
On 6-12-2011 23:24, Terry Reedy wrote:
> On Nov 30, Irmen de Jong opened a tracker issue with a patch improve 
> bytearray pickling.
> http://bugs.python.org/issue13503
> 
> Yesterday, Dec 5, Antoine Pitrou applied a revised fix.
> http://hg.python.org/cpython/rev/e2959a6a1440/
> The commit message:
> "Issue #13503: Use a more efficient reduction format for bytearrays with 
> pickle protocol
>>= 3. The old reduction format is kept with older protocols in order to allow 
>>unpickling
> under Python 2."
> 

Sure, but this patch only improved the pickle behavior of the bytearray type for
protocol level 3. It didn't touch Python 2.x, nor the pickling of arrays 
(array.array),
let alone numpy arrays.

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


Re: Hints for writing bit-twiddling code in Python

2011-12-07 Thread Peter Otten
Steven D'Aprano wrote:

> I have some bit-twiddling code written in Java which I am trying to port
> to Python. I'm not getting the same results though, and I think the
> problem is due to differences between Java's signed byte/int/long types,
> and Python's unified long integer type. E.g. Java's >>> is not exactly
> the same as Python's >> operator, and a character coerced to a byte in
> Java is not the same as ord(char) in Python. (The Java byte is in the
> range -128...127, I think, while the ord in Python is in 0...255.)
> 
> Can anyone point me to some good resources to help me port the Java code
> to Python?
> 
> If it helps, the Java code includes bits like this:
> 
> long newSeed = (seed & 0xL) * 0x41A7L;
> while (newSeed >= 0x8000L) {
> newSeed = (newSeed & 0x7FFFL) + (newSeed >>> 31L);
> }
> seed = (newSeed == 0x7FFFL) ? 0 : (int)newSeed;
> 
> 
> which I've translated into:
> 
> newseed = (seed & 0x)*0x41A7
> while (newseed >= 0x8000):
> newseed = (newseed & 0x7FFF) + (newseed >> 31)
> seed = 0 if newseed == 0x7FFF else newseed & 0x

I think you need to take negative ints into account. Try adding

if seed & 0x8000: # 2**31
seed -= 0x1 # 2**32, two's complement

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


Losing com pointer

2011-12-07 Thread Matteo Boscolo

Hi all,
I need some help to a com problem..

I got this class:

class foo(object):
def setComObject(comObject):
self.comO=comObject #This is a com object from a cad application

def showForm(self)
# use the self.comO to read some information from the cad 
application

# Show the pyqt form as child of cad application
# do somthing with the form
# do somthing with the self.comO <- Here if pass some time 
I'm not able to call any method to the com object


a=foo()
o="get istance of a cad application via com"
a.setComObject(o)
a.showForm() #< here if pass some time I'm not able to call any 
method to the com object


but I I' re call the
a.setComObject(o)  #Faster and I take less the 30 seconds on the form 
object it works well


It seems a problem of the garbage collector .. but I'm not sure how to 
debug it ..


any help is really appreciated.. it's the last dangerous bug in our 
application ...


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


Re: Hints for writing bit-twiddling code in Python

2011-12-07 Thread Serhiy Storchaka

07.12.11 06:03, Steven D'Aprano написав(ла):

long newSeed = (seed&  0xL) * 0x41A7L;
while (newSeed>= 0x8000L) {
 newSeed = (newSeed&  0x7FFFL) + (newSeed>>>  31L);
 }
seed = (newSeed == 0x7FFFL) ? 0 : (int)newSeed;


seed = (seed & 0x) * 0x41A7 % 0x7FFF

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


Re: Questions about LISP and Python.

2011-12-07 Thread Andrea Crotti

On 12/06/2011 04:36 AM, Xah Lee wrote:

i don't like python, and i prefer emacs lisp. The primary reason is
that python is not functional, especially with python 3. The python
community is full of fanatics with their drivels. In that respect,
it's not unlike Common Lisp community and Scheme lisp community.



I love emacs and I love python, but saying that elisp is a better language
than python and more functional is plain ridiculous.
Elisp is great to extend Emacs, but with dynamic scoping and side effects
used everywhere should not even be considered between the functional
languages, at least for how it's mainly used.

This is a typical usage taken from simple.el
(defun pop-global-mark ()
  "Pop off global mark ring and jump to the top location."
  (interactive)
  ;; Pop entries which refer to non-existent buffers.
  (while (and global-mark-ring (not (marker-buffer (car 
global-mark-ring

(setq global-mark-ring (cdr global-mark-ring)))
  (or global-mark-ring
  (error "No global mark set"))
  (let* ((marker (car global-mark-ring))
 (buffer (marker-buffer marker))
 (position (marker-position marker)))
(setq global-mark-ring (nconc (cdr global-mark-ring)
  (list (car global-mark-ring
(set-buffer buffer)
(or (and (>= position (point-min))
 (<= position (point-max)))
(if widen-automatically
(widen)
  (error "Global mark position is outside accessible part of buffer")))
(goto-char position)
(switch-to-buffer buffer)))

Which means more or elss pop a mark from the mark ring, get the current 
buffer/position,
then set the buffer, widen if necessary, go to some position and switch 
to that buffer.


Nothing wrong with it, but basically it messes around with global state, 
as most elisp functions

do.

And how python 3 would be less functional?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Questions about LISP and Python.

2011-12-07 Thread Terry Reedy

On 12/7/2011 5:14 AM, Andrea Crotti wrote:

On 12/06/2011 04:36 AM, Xah Lee wrote:

i don't like python, and i prefer emacs lisp. The primary reason is
that python is not functional, especially with python 3. The python
community is full of fanatics with their drivels. In that respect,
it's not unlike Common Lisp community and Scheme lisp community.



I love emacs and I love python, but saying that elisp is a better language
than python and more functional is plain ridiculous.
Elisp is great to extend Emacs, but with dynamic scoping and side effects
used everywhere should not even be considered between the functional
languages, at least for how it's mainly used.

This is a typical usage taken from simple.el
(defun pop-global-mark ()
"Pop off global mark ring and jump to the top location."
(interactive)
;; Pop entries which refer to non-existent buffers.
(while (and global-mark-ring (not (marker-buffer (car global-mark-ring
(setq global-mark-ring (cdr global-mark-ring)))
(or global-mark-ring
(error "No global mark set"))
(let* ((marker (car global-mark-ring))
(buffer (marker-buffer marker))
(position (marker-position marker)))
(setq global-mark-ring (nconc (cdr global-mark-ring)
(list (car global-mark-ring
(set-buffer buffer)
(or (and (>= position (point-min))
(<= position (point-max)))
(if widen-automatically
(widen)
(error "Global mark position is outside accessible part of buffer")))
(goto-char position)
(switch-to-buffer buffer)))

Which means more or elss pop a mark from the mark ring, get the current
buffer/position,
then set the buffer, widen if necessary, go to some position and switch
to that buffer.

Nothing wrong with it, but basically it messes around with global state,
as most elisp functions
do.

And how python 3 would be less functional?


It does not pretend that surrounding statements with parentheses turns 
them into expressions.

;-)

--
Terry Jan Reedy

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


Re: How to build 64-bit Python on Solaris with GCC?

2011-12-07 Thread Skip Montanaro
> Does anyone have a recipe for the subject build?

I know Solaris is a minority platform these days, but surely someone has 
tackled 
this problem, haven't they?

Thx,

Skip




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


Re: How to build 64-bit Python on Solaris with GCC?

2011-12-07 Thread Karim

Le 07/12/2011 12:30, Skip Montanaro a écrit :

Does anyone have a recipe for the subject build?

I know Solaris is a minority platform these days, but surely someone has tackled
this problem, haven't they?

Thx,

Skip





./configure
make
make install

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


Re: Questions about LISP and Python.

2011-12-07 Thread Neil Cerutti
On 2011-12-07, Terry Reedy  wrote:
> It does not pretend that surrounding statements with
> parentheses turns them into expressions.
> ;-)

I like being in a sexpression. Aww YEH!

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


Re: order independent hash?

2011-12-07 Thread Hrvoje Niksic
Chris Angelico  writes:

> 2011/12/5 Hrvoje Niksic :
>> If a Python implementation tried to implement dict as a tree,
>> instances of classes that define only __eq__ and __hash__ would not
>> be correctly inserted in such a dict.
>
> Couldn't you just make a tree of hash values? Okay, that's probably
> not the most useful way to do things, but technically it'd comply with
> the spec.

That's a neat idea.  The leaves of the tree would contain a list of
items with the same hash, but that's what you effectively get with a
linear-probe hash table anyway.

As you said, not immediately useful, but one could imagine the technique
being of practical use when implementing Python or a Python-compatible
language in a foreign environment that supports only tree-based
collections.
-- 
http://mail.python.org/mailman/listinfo/python-list


Dynamic variable creation from string

2011-12-07 Thread Massi
Hi everyone,

in my script I have a dictionary whose items are couples in the form
(string, integer values), say

D = {'a':1, 'b':2, 'c':3}

This dictionary is passed to a function as a parameter, e.g. :

def Sum(D) :
return D['a']+D['b']+D['c']

Is there a way to create three variables dynamically inside Sum in
order to re write the function like this?

def Sum(D) :
# Here some magic to create a,b,c from D
return a+b+c

It is really important that the scope of a,b,c is limited to the Sum
function, they must not exisit outside it or inside any other nested
functions.
Thanks in advance for your help!

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


Re: Dynamic variable creation from string

2011-12-07 Thread Waldek M.
On Wed, 7 Dec 2011 09:09:16 -0800 (PST), Massi wrote:
> def Sum(D) :
> return D['a']+D['b']+D['c']
> 
> Is there a way to create three variables dynamically inside Sum in
> order to re write the function like this?
> 
> def Sum(D) :
> # Here some magic to create a,b,c from D
> return a+b+c

Hello,

> It is really important that the scope of a,b,c is limited to the Sum
> function, they must not exisit outside it or inside any other nested
> functions.
> Thanks in advance for your help!

Can you clarify a bit? I'm not sure why do you need to define any
additional variables at all. You do not return variables
from a function - you can return *a value* which may be
a simple type or complex type.

Or maybe you mean something like creating a global name
from inside of a function? Well, that doesn't sound like a good idea,
though...

>>> def foo():
global a
a = 5

>>> foo()
>>> print("The variable is: ", a)
The variable is:  5
>>> 



Best regards,
Waldek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic variable creation from string

2011-12-07 Thread John Gordon
In  Massi 
 writes:

> in my script I have a dictionary whose items are couples in the form
> (string, integer values), say

> D = {'a':1, 'b':2, 'c':3}

> This dictionary is passed to a function as a parameter, e.g. :

> def Sum(D) :
> return D['a']+D['b']+D['c']

> Is there a way to create three variables dynamically inside Sum in
> order to re write the function like this?

Do you want to sum all the values in D?  If so, that's easy:

  def Sum(D):
  my_sum = 0
  for item in D:
  my_sum += D[item]
  return my_sum

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: order independent hash?

2011-12-07 Thread 88888 Dihedral
On Wednesday, December 7, 2011 9:28:40 PM UTC+8, Hrvoje Niksic wrote:
> Chris Angelico  writes:
> 
> > 2011/12/5 Hrvoje Niksic :
> >> If a Python implementation tried to implement dict as a tree,
> >> instances of classes that define only __eq__ and __hash__ would not
> >> be correctly inserted in such a dict.
> >
> > Couldn't you just make a tree of hash values? Okay, that's probably
> > not the most useful way to do things, but technically it'd comply with
> > the spec.
> 
> That's a neat idea.  The leaves of the tree would contain a list of
> items with the same hash, but that's what you effectively get with a
> linear-probe hash table anyway.
> 
> As you said, not immediately useful, but one could imagine the technique
> being of practical use when implementing Python or a Python-compatible
> language in a foreign environment that supports only tree-based
> collections.

The heap as the root that could be divided like a tree of nodes to be used
is funny. There are many ways to implement the heap manager in SW. 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic variable creation from string

2011-12-07 Thread Chris Angelico
On Thu, Dec 8, 2011 at 4:09 AM, Massi  wrote:
> def Sum(D) :
># Here some magic to create a,b,c from D
>return a+b+c

Welcome to TMTOWTDI land! We do magic here... several different ways.

You _may_ be able to do this, which is roughly equivalent to the
extract() function in PHP:

locals().update(D)

However, this is NOT guaranteed to work. It's more likely to work with
globals(), but that wouldn't restrict the scope the way you asked.

One handy trick that I found on the internet while researching this:
Use (or abuse!) function keyword parameters to do the dictionary
extraction. You have to explicitly name your desired keys this way,
but it may be suitable. (The function doesn't have to be defined
inside the other, incidentally.)

>>> def Sum(D):
   def inner_sum(a,b,c,**kwargs):
   # Real logic goes here.
   return a+b+c
   return inner_sum(**D)

>>> a={"a":5,"b":10,"c":20}
>>> Sum(a)
35

Alternatively, the exec() and eval() functions can be given
dictionaries which will serve as their variable scopes, so you could
possibly use that. Definitely looking like ugly code though.

For something as trivial as Sum(), you'd do best to simply type
D['a']+D['b']+D['c'] and be done with it. For something where you're
going to use them a lot, probably easiest to be explicit:

a,b,c = D['a'],D['b'],D['c']

However, this violates DRY principle, and risks hard-to-trace mismatch
bugs. I'd be inclined to simply be explicit all the time.

Depending on what D is, you may actually want to consider rewriting
this as a class with a member function.

class whatever:
 def Sum(self):
   return self.a+self.b+self.c

There should be one obvious way to do it, says the zen of Python.
Frankly, I'm not sure what that one obvious way is, here, although I'm
pretty certain that several of the options posited would be very bad
for your code!

Still, down's very nice... They ARE alternative possibilities.

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


Re: Dynamic variable creation from string

2011-12-07 Thread MRAB

On 07/12/2011 17:45, John Gordon wrote:

In  
Massi  writes:


in my script I have a dictionary whose items are couples in the form
(string, integer values), say



D = {'a':1, 'b':2, 'c':3}



This dictionary is passed to a function as a parameter, e.g. :



def Sum(D) :
 return D['a']+D['b']+D['c']



Is there a way to create three variables dynamically inside Sum in
order to re write the function like this?


Do you want to sum all the values in D?  If so, that's easy:

   def Sum(D):
   my_sum = 0
   for item in D:
   my_sum += D[item]
   return my_sum


Or even:

def Sum(D):
return sum(D.values())
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing: killing children when parent dies

2011-12-07 Thread Mihai Badoiu
ok, so the code is something like
#process A
  p = Process(...)
  p.daemon = 1
  p.start()   # starts process B
...

If process A dies (say error, or ctrl-c), or finishes, then process B also
dies.  But if process A is killed with the "kill" command, then process B
soldiers on...

Any idea on how to make process B die when process A gets killed by the
"kill" command?

thanks,

--mihai

On Sat, Dec 3, 2011 at 4:01 AM, Jack Keegan wrote:

> I think the OP meant when the parent gets killed (by ctrl+c or similar),
> not deleted. At least that's what I think when I think of a program being
> killed. Is it even possible to send a signal in such a case?
>
> Cheers,
>
> Jack
>
> On Fri, Dec 2, 2011 at 4:27 PM, 8 Dihedral <
> [email protected]> wrote:
>
>> Please check Erlang that spawn so easily. And there are Python packages
>> can do the same task.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
>
> --
> The earth is a very small stage in a vast cosmic arena. Think of the
> rivers of blood spilled by all those generals and emperors so that in glory
> and in triumph they could become the momentary masters of a fraction of a
> dot.
> - Carl Sagan [Pale Blue Dot]
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Insert trusted timestamp to PDF

2011-12-07 Thread Hegedüs , Ervin
Hello Everyone,

I'm looking for a tool, which can add a trusted timestamp to an
existing PDF file (and can sign - but currently only have to add
TS).

Could anybody help?


Thanks:


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


Re: Multiprocessing: killing children when parent dies

2011-12-07 Thread Dan Stromberg
On 12/7/11, Mihai Badoiu  wrote:
> ok, so the code is something like
> #process A
>   p = Process(...)
>   p.daemon = 1
>   p.start()   # starts process B
> ...
>
> If process A dies (say error, or ctrl-c), or finishes, then process B also
> dies.  But if process A is killed with the "kill" command, then process B
> soldiers on...
>
> Any idea on how to make process B die when process A gets killed by the
> "kill" command?

1) If all you care about is SIGTERM, SIGHUP and the like (and
specifically NOT SIGKILL), you could just install a signal handler
that catches any catchable signals you're interested in.  Then the
signal either kills the children directly, or sets a flag that tells
the main process to do some killing shortly.  Note that threads and
signal handlers don't mix very well - the combination tends to make
the main thread immune to control-C, whether you want it to be or not.
 Also, signal handlers tend to complicate performing I/O, as you're
more likely to read short blocks.

2) If you need to handle SIGKILL gracefully, and you have access to
the code of the child process, you could make sure that the child
isn't setting a SID (?).  ssh, I believe, likes to start a new SID,
making it immune to signals to the parent.  Alternatively, you could
add something to the child process' main loop that polls the parent,
exiting if the parent no longer exists.

3) If you need to handle SIGKILL gracefully, and you don't have access
to the code of the child process, you could use a single extra process
that checks for the presense of the parent, and if it doesn't exist
any more, then kill the children before exiting itself.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing: killing children when parent dies

2011-12-07 Thread Mihai Badoiu
I like 2) the most.  I do have access to the child.  The child is a process
started with multiprocessing.Process(function).  How do I _not_ set an SID?

thanks,

--mihai

On Wed, Dec 7, 2011 at 2:50 PM, Dan Stromberg  wrote:

> On 12/7/11, Mihai Badoiu  wrote:
> > ok, so the code is something like
> > #process A
> >   p = Process(...)
> >   p.daemon = 1
> >   p.start()   # starts process B
> > ...
> >
> > If process A dies (say error, or ctrl-c), or finishes, then process B
> also
> > dies.  But if process A is killed with the "kill" command, then process B
> > soldiers on...
> >
> > Any idea on how to make process B die when process A gets killed by the
> > "kill" command?
>
> 1) If all you care about is SIGTERM, SIGHUP and the like (and
> specifically NOT SIGKILL), you could just install a signal handler
> that catches any catchable signals you're interested in.  Then the
> signal either kills the children directly, or sets a flag that tells
> the main process to do some killing shortly.  Note that threads and
> signal handlers don't mix very well - the combination tends to make
> the main thread immune to control-C, whether you want it to be or not.
>  Also, signal handlers tend to complicate performing I/O, as you're
> more likely to read short blocks.
>
> 2) If you need to handle SIGKILL gracefully, and you have access to
> the code of the child process, you could make sure that the child
> isn't setting a SID (?).  ssh, I believe, likes to start a new SID,
> making it immune to signals to the parent.  Alternatively, you could
> add something to the child process' main loop that polls the parent,
> exiting if the parent no longer exists.
>
> 3) If you need to handle SIGKILL gracefully, and you don't have access
> to the code of the child process, you could use a single extra process
> that checks for the presense of the parent, and if it doesn't exist
> any more, then kill the children before exiting itself.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insert trusted timestamp to PDF

2011-12-07 Thread Irmen de Jong

On 07-12-11 20:41, Hegedüs, Ervin wrote:

Hello Everyone,

I'm looking for a tool, which can add a trusted timestamp to an
existing PDF file (and can sign - but currently only have to add
TS).


Note sure what a 'trusted timestamp' is, but pdftk can manipulate pdf 
files. See http://www.pdflabs.com/docs/pdftk-man-page/

(nothing to do with Python btw!)

Irmen

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


A HOME OF TOLERANCE !!!!!!!!!!!!!

2011-12-07 Thread bv
A HOME OF TOLERANCE


A Home Of Tolerance Media speculation since the horrific terrorist
attacks on America has pointed the finger at Muslims and the Arab
world, and that has meant ordinary citizens of the US and other
Western countries becoming easy prey for anti-faith hooligans. Shame.
Sadly, the latest horror to hit the US looks to have been caused by
people of Middle Eastern origin, bearing Muslim names. Again, shame.
This fuels more hatred for a religion and a people who have nothing to
do with these events. This is why I want to explain some basic facts
about this noble way we call Islam, before, God forbid, another
disaster occurs - next time probably aimed at Muslims. I came to Islam
in my late 20s, during my searching period as a wandering pop star. I
found a religion that blended scientific reason with spiritual reality
in a unifying faith far removed from the headlines of violence,
destruction and terrorism. One of the first interesting things I
learned in the Koran was that the name of the faith comes from the
word salam - peace. Far from the kind of Turko-Arab-centric message I
expected, the Koran presented a belief in the universal existence of
God, one God for all. It does not discriminate against peoples; it
says we may be different colors and from different tribes, but we are
all human and "the best of people are the most God- conscious". Today,
as a Muslim, I have been shattered by the horror of recent events; the
display of death and indiscriminate killing we've all witnessed has
dented humanity's confidence in itself. Terror on this scale affects
everybody on this small planet, and no one is free from the fallout.
Yet we should remember that such violence is almost an everyday
occurrence in some Muslim lands: it should not be exacerbated by
revenge attacks on more innocent families and communities. Along with
most Muslims, I feel it a duty to make clear that such orchestrated
acts of incomprehensible carnage have nothing to do with the beliefs
of most Muslims. The Koran specifically declares: "If anyone murders
an (innocent) person, it will be as if he has murdered the whole of
humanity. And if anyone saves a person it will be as if he has saved
the whole of humanity." The Koran that our young people learn is full
of stories and lessons from the history of humanity as a whole. The
Gospels and the Torah are referred to; Jesus and Abraham are
mentioned. In fact there is more mention in the Koran of the prophet
Moses than of any other. It acknowledges the coexistence of other
faiths, and in doing so acknowledges that other cultures can live
together in peace. "There is no compulsion in religion," it states,
meaning that people should not be compelled to change their faith.
Elsewhere it states, "To you, your religion; to me mine." Respect for
religious values and justice is at the Koran's core. The Koranic
history we teach our young provides ample examples of inter-religious
and international relationships; of how to live together. But some
extremists take elements of the sacred **ures out of con. They
act as individuals, and when they can't come together as part of a
political structure or consultative process, you find these dissident
factions creating their own rules, contrary to the spirit of the Koran
- which demands that those recognized as being in charge of Muslims
must consult together regarding society's affairs. There is a whole
chapter in the Koran entitled Consultation. Communal well being is
central to human life, so there is a concept in Islam called Istihsan,
which means "to look for the common good". Even though the Koran may
lay down a diktat, scholars are also supposed to consider the
circumstances prevalent at the time. Sometimes that means choosing the
lesser of two evils or even suspending legislation if necessary: for
instance, a person who steals bread during a famine is not treated as
a thief. Once I wrote in a song, "Where do the children play?" Our
sympathy and thoughts go out to the families of all those who lost
their lives in this tragic act of violence, as well as all those
injured. But life must go on. Children still need to play, and people
need to live and learn more about their neighbors so that ignorance
doesn't breed more blind fanaticism. Moderation is part of faith, so
those who accuse Muslim schools of fostering fanaticism should learn a
bit more about Islam. The Prophet (peace be upon him) said, "Ruined
are those who insist on hardship in faith," and, "A believer remains
within the scope of his religion as long as he doesn't kill another
person illegally." Such knowledge and words of guidance are
desperately needed at this time, to separate fact from falsehood, and
to recognise the Last Prophet's own definition of that which makes a
person representative, or otherwise, of the faith he lived and the one
we try to teach. by Yusuf Islam (formerly the singer Cat Stevens)
Published on Monday, September 24, 2001 by Al-Hewar Magazine.

IF YOU WISH T

Re: Insert trusted timestamp to PDF

2011-12-07 Thread Matteo Boscolo

have a look at:
http://www.boscolini.eu/Boscolini/index.php?option=com_content&view=article&id=64%3Anumbering-pdf-file-in-python&catid=38%3Aprogramming&Itemid=55&lang=en 


here I number some pdf files ..

regards,
Matteo

Il 07/12/2011 20:41, Hegedüs, Ervin ha scritto:

Hello Everyone,

I'm looking for a tool, which can add a trusted timestamp to an
existing PDF file (and can sign - but currently only have to add
TS).

Could anybody help?


Thanks:


a.



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


Re: Dynamic variable creation from string

2011-12-07 Thread Terry Reedy

On 12/7/2011 12:09 PM, Massi wrote:


in my script I have a dictionary whose items are couples in the form
(string, integer values), say

D = {'a':1, 'b':2, 'c':3}

This dictionary is passed to a function as a parameter, e.g. :

def Sum(D) :
 return D['a']+D['b']+D['c']

Is there a way to create three variables dynamically inside Sum in
order to re write the function like this?

def Sum(D) :
 # Here some magic to create a,b,c from D
 return a+b+c


No. The set of local names for a function is determined when the 
definition is executed and the body is compiled. Python 2 had an 
exception -- 'from x import *' -- that required an alternate 
complilation pathway. That possibility was eliminated in Python 3 and is 
now a syntax error.


Within functions, 'locals().update(D)' is more or less guaranteed to 
*not* add local names to the local namespace, even if it does add keys 
to the locals() dict that shadows the local namespace.


> It is really important that the scope of a,b,c is limited to the Sum
> function, they must not exisit outside it or inside any other nested
> functions.

Local names, by definition, are lexically scoped to the function 
definition and are not visible without. Since nested definitions are 
part of that lexical scope, local names are always visible within nested 
definitions. You cannot stop that. The association of local names is 
usually dynamically limited to one function call. The two exceptions are 
enclosure by a nested function that survives the function call and 
generators in a paused state.


--
Terry Jan Reedy

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


Re: Dynamic variable creation from string

2011-12-07 Thread Steven D'Aprano
On Wed, 07 Dec 2011 09:09:16 -0800, Massi wrote:

> Is there a way to create three variables dynamically inside Sum in order
> to re write the function like this?
> 
> def Sum(D) :
> # Here some magic to create a,b,c from D 
> return a+b+c

No magic is needed.

a, b, c = D['a'], D['b'], D['c']

However, there is no way to create variables from an *arbitrary* set of 
keys. And a good thing too, because how could you use them?

def Sum(D):
   # Magic happens here
   return a + b + z + foo + spam + fred + ... ???

Since you don't know what variable names will be created, you don't know 
which variables you need to add. Dynamic creation of variables is ALMOST 
ALWAYS the wrong approach.

In this specific case, what you should do to add up an arbitrary number 
of values from a dict is:

sum(D.values())


> It is really important that the scope of a,b,c is limited to the Sum
> function, they must not exisit outside it or inside any other nested
> functions.

The first part is trivially easy; since you are assigning to local 
variables, by definition they will be local to the Sum function and will 
not exist outside it.

The second part is impossible, because that is not how Python works. 
Nested functions in Python can always see variables in their enclosing 
scope. If you don't want that behaviour, use another language, or don't 
use nested functions.


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


Re: Dynamic variable creation from string

2011-12-07 Thread Terry Reedy

On 12/7/2011 7:03 PM, Steven D'Aprano wrote:

On Wed, 07 Dec 2011 09:09:16 -0800, Massi wrote:


Is there a way to create three variables dynamically inside Sum in order
to re write the function like this?


I should have mentioned in my earlier response that 'variable' is a bit 
vague and misleading. Python has names bound to objects.



def Sum(D) :
 # Here some magic to create a,b,c from D
 return a+b+c


No magic is needed.

a, b, c = D['a'], D['b'], D['c']


This is not what most people mean by 'dynamically created variables'. 
The names are static, in the code, before the code is executed.
In 2.x, 'from x import *' dynamically creates local names that are not 
in the code that contains the import. Dynamically creating objects is 
what Python code does all the time.


--
Terry Jan Reedy

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


Re: Dynamic variable creation from string

2011-12-07 Thread Steven D'Aprano
On Wed, 07 Dec 2011 19:27:43 -0500, Terry Reedy wrote:

> On 12/7/2011 7:03 PM, Steven D'Aprano wrote:
>> On Wed, 07 Dec 2011 09:09:16 -0800, Massi wrote:
>>
>>> Is there a way to create three variables dynamically inside Sum in
>>> order to re write the function like this?
> 
> I should have mentioned in my earlier response that 'variable' is a bit
> vague and misleading. Python has names bound to objects.
> 
>>> def Sum(D) :
>>>  # Here some magic to create a,b,c from D return a+b+c
>>
>> No magic is needed.
>>
>> a, b, c = D['a'], D['b'], D['c']
> 
> This is not what most people mean by 'dynamically created variables'.

I know that. I'm just pointing out that the OP can solve his *stated* 
problem of creating a *fixed* number of variables with *known* names 
without any magic.

I went on to discuss the case of an unknown number of unknown names, and 
suggested that the OP not do that, because it is much less useful than 
people think.


> The names are static, in the code, before the code is executed. In 2.x,
> 'from x import *' dynamically creates local names that are not in the
> code that contains the import. Dynamically creating objects is what
> Python code does all the time.

Of course. And even dynamically creating names: names don't exist until 
they are created at runtime. Name deletion is also possible. But what 
isn't normally done is "dynamic variable creation" in the sense of 
creating arbitrary variables (names bound to objects) based on names 
known only at runtime. That's extremely rare, and for good reason.


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


How to get Python make to detect /usr/local/ssl

2011-12-07 Thread B.A.S.
Any Python developers out there that help me?

I would like to configure/make Python so it uses my local OpenSSL-1.0.0e 
install in /usr/local/ssl.

I have tried uncommenting the promising section of 
./Python 2.7.2/Modules/Setup.dist below without success.

How to do it! Would like to upgrade SQLite as well...

-- snip of Setup.dist 

# Socket module helper for socket(2)
_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

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


Re: Dynamic variable creation from string

2011-12-07 Thread Chris Angelico
On Thu, Dec 8, 2011 at 11:03 AM, Steven D'Aprano
 wrote:
>> It is really important that the scope of a,b,c is limited to the Sum
>> function, they must not exisit outside it or inside any other nested
>> functions.
>
> The second part is impossible, because that is not how Python works.
> Nested functions in Python can always see variables in their enclosing
> scope. If you don't want that behaviour, use another language, or don't
> use nested functions.

To the OP: By "nested functions", did you mean actual nested functions
(those defined inside this function), or simply functions called from
this one?

This is a nested function, as the term is usually taken to mean:

def outer_function():
a = 1
def inner_function():
b = 2
return a+b
print(inner_function())  # Prints 3

The inner function has access to all of the outer function's
namespace. But if you meant this:

def function_1():
b = 2
return a+b

def function_2():
a = 1
print(function_1())

then it's quite the other way around - Python never shares variables
in this way (this would have function_1 assume that 'a' is a global
name, so if it's not, you'll get a run-time NameError).

As Steven says, there's no way in Python to hide variables from an
actual nested function. But if you just mean a function called from
this one, then what you want is the normal behaviour (and if you
actually want to share variables, you pass them as arguments).

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


Re: Questions about LISP and Python.

2011-12-07 Thread Rick Johnson
On Dec 6, 10:58 am, Ian Kelly  wrote:

(snip... beautiful retort)

Ian you make some damn good points and i could not help but laugh
hysterically at your dissection of Xah's tutorial. I don't 100% agree
with everything Mr. Lee rants about, like for instance, documents
needing to hyper link every possible sub-subject in every possible
subject -- we'd end up with a spaghetti mess of links. Besides,
students should follow a "linear" learning curve and not haphazardly
jump from subject to subject.

However, that being said, what does it prove when you can dissect
someones rant with elegant irony? It simply means that no ONE person
can write great documentation. They say... "it takes a village to
raise a child"... Hmm, i believe it takes a community to create good
docs.

Q: Do we have a "community" here? Hmm, more on that later...

I truly believe that Mr. Lee wants to make Python a better language,
and many other languages also! However he has experienced so much
resistance to his comments that he has  (like many among us) developed
what Psychologists call "learned helplessness".

Xah: "I found a problem"
Communty: "Well write a freaking patch or shut the hell up!
Xah: "Why bother, you will just throw it in the trash to spite me no
matter how good it is."
Commuinty: "You're lazy, you just want to complain"
Xah: "But, that's all you will allow me to do!"

Who's fault is it that Xah is not a productive part of this community?
Hmm? Do we just take the easy way out an blame Xah? Or do we need to
observe our "collective" attitudes to perceived "outsiders"?

I believe this community has a cancer. A cancer that is rotting us
from the inside. A cancer that has metastasis and is spreading like
wild fire.

*Inquisitive Joe asked:* What is the source of this cancer Rick?

The source is a direct result of insufficient leadership. Our current
leader has failed us. Maybe he never wanted to be a leader, but when
you go and declare yourself a "benevolent dictator for life" you'd
damn well better act like one!

Why has GvR not admonished the atrocious behavior of some people in
this community? Why has GvR not admitted publicly the hideous state of
IDLE and Tkinter? Where is the rally call? Where is the community
spirit? The future of Pythin is in your hands Mr. Van Rossum. Will you
step up and do what needs to be done? Will you have the courage? i
sincerely hope so. If not, please step down and allow someone to lead.
I await the supreme commanders ascent to power.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Questions about LISP and Python.

2011-12-07 Thread Rick Johnson
On Dec 6, 9:52 pm, alex23  wrote:
> (snip rambling nonsense)

Alex, i hope you are being theatrical with all this. If not, i fear
you may be putting too much stress on your heart. Please calm down.

> The months in which you don't post are an absolute goddamn
> _delight_

I am working on Python4000 Alex. *Someone* has to re-ignite Guido's
original vision.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Losing com pointer

2011-12-07 Thread Mark Hammond

On 7/12/2011 7:22 PM, Matteo Boscolo wrote:

Hi all,
I need some help to a com problem..

I got this class:

class foo(object):
def setComObject(comObject):
self.comO=comObject #This is a com object from a cad application

def showForm(self)
# use the self.comO to read some information from the cad application
# Show the pyqt form as child of cad application
# do somthing with the form
# do somthing with the self.comO <- Here if pass some time I'm not
able to call any method to the com object


What are the symptoms of that?  ie, what error do you get?

I suspect the remote process is going away - it almost certainly has 
nothing to do with Python itself deciding to make the object go away.


Mark



a=foo()
o="get istance of a cad application via com"
a.setComObject(o)
a.showForm() #< here if pass some time I'm not able to call any
method to the com object

but I I' re call the
a.setComObject(o) #Faster and I take less the 30 seconds on the form
object it works well

It seems a problem of the garbage collector .. but I'm not sure how to
debug it ..

any help is really appreciated.. it's the last dangerous bug in our
application ...

Regards,
Matteo


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


Re: Insert trusted timestamp to PDF

2011-12-07 Thread Hegedüs , Ervin
Hello Irmen,

On Wed, Dec 07, 2011 at 08:59:11PM +0100, Irmen de Jong wrote:
> On 07-12-11 20:41, Hegedüs, Ervin wrote:
> >Hello Everyone,
> >
> >I'm looking for a tool, which can add a trusted timestamp to an
> >existing PDF file (and can sign - but currently only have to add
> >TS).
> 
> Note sure what a 'trusted timestamp' is,
that's very important to understand what does it mean -
otherwise it's just groping :)

http://tools.ietf.org/html/rfc3161
http://en.wikipedia.org/wiki/Trusted_timestamp

> but pdftk can manipulate
> pdf files. See http://www.pdflabs.com/docs/pdftk-man-page/
> (nothing to do with Python btw!)

looks like it couldn't, but I'll contact them.


thanks:


a.

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


Re: Insert trusted timestamp to PDF

2011-12-07 Thread Alec Taylor
Just digitally sign the document using python-gnupg

/problem-solved!

On Thu, Dec 8, 2011 at 4:09 PM, Hegedüs,  wrote:
> Hello Irmen,
>
> On Wed, Dec 07, 2011 at 08:59:11PM +0100, Irmen de Jong wrote:
>> On 07-12-11 20:41, Hegedüs, Ervin wrote:
>> >Hello Everyone,
>> >
>> >I'm looking for a tool, which can add a trusted timestamp to an
>> >existing PDF file (and can sign - but currently only have to add
>> >TS).
>>
>> Note sure what a 'trusted timestamp' is,
> that's very important to understand what does it mean -
> otherwise it's just groping :)
>
> http://tools.ietf.org/html/rfc3161
> http://en.wikipedia.org/wiki/Trusted_timestamp
>
>> but pdftk can manipulate
>> pdf files. See http://www.pdflabs.com/docs/pdftk-man-page/
>> (nothing to do with Python btw!)
>
> looks like it couldn't, but I'll contact them.
>
>
> thanks:
>
>
> a.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insert trusted timestamp to PDF

2011-12-07 Thread Hegedüs , Ervin
Hello,

On Thu, Dec 08, 2011 at 04:28:01PM +1100, Alec Taylor wrote:
> Just digitally sign the document using python-gnupg
> 
> /problem-solved!

using gnupg to sign a document != add a timestamp to a pdf.

May be this doc helps to clear what's the different, and what I want:

http://learn.adobe.com/wiki/download/attachments/52658564/digital_signatures_in_acrobat_9x.pdf?version=1



thanks:


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


I love the decorator in Python!!!

2011-12-07 Thread 88888 Dihedral
I use the @ decorator to behave exactly like a c macro that 
does have fewer side effects. 

I am wondering is there other interesting methods to do the 
jobs in Python?

A lot people complained that no macro in Python. 

Cheers to the rule of Python :
If there's none then just go ahead and  build one!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insert trusted timestamp to PDF

2011-12-07 Thread marco . rucci
Hi, take a look at this online tool: http://easytimestamping.com

It is able to apply RFC3161 compliant trusted timestamps, issued by accredited 
Certification Authorities. 

The timestamp is applied to the pdf in detached mode (i.e. as a separate .tsr 
file)

If you need to integrate the timestamping process in a python app, be patient, 
we will release an API and a command line version very soon.

--
Marco Rucci
securo.it
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insert trusted timestamp to PDF

2011-12-07 Thread Alec Taylor
Or the python implementation of that RFC:
http://pypi.python.org/pypi/rfc3161/0.1.3

On Thu, Dec 8, 2011 at 6:39 PM,   wrote:
> Hi, take a look at this online tool: http://easytimestamping.com
>
> It is able to apply RFC3161 compliant trusted timestamps, issued by 
> accredited Certification Authorities.
>
> The timestamp is applied to the pdf in detached mode (i.e. as a separate .tsr 
> file)
>
> If you need to integrate the timestamping process in a python app, be 
> patient, we will release an API and a command line version very soon.
>
> --
> Marco Rucci
> securo.it
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list