!!! Kausha-s very HOT kiss scene.avi !!!

2010-04-13 Thread "Lou " Shy Amateur Strips
!!! Kausha-s very HOT kiss scene.avi !!!

http://sites.google.com/site/hifiprofile/
http://sites.google.com/site/hifiprofile/

 <<< EXTREME HOT GALLERIES >>>

http://sites.google.com/site/hifiprofile/

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


Seg fault when launching my module through my C/C++ application

2010-04-13 Thread Maxime Boure
Hello everyone,

I made a small python module to command NetworkManager and get some signals
from it.

My script works well alone, but when I launch it from my C/C++ program it
crashes at a certain function (here iface.GetDevices). Here is the function
that crashes and next my gdb print

*def get_device_path_by_type(type):*
*  proxy = bus.get_object('org.freedesktop.NetworkManager',
'/org/freedesktop/NetworkManager')*
*  iface = dbus.Interface(proxy,
dbus_interface='org.freedesktop.NetworkManager')*
*  print "iface : %s" % iface *
*  for d in iface.GetDevices():*
*print "--> after getdevices"*
*proxy = bus.get_object('org.freedesktop.NetworkManager', d)*
*iface = dbus.Interface(proxy,
dbus_interface='org.freedesktop.DBus.Properties')*
*devtype = iface.Get('org.freedesktop.NetworkManager.Device',
'DeviceType')*
*print "type : %d" % devtype*
*if devtype == type:*
*  print "%s" % d*
*  return d*
*  print "return none"*
*  return None*
*- - - - - - - - - - - - -  - - - - - - - - - - - -  - - - - - - - - - - -
-  - - - - - - - - - - - -  - - - - - - - - - - - -  - - - - - - - - - - -
-  - - - - - - - - - - - - *
*
iface :  :1.0 /org/freedesktop/NetworkManager at 0x3fae2710> implementing
'org.freedesktop.NetworkManager' at 0x3fae27d0>

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x4035a460 (LWP 2214)]
0x3b8af144 in sem_post@@GLIBC_2.4 () from /lib/libpthread.so.0
(gdb) bt
#0  0x3b8af144 in sem_post@@GLIBC_2.4 () from /lib/libpthread.so.0
#1  0x3b2ca9b4 in PyThread_release_lock () from /usr/lib/libpython2.6.so.1.0
#2  0x3b2987c4 in PyEval_ReleaseLock () from /usr/lib/libpython2.6.so.1.0
#3  0x3b2bd518 in PyThreadState_DeleteCurrent ()
   from /usr/lib/libpython2.6.so.1.0
#4  0x3f9bce50 in ?? () from /usr/lib/pyshared/python2.6/_dbus_bindings.so

Just so you know I use other function from that script that works well with
my C/C++ application. Do you have any idea of why there would be a threading
problem ? And why a seg fault ?

Thank you for your inputs

Regards

Maxime

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


curious about python version numbers

2010-04-13 Thread Alex Hall
Hi all,
I am just curious: if Python3.x is already out, why is 2.7 being
released? Are there two main types of Python? Thanks.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


packaging multiple python scripts as Windows exe file

2010-04-13 Thread Alex Hall
Hi all,
While my project is still suffering from major import problems, I will
soon have to try to package it as a Windows executable file. I do not
want an installer; I want the user to be able to run the program for
as long as they want, then to quit (by using a command from inside the
program) and that is it. Nothing to install, no files to copy, no
registry editing, just start and use it until done.

I know about the popular solutions for this sort of thing, but I read
that a DLL is required, and that this dll cannot be (legally)
distributed by myself? A few questions here:
1. Did I read this wrong / is this outdated? Please answer 'yes' as
this will be a real pain to deal with.

2. If I must have it but can distribute it, where should it go so my
program can find it?

3. If the user must download it for legal reasons, instead of me
giving it to them, can I just have a Python script take care of it and
put it in the same directory as the program, so the program can find
it, or do I need to register the dll with the system? If I need to
register, does this require admin login?

Thanks as always!

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: curious about python version numbers

2010-04-13 Thread Xavier Ho
Hi Alex,

It's because Python 3.x introduced a lot of backwards incompatibilities.
Python 2.7 aims to bridge that gap, so many 3rd party libraries that depend
on Python 2.x can transit onto Python 3.x better, as I understand.

Cheers,
Xav


On Mon, Apr 12, 2010 at 12:52 PM, Alex Hall  wrote:

> Hi all,
> I am just curious: if Python3.x is already out, why is 2.7 being
> released? Are there two main types of Python? Thanks.
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com; http://www.facebook.com/mehgcap
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: curious about python version numbers

2010-04-13 Thread Alf P. Steinbach

* Alex Hall:

Hi all,
I am just curious: if Python3.x is already out, why is 2.7 being
released? Are there two main types of Python? Thanks.


Old code and old programming habits may work as-is with 2.7 but not with a 3.x 
implementation.


So yes, there are two main extant variants of Python, 2.x and 3.x (and more if 
you count even earlier versions).


2.7 helps to ease the transition, and provides bug-fixes and better efficiency 
for the 2.x variant.



Cheers & hth.,

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


Re: curious about python version numbers

2010-04-13 Thread Shashwat Anand
It is like releasing window Xp SP3 even if Vista is out.

The problem is we should start using python 3.x but many application like
django, twisted had not migrated yet. Hence this stuff to support 2.x . 2.7
is the last 2.x version, no more.

On Tue, Apr 13, 2010 at 2:28 PM, Alf P. Steinbach  wrote:

> * Alex Hall:
>
>  Hi all,
>> I am just curious: if Python3.x is already out, why is 2.7 being
>> released? Are there two main types of Python? Thanks.
>>
>
> Old code and old programming habits may work as-is with 2.7 but not with a
> 3.x implementation.
>
> So yes, there are two main extant variants of Python, 2.x and 3.x (and more
> if you count even earlier versions).
>
> 2.7 helps to ease the transition, and provides bug-fixes and better
> efficiency for the 2.x variant.
>
>
> Cheers & hth.,
>
> - Alf
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: curious about python version numbers

2010-04-13 Thread Ben Finney
Alex Hall  writes:

> I am just curious: if Python3.x is already out, why is 2.7 being
> released? Are there two main types of Python?

Python 3.x brings improvements that break backward compatibility:

Python 3.0 (a.k.a. "Python 3000" or "Py3k") is a new version of the
language that is incompatible with the 2.x line of releases. The
language is mostly the same, but many details, especially how
built-in objects like dictionaries and strings work, have changed
considerably, and a lot of deprecated features have finally been
removed. Also, the standard library has been reorganized in a few
prominent places.

http://www.python.org/download/releases/3.0/>

For that reason, when Python 3.x was being planned, the Python
developers committed to supporting Python 2.x with backward-compatible
releases for an indeterminate length of time to allow third-party
libraries to steadily migrate to Python 3.x so it becomes more
attractive to use it for all new development.

Python 2.7 has been announced to be the last feature release in the 2.x
series:

Python 2.7 is scheduled to be the last major version in the 2.x
series before it moves into 5 years of bugfix-only mode.

http://www.python.org/download/releases/2.7/>

-- 
 \   “The Initial Mystery that attends any journey is: how did the |
  `\   traveller reach his starting point in the first place?” —Louise |
_o__)  Bogan, _Journey Around My Room_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tough sorting problem: or, I'm confusing myself

2010-04-13 Thread david jensen
On Apr 11, 9:39 pm, Raymond Hettinger  wrote:

> The overall algorithm looks about right.
> The inner-loop could be tighted-up a bit.
> And you could replace the outer sort with a heap.
>
> best2 = {}
> for i in itertools.combinations(range( 2**m), n-1):
>     scorelist = []
>     for j in range( 2**m ):
>         if j not in i:
>             k = tuple(sorted(i + (j,)))
>             scorelist.append((j, res[k][k.index(j)]))
>     best2[i] = heapq.nlargest(2, scorelist,
> key=operator.itemgetter(1))
>
> Raymond

Thanks for the ideas... I should have seen the k = tuple(sorted(i +
(j,))). I'm not sure a heap will help much, and at least to me,
doesn't improve readability.

Thanks for taking a look, I appreciate it!

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


Re: Tough sorting problem: or, I'm confusing myself

2010-04-13 Thread david jensen
On Apr 12, 1:22 am, Paul McGuire  wrote:
> On Apr 9, 10:03 am, david jensen  wrote:
>
>
>
> > Hi all,
>
> > I'm trying to find a good way of doing the following:
>
> > Each n-tuple in combinations( range( 2 ** m ), n ) has a corresponding
> > value n-tuple (call them "scores" for clarity later). I'm currently
> > storing them in a dictionary, by doing:
>
> > 
> > res={}
> > for i in itertools.combinations( range( 2**m ) , n):
> >     res[ i ] = getValues( i )    # getValues() is computationally
> > expensive
> > 
>
> > For each (n-1)-tuple, I need to find the two numbers that have the
> > highest scores versus them. I know this isn't crystal clear, but
> > hopefully an example will help: with m=n=3:
>
> > Looking at only the (1, 3) case, assuming:
> > getValues( (1, 2, 3) ) == ( -200, 125, 75 )    # this contains the
> > highest "other" score, where 2 scores 125
> > getValues( (1, 3, 4) ) == ( 50, -50, 0 )
> > getValues( (1, 3, 5) ) == ( 25, 300, -325 )
> > getValues( (1, 3, 6) ) == ( -100, 0, 100 )    # this contains the
> > second-highest, where 6 scores 100
> > getValues( (1, 3, 7) ) == ( 80, -90, 10  )
> > getValues( (1, 3, 8) ) == ( 10, -5, -5 )
>
> > I'd like to return ( (2, 125), (6, 100) ).
>
> > The most obvious (to me) way to do this would be not to generate the
> > res dictionary at the beginning, but just to go through each
> > combinations( range( 2**m), n-1) and try every possibility... this
> > will test each combination n times, however, and generating those
> > values is expensive. [e.g. (1,2,3)'s scores will be generated when
> > finding the best possibilities for (1,2), (1,3) and (2,3)]
>
> Add a memoizing decorator to getValues, so that repeated calls will do
> lookups instead of repeated calculations.
>
> -- Paul

Thanks for the idea... I'd thought of that, but didn't use it because
I don't think it improves complexity or readability: just makes it a
little more intuitive.

But thanks for your time!

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


DjangoCon Europe - 24. - 26.5.2010 in Berlin

2010-04-13 Thread Markus Zapke-Gründemann
DjangoCon Europe[1] is a Django[2] conference that aims to bring 
together the community and provide a wide range of sessions, panels, 
lightning talks and showcases of Django usage within various businesses. 
We aim to educate and bring people together to turn new ideas into 
working code!


The conference is organized by the German Django Association[3], takes 
place from the 24th to 26th of May 2010 and is located in Berlin, 
Germany. Sprints will be held on the 27th and 28th of May.


Tickets for the conference are available on a first-come, first-served 
basis, and are priced by attendee type:


* Corporate: 595 EUR
* Hobbyist: 289 EUR
* Student: 199 EUR

After many trials and tribulations, we're delighted to announce that 
DjangoCon Europe is accepting talk submissions until the 1st of May.


Django is a high-level Python Web framework that encourages rapid 
development and clean, pragmatic design.



[1] http://www.djangocon.eu/
[2] http://www.djangoproject.com/
[3] http://djangode.pbworks.com/

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


HTMLParser can't read japanese

2010-04-13 Thread Dodo

Here's a small script to generate again the error
running windows 7 with python 3.1

FILE : parseShift.py

import urllib.request as url
from html.parser import HTMLParser

class myParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print("Start of %s tag : %s" % (tag, attrs))


test = myParser()   
handle = url.urlretrieve("http://localhost/shift.html";)
handleTemp = open( handle[0] , encoding="Shift-JIS" )
test.feed( handleTemp.read() )
handleTempl.close()

FILE : shift.html (encoded Shift-JIS)

Some 
random japanese
東方プロジェクト Link


OUTPUT

Start of p tag : [('class', 'thisisclass (not_in_japanese) 
reading_this_should_be_ok')]

Start of p tag : []
Start of strong tag : []
Traceback (most recent call last):
  File "D:\Dorian\Python\parseShift.py", line 12, in 
test.feed( handleTemp.read() )
  File "C:\Python31\lib\html\parser.py", line 108, in feed
self.goahead(0)
  File "C:\Python31\lib\html\parser.py", line 148, in goahead
k = self.parse_starttag(i)
  File "C:\Python31\lib\html\parser.py", line 268, in parse_starttag
self.handle_starttag(tag, attrs)
  File "D:\Dorian\Python\parseShift.py", line 6, in handle_starttag
print("Start of %s tag : %s" % (tag, attrs))
  File "C:\Python31\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 
44-52: c

haracter maps to 


any help?
Dorian
--
http://mail.python.org/mailman/listinfo/python-list


Re: HTMLParser can't read japanese

2010-04-13 Thread Dodo

alright, it's just because of Windows cmd
in IDLE it works fine

any workaround?

Dorian

Le 13/04/2010 13:40, Dodo a écrit :

Here's a small script to generate again the error
running windows 7 with python 3.1

FILE : parseShift.py

import urllib.request as url
from html.parser import HTMLParser

class myParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print("Start of %s tag : %s" % (tag, attrs))


test = myParser()
handle = url.urlretrieve("http://localhost/shift.html";)
handleTemp = open( handle[0] , encoding="Shift-JIS" )
test.feed( handleTemp.read() )
handleTempl.close()

FILE : shift.html (encoded Shift-JIS)

Some
random japanese
東方プロジェクト Link

OUTPUT

Start of p tag : [('class', 'thisisclass (not_in_japanese)
reading_this_should_be_ok')]
Start of p tag : []
Start of strong tag : []
Traceback (most recent call last):
File "D:\Dorian\Python\parseShift.py", line 12, in 
test.feed( handleTemp.read() )
File "C:\Python31\lib\html\parser.py", line 108, in feed
self.goahead(0)
File "C:\Python31\lib\html\parser.py", line 148, in goahead
k = self.parse_starttag(i)
File "C:\Python31\lib\html\parser.py", line 268, in parse_starttag
self.handle_starttag(tag, attrs)
File "D:\Dorian\Python\parseShift.py", line 6, in handle_starttag
print("Start of %s tag : %s" % (tag, attrs))
File "C:\Python31\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position
44-52: c
haracter maps to 


any help?
Dorian


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


Re: HTMLParser can't read japanese

2010-04-13 Thread Stefan Behnel

Dodo, 13.04.2010 13:40:

Here's a small script to generate again the error
running windows 7 with python 3.1

FILE : parseShift.py

import urllib.request as url
from html.parser import HTMLParser

class myParser(HTMLParser):
  def handle_starttag(self, tag, attrs):
print("Start of %s tag : %s" % (tag, attrs))


You problem is the last line. Your terminal does not support printing the 
text, so you get an exception here.


Either change your terminal encoding to a suitable encoding, or write the 
text to an encoded file instead (see the 'encoding' option of the open() 
function for that).


Stefan

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


Error using httlib's HTTPSConnection with PKCS#12 certificate

2010-04-13 Thread Rémi
I'm trying to use httplib's HTTPSConnection  for client validation,
using a PKCS #12 certificate.  I know the certificate is good, as I
can connect to the server using it in MSIE and Firefox.

Here's my connect function (the certificate includes the private key).
I've pared it down to just the basics:

def connect(self, cert_file, host, usrname, passwd):
self.cert_file = cert_file
self.host = host

self.conn = httplib.HTTPSConnection(host=self.host, 
port=self.port,
key_file=cert_file, cert_file=cert_file)

self.conn.putrequest('GET', 'pathnet/,DanaInfo=200.222.1.1+')
self.conn.endheaders()
retCreateCon = self.conn.getresponse()

if is_verbose:
print "Create HTTPS connection, " + retCreateCon.read()

# ...


(Note: the request path is correct, as I connect to it in MSIE and
Firefox. I changed the IP address for the post.)

When I try to run this using a PKCS#12 certificate (a .pfx file), I
get back what appears to be an openSSL error. Here is the entire error
traceback:

  File "Usinghttplib_Test.py", line 175, in 
t.connect(cert_file=opts["-keys"], host=host_name, usrname=opts["-
username"], passwd=opts["-password"])
  File "Usinghttplib_Test.py", line 40, in connect
self.conn.endheaders()
  File "c:\python26\lib\httplib.py", line 904, in endheaders
self._send_output()
  File "c:\python26\lib\httplib.py", line 776, in _send_output
self.send(msg)
  File "c:\python26\lib\httplib.py", line 735, in send
self.connect()
  File "c:\python26\lib\httplib.py", line 1112, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
  File "c:\python26\lib\ssl.py", line 350, in wrap_socket
suppress_ragged_eofs=suppress_ragged_eofs)
  File "c:\python26\lib\ssl.py", line 113, in __init__
cert_reqs, ssl_version, ca_certs) ssl.SSLError: [Errno 336265225]
_ssl.c:337: error:140B0009:SSL
routines:SSL_CTX_use_PrivateKey_file:PEM lib


Notice, the openSSL error notes "PEM lib", which I found odd, since
I'm not trying to use a PEM certificate.

For kicks, I converted the PKCS#12 cert to a PEM cert, and ran the
same code using *that*.  In that case, I received no error, I was
prompted to enter the PEM pass phrase, and the code did attempt to
reach the server.  (I received the response "The service is not
available. Please try again later.", but I believe that would be
because the server does not accept the PEM cert.  I can't connect in
Firefox to the server using the PEM cert either.)

Is httplib's HTTPSConnection supposed to support PCKS#12
certificates?  (That is, pfx files.)  If so, why does it look like
openSSL is trying to load it inside the PEM lib?  Am I doing this all
wrong?

Any advice is welcome.

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


Code dojo on Thursday?

2010-04-13 Thread John Maclean
Is there a code Dojo in London on Thurs? I've requested two places but
have not heard a reply yet.


-- 
John Maclean MSc. (DIC) Bsc. (Hons),Core Linux Systems Engineering,07739
171 531
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: curious about python version numbers

2010-04-13 Thread Alex Hall
Thanks, everyone, for the answers! I am still on 2.6 since so many
packages rely on it. I got 3.1 at first, but I could not get much to
work with it so I installed 2.6 and have only found one package which
refuses to work, instead of a lot of them.

On 4/13/10, Shashwat Anand  wrote:
> It is like releasing window Xp SP3 even if Vista is out.
>
> The problem is we should start using python 3.x but many application like
> django, twisted had not migrated yet. Hence this stuff to support 2.x . 2.7
> is the last 2.x version, no more.
>
> On Tue, Apr 13, 2010 at 2:28 PM, Alf P. Steinbach  wrote:
>
>> * Alex Hall:
>>
>>  Hi all,
>>> I am just curious: if Python3.x is already out, why is 2.7 being
>>> released? Are there two main types of Python? Thanks.
>>>
>>
>> Old code and old programming habits may work as-is with 2.7 but not with a
>> 3.x implementation.
>>
>> So yes, there are two main extant variants of Python, 2.x and 3.x (and
>> more
>> if you count even earlier versions).
>>
>> 2.7 helps to ease the transition, and provides bug-fixes and better
>> efficiency for the 2.x variant.
>>
>>
>> Cheers & hth.,
>>
>> - Alf
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generating a rainbow?

2010-04-13 Thread Giacomo Boffi
Tobiah  writes:

> I'm having a difficult time with this.  I want
> to display a continuous range of hues using HTML
> hex representation (#RRGGBB).  How would I go 
> about scanning through the hues in order to
> make a rainbow?

if you mean real rainbows when you say "rainbow", as rainbows go from
low to high wavelengths and you have to specify colors to your display
in RGB, i think that you have to read, e.g.,

http://www.physics.sfasu.edu/astro/color.html

otoh if you mean simply a continuos palette with varying hues,
excellent answers were already posted

hth
g
-- 
compro mobili vecchi - vendo mobili antichi
-- 
http://mail.python.org/mailman/listinfo/python-list


Unit testing errors (testing the platform module)

2010-04-13 Thread John Maclean
I normally use  languages unit testing framework to get a better
understanding of how a language works. Right now I want to grok the
platform module;


 1 #!/usr/bin/env python
  2 '''a pythonic factor'''
  3 import unittest
  4 import platform
  5
  6 class TestPyfactorTestCase(unittest.TestCase):
  7 def setUp(self):
  8 '''setting up stuff'''
 13
 14 def testplatformbuiltins(self): 15
'''platform.__builtins__.blah '''
 16 self.assertEquals(platform.__builtins__.__class__, "")
 17
 18
 19 def tearDown(self):
 20 print 'cleaning stuff up'
 21
 22 if __name__ == "__main__":
 23 unittest.main()


Is there an error in my syntax? Why is my test failing? Line 16.


python stfu/testing/test_pyfactor.py
Fcleaning stuff up

==
FAIL: platform.__builtins__.blah
--
Traceback (most recent call last):
  File "stfu/testing/test_pyfactor.py", line 16, in testplatformbuiltins
self.assertEquals(platform.__builtins__.__class__, "")
AssertionError:  != ""

--
Ran 1 test in 0.000s

FAILED (failures=1)

-- 
John Maclean MSc. (DIC) Bsc. (Hons),Core Linux Systems Engineering,07739
171 531
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unit testing errors (testing the platform module)

2010-04-13 Thread Benjamin Kaplan
On Tue, Apr 13, 2010 at 10:01 AM, John Maclean  wrote:

> I normally use  languages unit testing framework to get a better
> understanding of how a language works. Right now I want to grok the
> platform module;
>
>
>  1 #!/usr/bin/env python
>  2 '''a pythonic factor'''
>  3 import unittest
>  4 import platform
>  5
>  6 class TestPyfactorTestCase(unittest.TestCase):
>  7 def setUp(self):
>  8 '''setting up stuff'''
>  13
>  14 def testplatformbuiltins(self): 15
> '''platform.__builtins__.blah '''
>  16 self.assertEquals(platform.__builtins__.__class__, "ict'>")
>  17
>  18
>  19 def tearDown(self):
>  20 print 'cleaning stuff up'
>  21
>  22 if __name__ == "__main__":
>  23 unittest.main()
>
>
> Is there an error in my syntax? Why is my test failing? Line 16.
>
>
Because you are checking if the type object dict is equal to the str object
"". A type object will never compare equal to a str object,
even though the string representation of them is the same.

>>> type({}) == ""
False
>>> type({})

>>> str(type({})) == ""
True
>>> type({}) == dict
True
>>> platform.__builtins__.__class__ == dict
True




>
> python stfu/testing/test_pyfactor.py
> Fcleaning stuff up
>
> ==
> FAIL: platform.__builtins__.blah
> --
> Traceback (most recent call last):
>  File "stfu/testing/test_pyfactor.py", line 16, in testplatformbuiltins
>self.assertEquals(platform.__builtins__.__class__, "")
> AssertionError:  != ""
>
> --
> Ran 1 test in 0.000s
>
> FAILED (failures=1)
>
> --
> John Maclean MSc. (DIC) Bsc. (Hons),Core Linux Systems Engineering,07739
> 171 531
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unit testing errors (testing the platform module)

2010-04-13 Thread Martin P. Hellwig

On 04/13/10 15:01, John Maclean wrote:

I normally use  languages unit testing framework to get a better
understanding of how a language works. Right now I want to grok the
platform module;


  1 #!/usr/bin/env python
   2 '''a pythonic factor'''
   3 import unittest
   4 import platform
   5
   6 class TestPyfactorTestCase(unittest.TestCase):
   7 def setUp(self):
   8 '''setting up stuff'''
  13
  14 def testplatformbuiltins(self): 15
'''platform.__builtins__.blah '''
  16 self.assertEquals(platform.__builtins__.__class__, "")
  17
  18
  19 def tearDown(self):
  20 print 'cleaning stuff up'
  21
  22 if __name__ == "__main__":
  23 unittest.main()


Is there an error in my syntax? Why is my test failing? Line 16.


python stfu/testing/test_pyfactor.py
Fcleaning stuff up

==
FAIL: platform.__builtins__.blah
--
Traceback (most recent call last):
   File "stfu/testing/test_pyfactor.py", line 16, in testplatformbuiltins
 self.assertEquals(platform.__builtins__.__class__, "")
AssertionError:  != ""

--
Ran 1 test in 0.000s

FAILED (failures=1)



What happens if you change this line:
self.assertEquals(platform.__builtins__.__class__, "")

To something like:
self.assertEquals(platform.__builtins__.__class__, type(dict()))

or
self.assertEquals(str(platform.__builtins__.__class__), "")

--
mph

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


Re: Unit testing errors (testing the platform module)

2010-04-13 Thread MRAB

John Maclean wrote:

I normally use  languages unit testing framework to get a better
understanding of how a language works. Right now I want to grok the
platform module;


 1 #!/usr/bin/env python
  2 '''a pythonic factor'''
  3 import unittest
  4 import platform
  5
  6 class TestPyfactorTestCase(unittest.TestCase):
  7 def setUp(self):
  8 '''setting up stuff'''
 13
 14 def testplatformbuiltins(self): 15
'''platform.__builtins__.blah '''
 16 self.assertEquals(platform.__builtins__.__class__, "")
 17
 18
 19 def tearDown(self):
 20 print 'cleaning stuff up'
 21
 22 if __name__ == "__main__":
 23 unittest.main()


Is there an error in my syntax? Why is my test failing? Line 16.


python stfu/testing/test_pyfactor.py
Fcleaning stuff up

==
FAIL: platform.__builtins__.blah
--
Traceback (most recent call last):
  File "stfu/testing/test_pyfactor.py", line 16, in testplatformbuiltins
self.assertEquals(platform.__builtins__.__class__, "")
AssertionError:  != ""

--
Ran 1 test in 0.000s

FAILED (failures=1)


platform.__builtins__.__class__ returns a dict, which is not the same as
"", a string.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unit testing errors (testing the platform module)

2010-04-13 Thread J. Cliff Dyer
The problem is that the class of platform.__builtins__ is a dict, not a
string containing the text "".  

Try replacing line 16 with this:

self.assertEqual(type(platform.__builtins__), dict)

Cheers,
Cliff


On Tue, 2010-04-13 at 15:01 +0100, John Maclean wrote:
> I normally use  languages unit testing framework to get a better
> understanding of how a language works. Right now I want to grok the
> platform module;
> 
> 
>  1 #!/usr/bin/env python
>   2 '''a pythonic factor'''
>   3 import unittest
>   4 import platform
>   5
>   6 class TestPyfactorTestCase(unittest.TestCase):
>   7 def setUp(self):
>   8 '''setting up stuff'''
>  13
>  14 def testplatformbuiltins(self): 15
> '''platform.__builtins__.blah '''
>  16 self.assertEquals(platform.__builtins__.__class__, " ict'>")
>  17
>  18
>  19 def tearDown(self):
>  20 print 'cleaning stuff up'
>  21
>  22 if __name__ == "__main__":
>  23 unittest.main()
> 
> 
> Is there an error in my syntax? Why is my test failing? Line 16.
> 
> 
> python stfu/testing/test_pyfactor.py
> Fcleaning stuff up
> 
> ==
> FAIL: platform.__builtins__.blah
> --
> Traceback (most recent call last):
>   File "stfu/testing/test_pyfactor.py", line 16, in testplatformbuiltins
> self.assertEquals(platform.__builtins__.__class__, "")
> AssertionError:  != ""
> 
> --
> Ran 1 test in 0.000s
> 
> FAILED (failures=1)
> 
> -- 
> John Maclean MSc. (DIC) Bsc. (Hons),Core Linux Systems Engineering,07739
> 171 531


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


Re: Code dojo on Thursday?

2010-04-13 Thread Tim Golden

On 13/04/2010 14:50, John Maclean wrote:

Is there a code Dojo in London on Thurs? I've requested two places but
have not heard a reply yet.




It's usually the first Thursday in the month. I've not heard about
one this Thursday. (Doesn't mean I'm right, of course).

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


Handling quotes in xml.dom text nodes

2010-04-13 Thread Chaim Krause
I am building a web page (HTML 4.01 Transitional) using
xml.dom.minidom. I have created a 

Re: Handling quotes in xml.dom text nodes

2010-04-13 Thread Chaim Krause
I am looking to find the best answer to my question, but in the mean
time I have resorted to monkey patching.

def _write_data_no_quote(writer, data):
"Writes datachars to writer."
data = data.replace("&", "&").replace("<", "<")
data = data.replace(">", ">")
writer.write(data)

minidom._write_data = _write_data_no_quote

Maybe this is the best way to do this. I'm not sure.
-- 
http://mail.python.org/mailman/listinfo/python-list


Constructing an if statement from the client data in python

2010-04-13 Thread Vishal Rana
Hi,

I need to construct an if statement from the data coming from the client as
below:

conditions: condition1, condition2, condition3, condition4 logical
operators: lo1, lo2, lo3 (Possible values: "and" "or")

Eg.

if condition1 lo1 condition2 lo3 condition4:
# Do something

I can think of eval/exec but not sure how safe they are! Any better approach
or alternative? Appreciate your responses :)

PS: Client-side: Flex, Server-side: Python, over internet

Thanks

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


Re: Code dojo on Thursday?

2010-04-13 Thread MRAB

Tim Golden wrote:

On 13/04/2010 14:50, John Maclean wrote:

Is there a code Dojo in London on Thurs? I've requested two places but
have not heard a reply yet.


It's usually the first Thursday in the month. I've not heard about
one this Thursday. (Doesn't mean I'm right, of course).


It looks like the 7th dojo was on 4 March and the 8th dojo was on 1
April, which were the first Thursdays of the month.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Constructing an if statement from the client data in python

2010-04-13 Thread Benjamin Kaplan
All the operators are available as functions in the operator module.
Just use a dict to select the correct function.


import operator

ops = {"and": operator.and_, "or": operator.or_}

op1 = ops[lo1]
op3 = ops[lo3]

if op3( op1( condition1, condition2), condition4) :
#do something



On Tue, Apr 13, 2010 at 11:56 AM, Vishal Rana  wrote:
>
> Hi,
>
> I need to construct an if statement from the data coming from the client as 
> below:
>
> conditions: condition1, condition2, condition3, condition4 logical operators: 
> lo1, lo2, lo3 (Possible values: "and" "or")
>
> Eg.
>
> if condition1 lo1 condition2 lo3 condition4:
>
>     # Do something
>
> I can think of eval/exec but not sure how safe they are! Any better approach 
> or alternative? Appreciate your responses :)
>
> PS: Client-side: Flex, Server-side: Python, over internet
>
> Thanks
>
> Vishal
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Handling quotes in xml.dom text nodes

2010-04-13 Thread Stefan Behnel

Chaim Krause, 13.04.2010 17:26:

I am building a web page (HTML 4.01 Transitional) using
xml.dom.minidom. I have created a

Re: Handling quotes in xml.dom text nodes

2010-04-13 Thread Chaim Krause
Stefan,

Thank you. The reason that I am using xml.dom.minidom is that I am
restricted to a stock RHEL5 stack. That means 2.4 with nothing added.
(Welcome to US Army IT !!!)

But, I figured out that I need to back up from xml.dom.minidom to
xml.dom and then I can use createCDATASection and get what I need.

Now I am off to fix the issue solving this unmasked. (Google Maps API
v3 doesn't like to be in an HTML 4.01 Transitional page. Ugh)

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


Re: curious about python version numbers

2010-04-13 Thread Terry Reedy

On 4/13/2010 9:54 AM, Alex Hall wrote:

Thanks, everyone, for the answers! I am still on 2.6 since so many
packages rely on it. I got 3.1 at first, but I could not get much to
work with it so I installed 2.6 and have only found one package which
refuses to work, instead of a lot of them.


2.7, now in beta, is aimed at a June release with 3.2 to follow maybe in 
Dec.


I believe the numpy folks are targeting 3.2. That will enable packages 
that depend on numpy to do the same.


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


Python, CGI and Sqlite3

2010-04-13 Thread Majdi Sawalha
Dear list members,

I am writing CGI program that reads a text feild and uses with select statement 
to retrieve data from a database file using sqlite3. the program behaived very 
strange as it does not recognizes the 

import sqlite3

statement? and it gives the following error
ImportError: No module named sqlite3,

i tried it on python shell and all statements are work well.
i tried it also by prining the output to a text file instead using cgi web 
folder, and it worked.

Looking forward to hearing from you.

best regards,

Majdi Sawalha

Faculty of Engineering
School of Computing
University of Leeds
Leeds, LS2 9JT
UK
http://www.comp.leeds.ac.uk/sawalha 


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


Re: Constructing an if statement from the client data in python

2010-04-13 Thread Terry Reedy

On 4/13/2010 11:56 AM, Vishal Rana wrote:

Hi,

I need to construct an if statement from the data coming from the client
as below:

conditions: condition1, condition2, condition3, condition4 logical
operators: lo1, lo2, lo3 (Possible values: "and" "or")

Eg.

|if  condition1 lo1 condition2 lo3 condition4:

 # Do something

|

I can think of eval/exec but not sure how safe they are! Any better
approach or alternative? Appreciate your responses :)

PS: Client-side: Flex, Server-side: Python, over internet


Unless Python on the server is properly sandboxed (not easy), this is 
not safe. Consider 'conditions' like


  1**1
  __import__('subprocess').Popen(['format', 'C:']) # don't test this !!!

I may not have the latter exactly correct but you should get the idea.
So sandboxing requires OS supervision and limitation of time and space 
consumption as well as removal from Python of dangerous builtins and 
modules.


Terry Jan Reedy

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


how to get text from a html file?

2010-04-13 Thread varnikat t
Hi,
Can anyone tell me how to get text from a html file?I am trying to display
the text of an html file in textview(of glade).If i directly display the
file,it shows with html tags and attributes, etc. in textview.I don't want
that.I just want the text.
Can someone help me with this?


Regards
Varnika Tewari
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get text from a html file?

2010-04-13 Thread Chris Colbert
On Tue, Apr 13, 2010 at 1:58 PM, varnikat t  wrote:
>
> Hi,
> Can anyone tell me how to get text from a html file?I am trying to display
> the text of an html file in textview(of glade).If i directly display the
> file,it shows with html tags and attributes, etc. in textview.I don't want
> that.I just want the text.
> Can someone help me with this?
>
>
> Regards
> Varnika Tewari
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>

You should look into beautiful soup

http://www.crummy.com/software/BeautifulSoup/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get text from a html file?

2010-04-13 Thread Grant Edwards
 On Tue, Apr 13, 2010 at 1:58 PM, varnikat t  wrote:

> Can anyone tell me how to get text from a html file?I am trying to display
> the text of an html file in textview(of glade).If i directly display the
> file,it shows with html tags and attributes, etc. in textview.I don't want
> that.I just want the text.

[Parent article is unavailable on gmane, so my reply isn't quite in
the right place in the tree]

I generally just use something like this:

  Popen(['w3m','-dump',filename],stdout=PIPE).stdout.read()

I'm sure there are more complex ways...
  
-- 
Grant Edwards   grant.b.edwardsYow! I'm having fun
  at   HITCHHIKING to CINCINNATI
  gmail.comor FAR ROCKAWAY!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get text from a html file?

2010-04-13 Thread Stefan Behnel

varnikat t, 13.04.2010 19:58:

Can anyone tell me how to get text from a html file?I am trying to display
the text of an html file in textview(of glade).If i directly display the
file,it shows with html tags and attributes, etc. in textview.I don't want
that.I just want the text.
Can someone help me with this?


E.g. using lxml.html:

import lxml.html as H
html = H.parse("the_html_file.html")
print H.tostring(html, method="text")

Stefan

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


Re: HTMLParser can't read japanese

2010-04-13 Thread John Nagle

   Yes.  Try "cmd /u" to get a Unicode console.

   HTMLparser should already have converted from Shift-JIS
to Unicode, so the "print" is outputting Unicode.

John Nagle

Stefan Behnel wrote:

Dodo, 13.04.2010 13:40:

Here's a small script to generate again the error
running windows 7 with python 3.1

FILE : parseShift.py

import urllib.request as url
from html.parser import HTMLParser

class myParser(HTMLParser):
  def handle_starttag(self, tag, attrs):
print("Start of %s tag : %s" % (tag, attrs))


You problem is the last line. Your terminal does not support printing 
the text, so you get an exception here.


Either change your terminal encoding to a suitable encoding, or write 
the text to an encoded file instead (see the 'encoding' option of the 
open() function for that).


Stefan


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


Re: Python, CGI and Sqlite3

2010-04-13 Thread Tim Chase

On 04/13/2010 12:41 PM, Majdi Sawalha wrote:

import sqlite3

statement? and it gives the following error
ImportError: No module named sqlite3,

i tried it on python shell and all statements are work well.


A couple possible things are happening but here are a few that 
pop to mind:


1) you're running different versions of python (sqlite was 
bundled beginning in 2.5, IIRC) so when you run from a shell, you 
get python2.5+ but your CGI finds an older version.  Your CGI can 
dump the value of sys.version which you can compare with your 
shell's version


2) the $PYTHONPATH is different between the two.  Check the 
contents of sys.path in both the shell and the CGI program to see 
if they're the same.  You might also dump the results of 
os.environ.get('PYTHONPATH', None)  to see if an environment 
variable specifies the $PYTHONPATH differently


3) while it reads correctly above, it's theoretically possible 
that you have a spelling error like "import sqllite3"?  I've been 
stung once or twice by this sort of problem so it's not entirely 
impossible :)


-tkc







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


Re: Constructing an if statement from the client data in python

2010-04-13 Thread Vishal Rana
They are bitwise operators!

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


Re: Constructing an if statement from the client data in python

2010-04-13 Thread Vishal Rana
They are bitwise operators!

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


RE: Python, CGI and Sqlite3

2010-04-13 Thread Ahmed, Shakir
-Original Message-
From: python-list-bounces+shahmed=sfwmd@python.org
[mailto:python-list-bounces+shahmed=sfwmd@python.org] On Behalf Of
Tim Chase
Sent: Tuesday, April 13, 2010 2:36 PM
To: Majdi Sawalha
Cc: python-list@python.org
Subject: Re: Python, CGI and Sqlite3

On 04/13/2010 12:41 PM, Majdi Sawalha wrote:
> import sqlite3
>
> statement? and it gives the following error
> ImportError: No module named sqlite3,
>
> i tried it on python shell and all statements are work well.

A couple possible things are happening but here are a few that 
pop to mind:

1) you're running different versions of python (sqlite was 
bundled beginning in 2.5, IIRC) so when you run from a shell, you 
get python2.5+ but your CGI finds an older version.  Your CGI can 
dump the value of sys.version which you can compare with your 
shell's version

2) the $PYTHONPATH is different between the two.  Check the 
contents of sys.path in both the shell and the CGI program to see 
if they're the same.  You might also dump the results of 
os.environ.get('PYTHONPATH', None)  to see if an environment 
variable specifies the $PYTHONPATH differently

3) while it reads correctly above, it's theoretically possible 
that you have a spelling error like "import sqllite3"?  I've been 
stung once or twice by this sort of problem so it's not entirely 
impossible :)

-tkc

Tim is right, following import works fine with me.

import sqlite3 






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

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


RE: Python-list Digest, Vol 79, Issue 108

2010-04-13 Thread angelaeyes
I wish to unsubscribe with immediate effect!!!

From: python-list-requ...@python.org To: python-list@python.org Sent: Tue Apr 
13 17:56:06 SAST 2010 Subject: Python-list Digest, Vol 79, Issue 108 -- 
http://mail.python.org/mailman/listinfo/python-list-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A 'foolproof' way to query inheritance tree? numbers.Real in 2.6)

2010-04-13 Thread Hans Mulder

Steven D'Aprano wrote:


Given a class C, is there some way to find out what classes
issubclass(C, X) will return true for? Obviously you can get a partial 
list, by walking the MRO, but is there a list somewhere of which ABCs 
consider C a subclass?


Presumably the general answer is No, because any class X could happen to 
have a __subclasscheck__ method that returns True when called with C.


New style class method __subclasses__ that returns a list of the immediate
subclasses.  By recursing down from object, you can make a list of all new
style classes in your current interpreter.  Then use issubclass to find
the ones that consider themselves subclasses of C.

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


Re: Constructing an if statement from the client data in python

2010-04-13 Thread Chris Rebert
On Tue, Apr 13, 2010 at 8:56 AM, Vishal Rana  wrote:
> Hi,
>
> I need to construct an if statement from the data coming from the client as
> below:
>
> conditions: condition1, condition2, condition3, condition4 logical
> operators: lo1, lo2, lo3 (Possible values: "and" "or")
>
> Eg.
>
> if condition1 lo1 condition2 lo3 condition4:
>
>     # Do something
>
> I can think of eval/exec but not sure how safe they are! Any better approach
> or alternative? Appreciate your responses :)
>
> PS: Client-side: Flex, Server-side: Python, over internet

Do you literally get a string, or do/could you get the expression in a
more structured format?

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A 'foolproof' way to query inheritance tree? numbers.Real in 2.6)

2010-04-13 Thread Chris Rebert
On Tue, Apr 13, 2010 at 12:15 PM, Hans Mulder  wrote:
> Steven D'Aprano wrote:
>> Given a class C, is there some way to find out what classes
>> issubclass(C, X) will return true for? Obviously you can get a partial
>> list, by walking the MRO, but is there a list somewhere of which ABCs
>> consider C a subclass?
>>
>> Presumably the general answer is No, because any class X could happen to
>> have a __subclasscheck__ method that returns True when called with C.
>
> New style class method __subclasses__ that returns a list of the immediate
> subclasses.  By recursing down from object, you can make a list of all new
> style classes in your current interpreter.  Then use issubclass to find
> the ones that consider themselves subclasses of C.

Being pedantic here, but your last statement is the wrong way around:
C is the one who decides which classes should be considered its
subclasses.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Download Visual Studio Express 2008 now

2010-04-13 Thread Michel Claveau - MVP
Hi!

Thanks for this idea.

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


Re: Constructing an if statement from the client data in python

2010-04-13 Thread Vishal Rana
They are bitwise operators!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: packaging multiple python scripts as Windows exe file

2010-04-13 Thread Mike Driscoll
On Apr 12, 5:20 pm, Alex Hall  wrote:
> Hi all,
> While my project is still suffering from major import problems, I will
> soon have to try to package it as a Windows executable file. I do not
> want an installer; I want the user to be able to run the program for
> as long as they want, then to quit (by using a command from inside the
> program) and that is it. Nothing to install, no files to copy, no
> registry editing, just start and use it until done.
>
> I know about the popular solutions for this sort of thing, but I read
> that a DLL is required, and that this dll cannot be (legally)
> distributed by myself? A few questions here:
> 1. Did I read this wrong / is this outdated? Please answer 'yes' as
> this will be a real pain to deal with.
>
> 2. If I must have it but can distribute it, where should it go so my
> program can find it?
>
> 3. If the user must download it for legal reasons, instead of me
> giving it to them, can I just have a Python script take care of it and
> put it in the same directory as the program, so the program can find
> it, or do I need to register the dll with the system? If I need to
> register, does this require admin login?
>
> Thanks as always!
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com;http://www.facebook.com/mehgcap


Without knowing the exact DLL you're thinking of, we can't be sure
what the answer is. But I think you're talking about a certain MS DLL
that Python distributes. If so, I've read multiple threads on this
topic that claim that since Python distributes it, there is an implied
permission that you can as well. Since I'm not a lawyer, I can't say
for sure, but the articles I've seen are pretty convincing.

---
Mike Driscoll

Blog:   http://blog.pythonlibrary.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Constructing an if statement from the client data in python

2010-04-13 Thread Chris Rebert
> On Tue, Apr 13, 2010 at 12:29 PM, Chris Rebert  wrote:
>> On Tue, Apr 13, 2010 at 8:56 AM, Vishal Rana  wrote:
>> > Hi,
>> >
>> > I need to construct an if statement from the data coming from the client
>> > as
>> > below:
>> >
>> > conditions: condition1, condition2, condition3, condition4 logical
>> > operators: lo1, lo2, lo3 (Possible values: "and" "or")
>> >
>> > Eg.
>> >
>> > if condition1 lo1 condition2 lo3 condition4:
>> >
>> >     # Do something
>> >
>> > I can think of eval/exec but not sure how safe they are! Any better
>> > approach
>> > or alternative? Appreciate your responses :)
>> >
>> > PS: Client-side: Flex, Server-side: Python, over internet
>>
>> Do you literally get a string, or do/could you get the expression in a
>> more structured format?

On Tue, Apr 13, 2010 at 12:46 PM, Vishal Rana  wrote:
> Its a form at the client side where you can construct a query
> using different conditions and logical operators.
> I can take it in any format!, currently it comes as a parameters to an RPC.

Well, then if possible, I'd have the form send it back in a Lisp-like
format and run it through a simple evaluator:

def and_(conds, context):
for cond in conds:
if not evaluate(cond, context):
return False
return True

def or_(conds, context):
for cond in conds:
if evaluate(cond, context):
return True
return False

def greater_than(pair, context):
left, right = [context[name] for name in pair]
return left > right

OPNAME2FUNC = {"and" : and_, "or" : or_, ">" : greater_than}

def evaluate(expr, context):
op_name, operands = expr[0], expr[1:]
return OPNAME2FUNC[op_name](operands, context)

expression = ["and", [">", "x", "y"], ["or", [">", "y", "z"], [">", "x", "z"]]]
variables = {"x" : 7, "y" : 3, "z" : 5}
print evaluate(expression, variables)

If it's just ands and ors of bare variables (no '>' or analogous
operations), the code can be simplified a bit.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Constructing an if statement from the client data in python

2010-04-13 Thread Vishal Rana
Thanks Chris

On Tue, Apr 13, 2010 at 1:08 PM, Chris Rebert  wrote:

> > On Tue, Apr 13, 2010 at 12:29 PM, Chris Rebert 
> wrote:
> >> On Tue, Apr 13, 2010 at 8:56 AM, Vishal Rana 
> wrote:
> >> > Hi,
> >> >
> >> > I need to construct an if statement from the data coming from the
> client
> >> > as
> >> > below:
> >> >
> >> > conditions: condition1, condition2, condition3, condition4 logical
> >> > operators: lo1, lo2, lo3 (Possible values: "and" "or")
> >> >
> >> > Eg.
> >> >
> >> > if condition1 lo1 condition2 lo3 condition4:
> >> >
> >> > # Do something
> >> >
> >> > I can think of eval/exec but not sure how safe they are! Any better
> >> > approach
> >> > or alternative? Appreciate your responses :)
> >> >
> >> > PS: Client-side: Flex, Server-side: Python, over internet
> >>
> >> Do you literally get a string, or do/could you get the expression in a
> >> more structured format?
>
> On Tue, Apr 13, 2010 at 12:46 PM, Vishal Rana 
> wrote:
> > Its a form at the client side where you can construct a query
> > using different conditions and logical operators.
> > I can take it in any format!, currently it comes as a parameters to an
> RPC.
>
> Well, then if possible, I'd have the form send it back in a Lisp-like
> format and run it through a simple evaluator:
>
> def and_(conds, context):
>for cond in conds:
>if not evaluate(cond, context):
>return False
>return True
>
> def or_(conds, context):
>for cond in conds:
>if evaluate(cond, context):
>return True
>return False
>
> def greater_than(pair, context):
>left, right = [context[name] for name in pair]
>return left > right
>
> OPNAME2FUNC = {"and" : and_, "or" : or_, ">" : greater_than}
>
> def evaluate(expr, context):
>op_name, operands = expr[0], expr[1:]
>return OPNAME2FUNC[op_name](operands, context)
>
> expression = ["and", [">", "x", "y"], ["or", [">", "y", "z"], [">", "x",
> "z"]]]
> variables = {"x" : 7, "y" : 3, "z" : 5}
> print evaluate(expression, variables)
>
> If it's just ands and ors of bare variables (no '>' or analogous
> operations), the code can be simplified a bit.
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Compiling Python extension modules in the near future, was: Re: Download Visual Studio Express 2008 now

2010-04-13 Thread Irmen de Jong

On 12-4-2010 22:36, Martin v. Loewis wrote:


If you are planning to build Python extension modules in the next five
years, I recommend that you obtain a copy of VS Express, just in case
Microsoft removes it from their servers.


Thanks for the idea Martin. However I've changed the post title a little because at 
first I skipped this post because I thought that it was product spam ;-)


Irmen de Jong.

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


Re: packaging multiple python scripts as Windows exe file

2010-04-13 Thread Joaquin Abian
On Apr 13, 9:56 pm, Mike Driscoll  wrote:
> On Apr 12, 5:20 pm, Alex Hall  wrote:
>
>
>
> > Hi all,
> > While my project is still suffering from major import problems, I will
> > soon have to try to package it as a Windows executable file. I do not
> > want an installer; I want the user to be able to run the program for
> > as long as they want, then to quit (by using a command from inside the
> > program) and that is it. Nothing to install, no files to copy, no
> > registry editing, just start and use it until done.
>
> > I know about the popular solutions for this sort of thing, but I read
> > that a DLL is required, and that this dll cannot be (legally)
> > distributed by myself? A few questions here:
> > 1. Did I read this wrong / is this outdated? Please answer 'yes' as
> > this will be a real pain to deal with.
>
> > 2. If I must have it but can distribute it, where should it go so my
> > program can find it?
>
> > 3. If the user must download it for legal reasons, instead of me
> > giving it to them, can I just have a Python script take care of it and
> > put it in the same directory as the program, so the program can find
> > it, or do I need to register the dll with the system? If I need to
> > register, does this require admin login?
>
> > Thanks as always!
>
> > --
> > Have a great day,
> > Alex (msg sent from GMail website)
> > mehg...@gmail.com;http://www.facebook.com/mehgcap
>
> Without knowing the exact DLL you're thinking of, we can't be sure
> what the answer is. But I think you're talking about a certain MS DLL
> that Python distributes. If so, I've read multiple threads on this
> topic that claim that since Python distributes it, there is an implied
> permission that you can as well. Since I'm not a lawyer, I can't say
> for sure, but the articles I've seen are pretty convincing.
>
> ---
> Mike Driscoll
>
> Blog:  http://blog.pythonlibrary.org

the OP probably means MSVCR71.dll that is needed to make single file
executables with py2exe.
This has been discussed elsewhere. Look at 
http://www.py2exe.org/index.cgi/Tutorial#Step5

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


Creating a standalone application

2010-04-13 Thread Luis Quesada

Dear all,
I am getting an "expected string without null bytes" error when using 
cxfreeze for creating a standalone application (in Linux-Ubuntu). None 
of my files has null bytes. I also tried pyinstaller but I got the error 
 attached at the end.
My program runs fine when executed from eclipse.  What is the easiest 
way of creating a standalone application? Is there a way of creating the 
executable file from eclipse/pydev?

Cheers,
Luis



cxfreeze's output
lques...@lquesada-laptop:~/workspace/MetroNode/src/models$ cxfreeze 
uncovered.py --target-dir dist
copying /usr/lib/pymodules/python2.6/cx_Freeze/bases/Console -> 
dist/uncovered

copying /usr/lib/libpython2.6.so.1.0 -> dist/libpython2.6.so.1.0
Traceback (most recent call last):
  File "/usr/bin/cxfreeze", line 5, in 
main()
  File "/usr/lib/pymodules/python2.6/cx_Freeze/main.py", line 170, in main
freezer.Freeze()
  File "/usr/lib/pymodules/python2.6/cx_Freeze/freezer.py", line 405, 
in Freeze

self._FreezeExecutable(executable)
  File "/usr/lib/pymodules/python2.6/cx_Freeze/freezer.py", line 173, 
in _FreezeExecutable

exe.copyDependentFiles, scriptModule)
  File "/usr/lib/pymodules/python2.6/cx_Freeze/freezer.py", line 333, 
in _WriteModules

initModule = finder.IncludeFile(initScript, "cx_Freeze__init__")
  File "/usr/lib/pymodules/python2.6/cx_Freeze/finder.py", line 386, in 
IncludeFile

deferredImports)
  File "/usr/lib/pymodules/python2.6/cx_Freeze/finder.py", line 259, in 
_LoadModule

module.code = compile(fp.read() + "\n", path, "exec")
TypeError: compile() expected string without null bytes
lques...@lquesada-laptop:~/workspace/MetroNode/src/models$

==
pyinstaller's output

lques...@lquesada-laptop:~/workspace/MetroNode/src/models$ python 
~/pyinstaller-1.4/Build.py uncovered.spec

checking Analysis
building Analysis because outAnalysis0.toc non existent
running Analysis outAnalysis0.toc
Analyzing: /home/lquesada/pyinstaller-1.4/support/_mountzlib.py
Analyzing: /home/lquesada/pyinstaller-1.4/support/useUnicode.py
Analyzing: uncovered.py
ldd: 
/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_conflict.so: 
No such file or directory
ldd: 
/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_nodesel.so: 
No such file or directory
ldd: 
/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_vars.so: 
No such file or directory
ldd: 
/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_heur.so: 
No such file or directory
ldd: 
/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_branch.so: 
No such file or directory
ldd: 
/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_sepa.so: 
No such file or directory
ldd: 
/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_prop.so: 
No such file or directory
ldd: 
/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_presol.so: 
No such file or directory
ldd: 
/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_soln.so: 
No such file or directory
ldd: 
/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_cons.so: 
No such file or directory
ldd: 
/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_scip.so: 
No such file or directory
Warnings written to 
/home/lquesada/workspace/MetroNode/src/models/warnuncovered.txt

checking PYZ
rebuilding outPYZ1.toc because outPYZ1.pyz is missing
building PYZ outPYZ1.toc
checking PKG
rebuilding outPKG3.toc because outPKG3.pkg is missing
building PKG outPKG3.pkg
Cannot find ('zibopt._conflict.so', 
'/usr/local/lib/python2.6/dist-packages/python_zibopt-0.5.beta_r97-py2.6-linux-i686.egg/zibopt/_conflict.so', 
1, 'b')

Traceback (most recent call last):
  File "/home/lquesada/pyinstaller-1.4/Build.py", line 1160, in 
main(args[0], configfilename=opts.configfile)
  File "/home/lquesada/pyinstaller-1.4/Build.py", line 1148, in main
build(specfile)
  File "/home/lquesada/pyinstaller-1.4/Build.py", line , in build
execfile(spec)
  File "uncovered.spec", line 14, in 
console=1 )
  File "/home/lquesada/pyinstaller-1.4/Build.py", line 661, in __init__
strip_binaries=self.strip, upx_binaries=self.upx, crypt=self.crypt)
  File "/home/lquesada/pyinstaller-1.4/Build.py", line 561, in __init__
self.__postinit__()
  File "/home/lquesada/pyinstaller-1.4/Build.py", line 196, in __postinit__
self.assemble()
  File "/home/lquesada/pyinstaller-1.4/Build.py", line 618, in assemble
archive.build(self.name, mytoc)
  File "/home/lquesada/pyinstaller-1.4/archive.py", line 229, in build
self.add(tocent

Re: Creating a standalone application

2010-04-13 Thread Lawrence D'Oliveiro
In message , Luis Quesada wrote:

> I am getting an "expected string without null bytes" error when using
> cxfreeze for creating a standalone application (in Linux-Ubuntu).

Why bother? Every decent Linux system will have Python available. Why not 
just distribute it as a script?
-- 
http://mail.python.org/mailman/listinfo/python-list


mailbox multipart

2010-04-13 Thread janwillem
I am trying to analyze mailboxes using an iterator:
for key, message in mbox.iteritems():

When message is a simple mail message['date']  results the date.
When, however, it is a multipart message this results in None. How can
you full proof get the "date", "from" and "to" of of a multipart mail
using python?
Thanks janwillem

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


when should I explicitely close a file?

2010-04-13 Thread gelonida
Hi,


I've been told, that following code snippet is not good.


open("myfile","w").write(astring) , because I'm neither explicitely
closing nor using the new 'with' syntax.

What exactly is the impact of not closing the file explicitely
(implicitley with a 'with' block)?


Even with my example
I'd expected to get an exception raised if not all data could have
been written.

I'd also expected, that all write data is flushed as soon as the
filehandle is out of scope (meaning in the next line of my source
code).


Thanks for explaining me exactly what kind of evil I could encounter
with not explicitely closing.

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


Re: Creating a standalone application

2010-04-13 Thread Luis Quesada

Lawrence D'Oliveiro wrote:

In message , Luis Quesada wrote:


I am getting an "expected string without null bytes" error when using
cxfreeze for creating a standalone application (in Linux-Ubuntu).


Why bother? Every decent Linux system will have Python available. Why not 
just distribute it as a script?


Well every decent Linux system will have Java available too but it is 
still preferable to distribute jar files. The point is that I don't want 
 to force my users to install all the packages that I had to install.

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


Re: when should I explicitely close a file?

2010-04-13 Thread Chris Rebert
On Tue, Apr 13, 2010 at 3:01 PM, gelonida  wrote:
> Hi,
>
> I've been told, that following code snippet is not good.
>
> open("myfile","w").write(astring) , because I'm neither explicitely
> closing nor using the new 'with' syntax.
>
> What exactly is the impact of not closing the file explicitely
> (implicitley with a 'with' block)?
>
> Even with my example
> I'd expected to get an exception raised if not all data could have
> been written.
>
> I'd also expected, that all write data is flushed as soon as the
> filehandle is out of scope (meaning in the next line of my source
> code).

That extremely-quick responsiveness of the garbage-collection
machinery is only guaranteed by CPython, not the language
specification itself, and indeed some of the other implementations
*explicitly don't* make that guarantee (and hence the data may not get
flushed in a timely manner on those implementations). And portability
of code is encouraged, hence the admonishment you encountered.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: when should I explicitely close a file?

2010-04-13 Thread Steven D'Aprano
On Tue, 13 Apr 2010 15:01:25 -0700, gelonida wrote:

> Hi,
> 
> 
> I've been told, that following code snippet is not good.
> 
> 
> open("myfile","w").write(astring) , because I'm neither explicitely
> closing nor using the new 'with' syntax.
> 
> What exactly is the impact of not closing the file explicitely
> (implicitley with a 'with' block)?


Your data may not be actually written to disk until the file closes. If 
you have a reference loop, and Python crashes badly enough, the garbage 
collector may never run and the file will never be closed, hence you will 
get data loss.

If you are running something other than CPython (e.g. IronPython or 
Jython) then the file might not be closed until your program exits. If 
you have a long-running program that opens many, many files, it is 
possible for you to run out of system file handles and be unable to open 
any more.

Best practice is to explicitly close the file when you are done with it, 
but for short scripts, I generally don't bother. Laziness is a virtue :)

But for library code and larger applications, I always explicitly close 
the file, because I want to control exactly when the file is closed 
rather than leave it up to the interpreter. I don't know if my code might 
one day end up in a long-running Jython application so I try to code 
defensively and avoid even the possibility of a problem.


> Even with my example
> I'd expected to get an exception raised if not all data could have been
> written.

Generally if you get an exception while trying to *close* a file, you're 
pretty much stuffed. What are you going to do? How do you recover?

My feeling is that you're probably safe with something as simple as 

file("myfile", "w").write("my data\n")

but if you do something like

some_data_structure.filehandle = file("myfile", "w")
some_data_structure.filehandle.write("my data\n")
# ... lots more code here

and some_data_structure keeps the file open until the interpreter shuts 
down, there *might* be rare circumstances where you won't be notified of 
an exception, depending on the exact circumstances of timing of when the 
file gets closed. In the worst case, the file might not be closed until 
the interpreter is shutting down *and* has already dismantled the 
exception infrastructure, and so you can't get an exception. I don't know 
enough about the Python runtime (particularly about how it works during 
shutdown) to know how real this danger is, but if it is a danger, I bet 
it involves __del__ methods.



> I'd also expected, that all write data is flushed as soon as the
> filehandle is out of scope (meaning in the next line of my source code).

This is only guaranteed with CPython, not other implementations.

My feeling is that explicit closing is pedantic and careful, implicit 
closing is lazy and easy. You make your choice and take your chance :)




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


Re: how to get text from a html file?

2010-04-13 Thread rake
On Apr 13, 2:12 pm, Chris Colbert  wrote:
> On Tue, Apr 13, 2010 at 1:58 PM, varnikat t  wrote:
>
> > Hi,
> > Can anyone tell me how to get text from a html file?I am trying to display
> > the text of an html file in textview(of glade).If i directly display the
> > file,it shows with html tags and attributes, etc. in textview.I don't want
> > that.I just want the text.
> > Can someone help me with this?
>
> > Regards
> > Varnika Tewari
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> You should look into beautiful soup
>
> http://www.crummy.com/software/BeautifulSoup/

For more complex parsing beautiful soup is definitely the way to go.

However, if all you want to do is strip the html and keep all
remaining text I'd recommend pyparsing package with this short script:

http://pyparsing.wikispaces.com/file/view/htmlStripper.py
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: when should I explicitely close a file?

2010-04-13 Thread Giampaolo Rodola'
What about open('foo', 'w').close().
Does it have the same problems?


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: when should I explicitely close a file?

2010-04-13 Thread Chris Rebert
On Tue, Apr 13, 2010 at 5:45 PM, Giampaolo Rodola'  wrote:
> What about open('foo', 'w').close().
> Does it have the same problems?

Well, no, but that's only because it's a pointless no-op that doesn't
really do anything besides possibly throwing an exception (e.g. if the
script didn't have write access to the current directory).

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: when should I explicitely close a file?

2010-04-13 Thread Dave Angel

gelonida wrote:

Hi,


I've been told, that following code snippet is not good.


open("myfile","w").write(astring) , because I'm neither explicitely
closing nor using the new 'with' syntax.

What exactly is the impact of not closing the file explicitely
(implicitley with a 'with' block)?


Even with my example
I'd expected to get an exception raised if not all data could have
been written.

I'd also expected, that all write data is flushed as soon as the
filehandle is out of scope (meaning in the next line of my source
code).


Thanks for explaining me exactly what kind of evil I could encounter
with not explicitely closing.


  

Evil?  No.  Just undefined behavior.

The language does NOT guarantee that a close or even a flush will occur 
when an object "goes out of scope."  This is the same in Python as it is 
in Java.  There's also no exception for data not being flushed.


In one particular implementation of Python, called CPython, there are 
some things that tend to help.  So if you're sure you're always going to 
be using this particular implementation, and understand what the 
restrictions are, then go ahead and be sloppy.  Similarly, on some OS 
systems, files are flushed when a process ends.  So if you know your 
application is only going to run on those environments, you might not 
bother closing files at the end of execution.


It all depends on how restrictive your execution environment is going to be.

DaveA

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


Re: when should I explicitely close a file?

2010-04-13 Thread Ryan Kelly
On Tue, 2010-04-13 at 18:19 -0700, Chris Rebert wrote:
> On Tue, Apr 13, 2010 at 5:45 PM, Giampaolo Rodola'  wrote:
> > What about open('foo', 'w').close().
> > Does it have the same problems?
> 
> Well, no, but that's only because it's a pointless no-op that doesn't
> really do anything besides possibly throwing an exception (e.g. if the
> script didn't have write access to the current directory).

Actually, it will create the file if it doesn't exist, and truncate it
to zero length if it does.


  Ryan


-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details


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


Re: Creating a standalone application

2010-04-13 Thread Gabriel Genellina
En Tue, 13 Apr 2010 18:02:07 -0300, Luis Quesada   
escribió:


I am getting an "expected string without null bytes" error when using  
cxfreeze for creating a standalone application (in Linux-Ubuntu). None  
of my files has null bytes.


Are you sure? A text file saved as, e.g., UTF-16, does contain null bytes.


cxfreeze's output
...
   File "/usr/lib/pymodules/python2.6/cx_Freeze/finder.py", line 386, in  
IncludeFile

 deferredImports)
   File "/usr/lib/pymodules/python2.6/cx_Freeze/finder.py", line 259, in  
_LoadModule

 module.code = compile(fp.read() + "\n", path, "exec")
TypeError: compile() expected string without null bytes


I would add a few 'print' statements in finder.py to determine which file  
is failing.


--
Gabriel Genellina

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


Does Abstract class , interfaces there in python ?

2010-04-13 Thread gopi krishna
Hi ,
 I want to know whether there is an abstract class and interfaces in python.
If so how to implement it..
Pls help me on this.
Thanks
Gopi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Abstract class , interfaces there in python ?

2010-04-13 Thread Chris Rebert
On Tue, Apr 13, 2010 at 10:57 PM, gopi krishna
 wrote:
> Hi ,
>  I want to know whether there is an abstract class and interfaces in python.

Sort of: http://docs.python.org/library/abc.html

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mailbox multipart

2010-04-13 Thread Tim Roberts
janwillem  wrote:
>
>I am trying to analyze mailboxes using an iterator:
>for key, message in mbox.iteritems():
>
>When message is a simple mail message['date']  results the date.
>When, however, it is a multipart message this results in None. How can
>you full proof get the "date", "from" and "to" of of a multipart mail
>using python?

Perhaps you should post your code.  There's no particular reason why you
should see this.  The mailbox iterator should return the outer multipart
container, which has the headers.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get text from a html file?

2010-04-13 Thread Stefan Behnel

rake, 14.04.2010 02:45:

On Apr 13, 2:12 pm, Chris Colbert wrote:

You should look into beautiful soup

http://www.crummy.com/software/BeautifulSoup/


For more complex parsing beautiful soup is definitely the way to go.


Why would a library that even the author has lost interest in be "the way 
to go"?


Stefan

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