Clone Digger: the tool for finding software clones; Google Summer of Code 2008 participant

2008-03-24 Thread Peter Bulychev
Hello

I'm happy to announce the first release of Clone Digger tool (1.0-beta).

Some background on software clones
==
Two continuous fragments of code form clone if they are similar enough.
The presence of clones can greatly increase the software maintenance
cost. For instance, every error in the original have to be fixed in
all copies.

What is it
==
Clone Digger is the tool for finding software clones (duplicate code)
in programs.
Currently Python language is supported, Java support will be added later.
The following definition of clone is used: two sequences of statements
form clone if one of it can be obtained from the other by replacing some
subtrees of its abstract syntax tree by other subtrees.
Found clone candidates are reported to the HTML with a highlighting of
differences.
This report can be used to form recommendations for refactoring.

License
==
Clone Digger is provided under the GPL license.

Links
==
Project site: http://clonedigger.sourceforge.net
Download: http://clonedigger.sourceforge.net/download.html
Clone Digger was tested on Python 2.4 and 2.5.

To my knowledge Clone Digger is the first tool that finds software
clones in Python sources (excluding tools working on the pure text
level). I hope that Clone Digger will be very useful for the Python
community.

p.s.
Clone Digger participates in the Google Summer of Code 2008 program. I
am looking for a student willing to work on code analysis and
refactoring. The project ideas are listed here:
http://clonedigger.sourceforge.net/google_summer_of_code.html

PA HREF=http://clonedigger.sourceforge.net;Clone Digger
1.0-beta/A - the tool for finding software clones in Python
programs.  (23-March-2008) /P

-- 
Best regards,
   Peter Bulychev.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Update release 0.1.1 of Evoque Templating

2008-03-24 Thread mario ruggier
Version 0.1.1 of Evoque is now available.

This is mostly a bug-fix release. See complete change log from:
http://evoque.gizmojo.org/download/

Other than fixes, it may be worthwhile to mention the addition of a 
recipe for using Evoque Templating with Django, see:
http://evoque.gizmojo.org/ext/django/

What is Evoque Templating?
In addition to legitimately contending to being the fastest pure-python 
text templating engine (see benchmark) Evoque is a full-featured and 
framework-independent templating system for python with some important 
features not offered by other systems, such as automatic input quoting 
and guaranteed XSS protection, restricted template execution mode to be 
able to expose your templates to untrusted editors, processing is 
always and only done in unicode, etc (see features). Evoque weighs in 
under 1K source lines of code, and is licensed under the Academic Free 
License version 3.0.
[benchmark] http://evoque.gizmojo.org/benchmark/
[features] http://evoque.gizmojo.org/features/
[home] http://evoque.gizmojo.org/

Best regards, mario

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Multiline CSV export to Excel produces unrecognized characters?

2008-03-24 Thread felciano
Hi --

Is there a standard way to use the csv module to export data that
contains multi-line values to Excel? I can get it mostly working, but
Excel seems to have difficulty displaying the generated multi-line
cells.

The following reproduces the problem in python 2.5:

import csv
row = [1,hello,this is\na multiline\ntext field]
writer = csv.writer(open(test.tsv, w), dialect=excel-tab,
quotechar='')
writer.writerow(row)

When opening the resulting test.tsv file, I do indeed see a cell with
a multi-line value, but there is a small boxed question mark at the
end of each of the lines, as if Excel didn't recognize the linebreak.

Any idea why these are there or how to get rid of them?

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


Re: Multiline CSV export to Excel produces unrecognized characters?

2008-03-24 Thread Marc 'BlackJack' Rintsch
On Sun, 23 Mar 2008 23:30:11 -0700, felciano wrote:

 The following reproduces the problem in python 2.5:
 
 import csv
 row = [1,hello,this is\na multiline\ntext field]
 writer = csv.writer(open(test.tsv, w), dialect=excel-tab,
 quotechar='')
 writer.writerow(row)
 
 When opening the resulting test.tsv file, I do indeed see a cell with
 a multi-line value, but there is a small boxed question mark at the
 end of each of the lines, as if Excel didn't recognize the linebreak.
 
 Any idea why these are there or how to get rid of them?

Any chance you are doing this on Windows and Excel doesn't like the
return+linefeed line endings that Windows produces when writing files in
text mode?  Try 'wb' as mode for the output file.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: encoding/decoding issue with python2.5 and pymssql

2008-03-24 Thread Tzury Bar Yochay
These are not cutpaste but typed by hand, yet they are identical to
the actual output.
seems like the first 8 bytes are swapped while the other half is
straightforward.

I deeply thank you for your assistance.

I am currently using a combination of reversed and list comprehension
to rebuild this byte array.


On Mar 24, 8:48 am, Dennis Lee Bieber [EMAIL PROTECTED] wrote:
 On Sun, 23 Mar 2008 22:33:58 -0700 (PDT), Tzury Bar Yochay
 [EMAIL PROTECTED] declaimed the following in comp.lang.python:

  for example:
  the value
  'EE604EE3-4AB0-4EE7-AF4D-018124393CD7'
  is represent as
  '\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9\xd7'

         Are those direct cutpaste?

  .join([%2.2X % ord(x) for x in 
  '\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9\xd7'])

 'E34E60EEB04AE74EAF4D018124393CD7'

 or, putting in -

 'E34E60EE-B04A-E74E-AF4D-018124393CD7'

         The last half is a direct match... the front half looks to have some
 byte-swapping

 E34E60EE = (swap shorts)    60EEE34E
 60EEE34E = (swap bytes)     EE604EE3                

 B04A = 4AB0         

 E74E = 4EE7         

         Anything 
 onhttp://www.sqljunkies.com/Article/4067A1B1-C31C-4EAF-86C3-80513451FC0...
 of any help (besides the facet of using a GUID to ID the page describing
 GUIDs G)

 --
         Wulfraed        Dennis Lee Bieber               KD6MOG
         [EMAIL PROTECTED]             [EMAIL PROTECTED]
                 HTTP://wlfraed.home.netcom.com/
         (Bestiaria Support Staff:               [EMAIL PROTECTED])
                 HTTP://www.bestiaria.com/

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


Re: Does python hate cathy?

2008-03-24 Thread Terry Reedy

QS [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

From the title, I assumed this was spam like others with similar titles --
and that the perl newsgroup, for instance, would have 'Does perl hate 
cathy?

| I am new to python, and I encountered a weird problem.

Observation: as you will learn, the form of the error message was different 
from the standard tracebacks one gets during program execution.  This was a 
clue that it was a cleanup message and actually did make sense.

Summary lessons.

1. What a Python interpreter does after it executes the last statement is 
undefined by the language spec.  It could do absolutely nothing (and I wish 
some programs that wastefully spend minutes 'cleaning up' did just that!). 
CPython tries to do some cleanup when requested but the results are 
sometimes seemingly arbitrary.

2. If you use __del__, do so for a reason (and keeping a population count 
is one, though rare*), and explicitly delete the objects for which you want 
dependable behavior.

*A population count is a good example of a class attribute.  But it seems 
to be rare in practice because if one wants that, it seems that a 
population collection (with a len() method) is usually also wanted --  
perhaps so one can iterate thru the population.

3. Experimenting with Python is a good way to learn.  Keep it up!

tjr



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


Re: Why I hate lambdas (Re: Do any of you recommend Python as afirst programming language?)

2008-03-24 Thread Terry Reedy

Steven D'Aprano [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| Unfortunately there's nothing we can do to fix that error. Even though
| the function object has an attribute __name__ (also known as
| func_name) which is set to spam, it isn't used for tracebacks. Instead,
| the label comes from a read-only attribute buried deep in the function
| object:
|
|  tasty_stuff.func_code.co_name = 'yummy meat-like product in a can'
| Traceback (most recent call last):
|  File stdin, line 1, in module
| TypeError: readonly attribute

The fact that .func_name (which is writeable) is not used at first 
surprised me until I remembered that code objects can potentially be used 
by multiple function objects and hence are not connected to any one in 
particular.

| This is a mistake, in my opinion. It's an arbitrary decision to make this
| read-only (as far as I can tell), which goes against the grain of
| Python's we're all consenting adults here philosophy.
|
| By the way, in case you're thinking that wanting to change the (so-
| called) name of a function is a silly think to do, not at all. Consider
| factory functions:
|
| def factory(how_much):
|def f(n=1):
|for i in range(n):
|print I love spam a %s % how_much
|return f
|
| Every function created by the factory has the same name, no matter what
| name you actually use to refer to it. factory('little') and
| factory('lot') both uselessly identify themselves as f in tracebacks.

workaround:
 ftext = 'def %s(): pass'
 exec ftext%'ftest'
 ftest
function ftest at 0x00C01070

so:
def factory(how_much):
'param how_much MUST be a legal name'
exec '''def %(how_much)s(n=1):
for i in range(n):
print I love spam a %(how_much)s''' % {'how_much': how_much}
return locals()[how_much]

f2=factory('much')
print f2.func_name

prints 'much'
But certainly setting .co_name directly would be easier

Terry Jan Reedy



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


problem with harvestman on ubuntu7.10 gusty

2008-03-24 Thread gags
Hi there

I just saw that program on the awards and wanted to use it as
i installed it on ubuntu gusty gibbon it worked fine without errors
and when i  run it i get the following errors


 File /usr/bin/harvestman, line 364, in module
   spider.run_projects()

 File /usr/bin/harvestman, line 283, in run_projects
   self.register_common_objects()

 File /usr/bin/harvestman, line 135, in register_common_objects
   conn = connector.HarvestManNetworkConnector()

 File /usr/share/pycentral/harvestman/site-packages/HarvestMan/
connector.py, line 201, in _init_
   self.__configure()

 File /usr/share/pycentral/harvestman/site-packages/HarvestMan/
connector.py, line 326, in __configure
   self.__configure_protocols()

 File /usr/share/pycentral/harvestman/site-packages/HarvestMan/
connector.py, line 449, in __configure_protocols
   cookiehandler)

 File /usr/lib/python2.5/urllib2.py, line 467, in build_opener
   opener.add_handler(h)

 File /usr/lib/python2.5/urllib2.py, line 303, in add_handler
   type(handler))
TypeError: expected BaseHandler instance, got type 'NoneType'


regards
puneet brar
9815665000
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: On copying arrays

2008-03-24 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

 Is there a conceptual difference between
 best =test[:]
 and
best = [x for x in test] ?
 test is a list of real numbers. Had to use the second form to avoid a
 nasty bug
 in a program I am writing. I have to add too that I was using psyco
 in Python 2.5.1.
 
The first one will only copy sliceable sequences and will give you a result 
of the same type as test (e.g. if test is a tuple so is best).

The second one will copy any sequence, always results in a list and as a 
side effect assigns a value to 'x'.

The method usually recommended is:

  best = list(test)

as it has no side effects, copies any sequence and may be faster than the 
list comprehension. As with the second of your examples it always gives you 
a list.
-- 
http://mail.python.org/mailman/listinfo/python-list


problems with harvestman on ubuntu 7.10 gusty gibbon

2008-03-24 Thread puneetbrar
Hi there
 
I just saw that program on the awards and wanted to use it as
i installed it on ubuntu gusty gibbon it worked fine without errors
and when i  run it i get the following errors
 

 File /usr/bin/harvestman, line 364, in module
   spider.run_projects()
 
 File /usr/bin/harvestman, line 283, in run_projects
   self.register_common_objects()
 
 File /usr/bin/harvestman, line 135, in register_common_objects
   conn = connector.HarvestManNetworkConnector()
 
 File
/usr/share/pycentral/harvestman/site-packages/HarvestMan/connector.py,
line 201, in _init_
   self.__configure()
 
 File
/usr/share/pycentral/harvestman/site-packages/HarvestMan/connector.py,
line 326, in __configure
   self.__configure_protocols()
 
 File
/usr/share/pycentral/harvestman/site-packages/HarvestMan/connector.py,
line 449, in __configure_protocols
   cookiehandler)
 
 File /usr/lib/python2.5/urllib2.py, line 467, in build_opener
   opener.add_handler(h)
 
 File /usr/lib/python2.5/urllib2.py, line 303, in add_handler
   type(handler))
TypeError: expected BaseHandler instance, got type 'NoneType'


regards
puneet brar


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


Re: always getting 'None' return value from PyObject_CallObject

2008-03-24 Thread Gal Aviel
problem fixed ...
my bad.
I was using a dispatch mechanism where the C code always called the same python
dispatch function, with the actual function name to invoke as arguments.
Anyway, I forgot the 'return' statement.
The code is below.
Many thanks and apologies for the help provided :)

def dispatch(*args):
#print Dispatch: args are 
#print args[1:]
global_dict = globals()
return global_dict[args[0]](args[1:])


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


Shortcutting the function call stack

2008-03-24 Thread Julien
Hello all,

I would like to do something like:

def called(arg)
if arg==True:
!!magic!!caller.return 1

def caller(arg)
called(arg)
return 2

Here, the fake !!!magic!!! represents a statement (which I ignore)
that would make the caller function return a value different from what
it'd return normally.

For example, caller(True) would return 1, and caller(False) would
return 2. The reason I want that is because I don't want the caller
function to know what's going on in the called function, and be
shortcut if the called function think it's necessary.

Would you know if that's possible, and if so, how?

I've done a bit of research and I think I've found some good pointers,
in particular using the 'inspect' library:

import inspect

def called(arg)
if arg==True:
caller_frame = inspect.stack()[1]
...

Here 'caller_frame' contains the frame of the caller function. Now,
how can I make that frame return a particular value?

By the way, I'm not really interested in 'called' throwing an
exception and 'caller' catching it. In fact, I want things to remain
completely transparent for 'caller'.

Hope that was clear... :/

Thanks!

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


Installing Mutagen Package On Windows

2008-03-24 Thread Benjamin Serrato
Hey, I've run into another problem. I am trying to install the Mutagen 
package to use as my first useful program, but can't figure out how to 
install it on windows. The README says it is a simple application of--

Installing
--
  $ ./setup.py build
  $ su -c ./setup.py install

--but I ran c:\python c:\python25\tools\scripts\setup.py build and did 
similarly for setup.py. I also added c:\python25 and 
c:\python25\tools\scripts to my path, but this hasn't worked. I have 
heard of 'easy_install' but don't know how to run easy_install. So, I 
ask for a reference because Google did not give me a quick answer and 
the python.org explanation at PEP 250 doesn't really explain what I 
should do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyparsing help

2008-03-24 Thread Francesco Bochicchio
Il Sat, 22 Mar 2008 14:11:16 -0700, rh0dium ha scritto:

 Hi all,
 
 I am struggling with parsing the following data:
 
 test1 = 
 Technology  {
 name= gtc dielectric  
= 2.75e-05 unitTimeName  
  = ns timePrecision   = 1000
 unitLengthName  = micron
 lengthPrecision = 1000 gridResolution   
   = 5
 unitVoltageName = v voltagePrecision  
  = 100 unitCurrentName =
 ma currentPrecision= 1000
 unitPowerName   = pw powerPrecision   
   = 1000 unitResistanceName  =
 kohm resistancePrecision = 1000
 unitCapacitanceName = pf
 capacitancePrecision= 1000
 unitInductanceName  = nh
 inductancePrecision = 100
 }
 
 Tileunit {
 width   = 0.22 height   
   = 1.69
 }
 


Did you think of using something a bit more sofisticated than pyparsing?
I have had a good experience to using ply, a pure-python implementation
of yacc/lex tools, which I used to extract significant data from C 
programs to automatize documentation.

I never used before yacc or similar tools, but having a bit of experience 
with BNF notation, I found ply easy enough. In my case, the major problem 
was to cope with yacc limitation in describing C syntax (which I solved 
by oelaxing the rules a bit, since I was going to process only already-
compiled C code). In your much simpler case, I'd say that a few 
production rules should be enough.

P.S : there are others, faster and maybe more complete python parser, but 
as I said ply is pure python: no external libraries and runs everywhere.

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


hi friends........... google group invites you a won dering world of businesss ............. do u want to earn mil lions of dollers per month through online jobs joined with me and find the way to ea

2008-03-24 Thread bright
  hi friends... google group invites you a wondering world of
businesss . do u want to earn millions of dollers per
month through online jobs joined with me and find the way to earn
dollers. visit us www.jobsforyouguys.blogspot.co­m
-- 
http://mail.python.org/mailman/listinfo/python-list


Disable resize button

2008-03-24 Thread myonov
Hi!

I need to disable resize button in Tkinter.
I inherit the Frame class. Then in the constructor i make my buttons,
labels, etc. Then I pack them and when move borders of the frame
everything changes it's location and it looks really bad. How can I
change that?
That's my code:
# -*- coding: cp1251 -*-
import Tkinter

class App(Tkinter.Frame):
def click(self):
pass

def click2(self):
pass

def __init__(self, master=None):
Tkinter.Frame.__init__(self, master, width = 700, height =
400,\
   bg = #99)
self.pack()

#   Buttons

self.b1 = Tkinter.Button(self, text = uДобави Книга,\
 command=self.click, font = Courier,
\
 fg = red)
self.b2 = Tkinter.Button(self, text = uДобави читател,\
 command=self.click2, font = Courier,
\
 fg = red)
self.b1.place(relx = 0.75, rely = 0.3)
self.b2.place(relx = 0.75, rely = 0.4)

#   Labels

self.l1 = Tkinter.Label(self, font = Courier, height = 4,\
text = uИнформация, fg = #ff,\
bg = #99)
self.l1.place(x = 275, y = 10)

#   Text Control
#self.txt = Tkinter.Text(self, bg = #124456, )
#self.txt.pack()




def main():
app = App()
app.mainloop()

if __name__ == __main__: main()
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pyparsing help

2008-03-24 Thread Paul McGuire
On Mar 23, 4:04 pm, rh0dium [EMAIL PROTECTED] wrote:

 I needed to tweak it a bit to ignore the comments..  Namely this fixed
 it up..

     mainDict = dictOf(
             Group(Word(alphas)+Optional(quotedString)),
             Suppress({) + attrDict + Suppress(})
             ) | cStyleComment.suppress()

 Thanks again.  Now I just need to figure out how to use your dicts to
 do some work..- Hide quoted text -

 - Show quoted text -

I'm glad this is coming around to some reasonable degree of completion
for you.  One last thought - your handling of comments is a bit crude,
and will not handle comments that crop up in the middle of dict
entries, as in:

color= /* using non-standard color during testing */
   plum

The more comprehensive way to handle comments is to call ignore.
Using ignore will propagate the comment handling to all embedded
expressions, so you only need to call ignore once on the top-most
pyparsing expression, as in:

mainDict.ignore(cStyleComment)

Also, ignore does token suppression automatically.

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


Re: Installing Mutagen Package On Windows

2008-03-24 Thread Diez B. Roggisch
Benjamin Serrato schrieb:
 Hey, I've run into another problem. I am trying to install the Mutagen 
 package to use as my first useful program, but can't figure out how to 
 install it on windows. The README says it is a simple application of--
 
 Installing
 --
  $ ./setup.py build
  $ su -c ./setup.py install
 
 --but I ran c:\python c:\python25\tools\scripts\setup.py build and did 
 similarly for setup.py. I also added c:\python25 and 
 c:\python25\tools\scripts to my path, but this hasn't worked. I have 
 heard of 'easy_install' but don't know how to run easy_install. So, I 
 ask for a reference because Google did not give me a quick answer and 
 the python.org explanation at PEP 250 doesn't really explain what I 
 should do.

You need to call

python2.5 setup.py install

and google for setuptools, python, easy_install to find out all about it 
you need.

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


Re: Why I hate lambdas (Re: Do any of you recommend Python as afirst programming language?)

2008-03-24 Thread Steven D'Aprano
On Mon, 24 Mar 2008 04:33:53 -0400, Terry Reedy wrote:

 The fact that .func_name (which is writeable) is not used at first
 surprised me until I remembered that code objects can potentially be
 used by multiple function objects and hence are not connected to any one
 in particular.

How does that happen?

And if it is the case, what's the justification for giving them a co_name 
attribute? Surely the name of the function should be that of the function 
object, not of one of the shared parts?


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


Re: parsing json output

2008-03-24 Thread Paul McGuire
On Mar 18, 9:10 pm, Gowri [EMAIL PROTECTED] wrote:
 Hi,

 I have a service running somewhere which gives me JSON data. What I do
 is this:

 import urllib,urllib2
 import cjson

 url = 'http://cmsdoc.cern.ch/cms/test/aprom/phedex/dev/gowri/datasvc/
 tbedi/requestDetails'
 params = {'format':'json'}
 eparams = urllib.urlencode(params)
 request = urllib2.Request(url,eparams)
 response = urllib2.urlopen(request)    # This request is sent in HTTP
 POST
 print response.read()

 This prints a whole bunch of nonsense as expected. I use cjson and am
 unable to figure out how to print this json response and I guess if I
 can do this, parsing should be straightforward?
snip

Gowri -

On a lark, I tried using the JSON parser that ships with the examples
in pyparsing (also available online at 
http://pyparsing.wikispaces.com/space/showimage/jsonParser.py).
The parsed data returned by pyparsing gives you a results object that
supports an attribute-style access to the individual fields of the
JSON object.  (Note: this parser only reads, it does not write out
JSON.)

Here is the code to use the pyparsing JSON parser (after downloading
pyparsing and the jsonParser.py example), tacked on to your previously-
posted code to retrieve the JSON data in variable 's':


from jsonParser import jsonObject
data = jsonObject.parseString(s)

# dump out listing of object and attributes
print data.dump()
print

# printe out specific attributes
print data.phedex.call_time
print data.phedex.instance
print data.phedex.request_call

# access an array of request objects
print len(data.phedex.request)
for req in data.phedex.request:
#~ print req.dump()
print -, req.id, req.last_update


This prints out (long lines clipped with '...'):

[['phedex', [['request', [[['last_update', '1188037561'], ...
- phedex: [['request', [[['last_update', '1188037561'],
['numofapproved', '1'],...
  - call_time: 0.10059
  - instance: tbedi
  - request: [[['last_update', '1188037561'], ['numofapproved',
'1'], ...
  - request_call: requestDetails
  - request_date: 2008-03-24 12:56:32 UTC
  - request_timestamp: 1206363392.09
  - request_url: 
http://cmsdoc.cern.ch/cms/test/aprom/phedex/dev/gowri/datasvc/tbedi/requestDetails?format=json

0.10059
tbedi
requestDetails
1884
- 7425 1188037561
- 8041 1188751826
- 9281 1190116795
- 9521 1190248781
- 12821 1192615612
- 13121 1192729887
...

The dump() method is a quick way to see what keys are defined in the
output object, and from the code you can see how to nest the
attributes following the nesting in the dump() output.

Pyparsing is pure Python, so it is quite portable, and works with
Python 2.3.1 and up (I ran this example with 2.5.1).

You can find out more at http://pyparsing.wikispaces.com.

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


python library to manipulate PALM documents ?

2008-03-24 Thread Francesco Bochicchio
Hi all,

anybody knows a python equivalent of the perl PALM::Doc module (and 
eventually other PALM::).

I have a e-book device wich reads mobi-pocket format (among others). I 
have downloaded from a forum a set of perl scripts to convert HTML to
unencripted mobipocket format and vice-versa. It uses the PALM:: package. 
I would attempt (for my convenience and for the fun of it) to make a
python equivalent of that. Hence my quest for a Palm::Doc equivalent. 

My googling up to now resulted in nothing relevant. Keeping searching ...

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


Re: Why I hate lambdas (Re: Do any of you recommend Python as afirst programming language?)

2008-03-24 Thread Arnaud Delobelle
On Mar 24, 1:26 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Mon, 24 Mar 2008 04:33:53 -0400, Terry Reedy wrote:
  The fact that .func_name (which is writeable) is not used at first
  surprised me until I remembered that code objects can potentially be
  used by multiple function objects and hence are not connected to any one
  in particular.

 How does that happen?

Like this:

 def foomaker(x):
... def foo(y): return x+y
... return foo
...
 foo1 = foomaker(1)
 foo2 = foomaker(2)
 foo1.func_code
code object foo at 0x73530, file stdin, line 2
 foo2.func_code
code object foo at 0x73530, file stdin, line 2

Of course foo1 and foo2 are not the same thing:

 foo1(8)
9
 foo2(8)
10

 And if it is the case, what's the justification for giving them a co_name
 attribute? Surely the name of the function should be that of the function
 object, not of one of the shared parts?

 foo1.__name__
'foo'
 foo1.func_code.co_name
'foo'

As seen above, func.__name__ and func.func_code.co_name are the same
thing (until tampered with).

--
Arnaud

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


Serving another web site which requires authentication

2008-03-24 Thread hasnihon . support
Hi,

I need your suggestions about the topic.
Actually, I'm not sure where to start but basically, I want to make
something like;

(I have an account on a site which requires log-in)
- I'll be logged-in to that site with my account in my server.
- And when a user connects to my site, I'll forward him/her to that
  site, using my account even if he/she doesn't have an account
  on that site...

probably, I need to develop a proxy to do this, but I'm not sure...
(I use python + django)

I really appriciate your ideas.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shortcutting the function call stack

2008-03-24 Thread Steven D'Aprano
On Mon, 24 Mar 2008 04:21:29 -0700, Julien wrote:

 Hello all,
 
 I would like to do something like:
 
 def called(arg)
 if arg==True:
 !!magic!!caller.return 1

Instead of writing if arg==True, or if (arg==True)==True, or even 
if ((arg==True)==True)==True, you should just write:

if arg:

That's probably all you need.


 
 def caller(arg)
 called(arg)
 return 2


def called(arg):
return 1

def caller(arg):
if arg: return called(arg)
return 2


And if you wish to change the place where the decision is made:

def called(arg):
if arg: return 1
else: return 2

def caller(arg):
return called(arg)


 Here, the fake !!!magic!!! represents a statement (which I ignore) that
 would make the caller function return a value different from what it'd
 return normally.

The statement you use to return a value different from what you would 
normally return is the return statement. You need to call that 
statement from the function doing the returning, not from another 
function.



 The reason I want that is because I don't want the caller function to
 know what's going on in the called function, and be shortcut if the
 called function think it's necessary.

Not knowing what's going on in called functions is why functions were 
invented in the first place. That's what they do.

What shortcut do you think you might want to take? There are probably 
better solutions than playing around with the internals of the 
interpreter. I have a feeling you are trying to implement some sort of 
function cache, maybe... 

def check_in_cache(arg):  # fake cache code
if arg:
!!magic!!caller.return 1  # not real Python

def function(arg):
check_in_cache(arg)  # magic happens here
# but if it doesn't, we do lots of calculations here
return 2  # and finally return


Is that the sort of thing you're trying for? If so, that's not the way to 
go about it.



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


urllib leaves connections/sockets waiting. BIG problem!!!

2008-03-24 Thread binaryj
hi i am using urllib2 to do some automated web thing.
basically i hit on sites and check the price what they are offering
for their product and then decide if i want to lower or increase my
pricing.so in short i have to hit hundreds of sites!

for the problem:
=
i run 20 threads all do the same stuff. (hit and run :) )
after around 10-15 hits(per thread) hits the thread does nothing. it
freezes. slowely but STEADILY all the threads end up with the same
fate :(

i did some netstat and found out that the connecton(sockets) the
program had opened are waiting the CLOSE_WAIT state !!

netstat -t
tcp1  0 192.168.1.2:4882host-blabla:www
CLOSE_WAIT
tcp1  0 192.168.1.2:4884host-blabla:www
CLOSE_WAIT
tcp1  0 192.168.1.2:4375host-blabla:www
CLOSE_WAIT


OUTPUT OF PROGRAM:
THREAD: #Thread-2 getting price from webi-d  7511975 DONE !!!
THREAD: #Thread-1 getting price from webi-d  4449152 DONE !!!
THREAD: #Thread-2 getting price from webi-d  7466091 DONE !!!
THREAD: #Thread-1 getting price from webi-d  8641914 DONE !!!
THREAD: #Thread-2 getting price from webi-d  7745289 DONE !!!
THREAD: #Thread-1 getting price from webi-d  6032442 DONE !!!
THREAD: #Thread-2 getting price from webi-d  8149873 DONE !!!
no-price-on-page error
THREAD: #Thread-1 getting price from webi-d  5842934 DONE !!!
no-price-on-page error
THREAD: #Thread-2 getting price from webi-d  3385778 DONE !!!
THREAD: #Thread-1 getting price from webi-d  4610122 DONE !!!
THREAD: #Thread-2 getting price from webi-d  8641536 DONE !!!
THREAD: #Thread-1 getting price from webi-d  4219935 DONE !!!
-and thats it, it freezes. i have waited 1hr the sockets have
not changed their states! :(


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


Re: Why I hate lambdas (Re: Do any of you recommend Python as afirst programming language?)

2008-03-24 Thread Steven D'Aprano
On Mon, 24 Mar 2008 06:48:10 -0700, Arnaud Delobelle wrote:

 On Mar 24, 1:26 pm, Steven D'Aprano [EMAIL PROTECTED]
 cybersource.com.au wrote:
 On Mon, 24 Mar 2008 04:33:53 -0400, Terry Reedy wrote:
  The fact that .func_name (which is writeable) is not used at first
  surprised me until I remembered that code objects can potentially be
  used by multiple function objects and hence are not connected to any
  one in particular.

 How does that happen?
 
 Like this:
 
 def foomaker(x):
 ... def foo(y): return x+y
 ... return foo
 ...
 foo1 = foomaker(1)
 foo2 = foomaker(2)
 foo1.func_code
 code object foo at 0x73530, file stdin, line 2
 foo2.func_code
 code object foo at 0x73530, file stdin, line 2


Ah, that makes sense. And obvious in hindsight.


 Of course foo1 and foo2 are not the same thing:

Naturally not. They are different functions. The fact that they share a 
small part (func_code) is irrelevant. There's more to a function than the 
code object.



 And if it is the case, what's the justification for giving them a
 co_name attribute? Surely the name of the function should be that of
 the function object, not of one of the shared parts?
 
 foo1.__name__
 'foo'
 foo1.func_code.co_name
 'foo'
 
 As seen above, func.__name__ and func.func_code.co_name are the same
 thing (until tampered with).

Yes, but what I'm asking is why the code objects have a co_name 
attribute. And even if there's a good reason for code objects to have a 
name, why do tracebacks use func.func_code.co_name instead of 
func.__name__?


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

Re: Serving another web site which requires authentication

2008-03-24 Thread binaryj
ur in luck i am an expert at this!
tell me the details , site name etc

you would have to proxy everything, basically the urls in the copied
page have to be changed to point to ur site.

its highly possible. a minor adjustment to ur urlconf and it will work.
-- 
http://mail.python.org/mailman/listinfo/python-list


URL encoding

2008-03-24 Thread vvangelovski
Is there any method in the standard modules that can perform proper
url encoding according to RFC?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: URL encoding

2008-03-24 Thread binaryj
On Mar 24, 7:04 pm, [EMAIL PROTECTED] wrote:
 Is there any method in the standard modules that can perform proper
 url encoding according to RFC?

whats wrong with the current encoding ??? it just works fine!!!

or is it that u dont know about urllib.urlencode() ??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: On copying arrays

2008-03-24 Thread Steven D'Aprano
On Mon, 24 Mar 2008 09:52:21 +, Duncan Booth wrote:

 The method usually recommended is:
 
   best = list(test)
 
 as it has no side effects

In general, you can't assume *anything* in Python has no side effects, 
unless you know what sort of object is being operated on. Here's an 
example that changes the value of test:

 test = iter((1, 2, 3, 4, 5, 6))
 best = list(test)
 best
[1, 2, 3, 4, 5, 6]
 another = list(test)
 another
[]


And here's an example that has a rather obvious side-effect:


 class Foo(object):
... def __getitem__(self, n):
... if n == 3: print I'm in ur puter, deletin ur files
... if 0 = n  6: return n+1
... raise IndexError
...
 test = Foo()
 best = list(test)
I'm in ur puter, deletin ur files
 best
[1, 2, 3, 4, 5, 6]


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


Re: Multiline CSV export to Excel produces unrecognized characters?

2008-03-24 Thread felciano

 Any chance you are doing this on Windows and Excel doesn't like the
 return+linefeed line endings that Windows produces when writing files in
 text mode?  Try 'wb' as mode for the output file.

 Ciao,
 Marc 'BlackJack' Rintsch

Fixed! Can't believe I missed that...

Thank you for the quick reply!

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


Re: Why I hate lambdas (Re: Do any of you recommend Python as afirst programming language?)

2008-03-24 Thread Arnaud Delobelle
On Mar 24, 2:01 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
[...]

 Yes, but what I'm asking is why the code objects have a co_name
 attribute. And even if there's a good reason for code objects to have a
 name, why do tracebacks use func.func_code.co_name instead of
 func.__name__?

From what I remember when I looked at the source: stack frames execute
code objects, not functions.  They don't know what function has
spawned them, only what code object they are executing.  In fact when
one thinks of it, it makes more sense for code objects to have a name
(taken from the def statement) than for function objects, as there is
exactly one code object for every def statement.

--
Arnaud

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


Re: Shortcutting the function call stack

2008-03-24 Thread Jason
On Mar 24, 5:21 am, Julien [EMAIL PROTECTED] wrote:
 Hello all,

 I would like to do something like:

 def called(arg)
 if arg==True:
 !!magic!!caller.return 1

 def caller(arg)
 called(arg)
 return 2

 Here, the fake !!!magic!!! represents a statement (which I ignore)
 that would make the caller function return a value different from what
 it'd return normally.

 For example, caller(True) would return 1, and caller(False) would
 return 2. The reason I want that is because I don't want the caller
 function to know what's going on in the called function, and be
 shortcut if the called function think it's necessary.

 Would you know if that's possible, and if so, how?

 I've done a bit of research and I think I've found some good pointers,
 in particular using the 'inspect' library:

 import inspect

 def called(arg)
 if arg==True:
 caller_frame = inspect.stack()[1]
 ...

 Here 'caller_frame' contains the frame of the caller function. Now,
 how can I make that frame return a particular value?

 By the way, I'm not really interested in 'called' throwing an
 exception and 'caller' catching it. In fact, I want things to remain
 completely transparent for 'caller'.

 Hope that was clear... :/

 Thanks!

 Julien

As Steven wrote, it's not very clear.  If we knew the intent of this,
we could perhaps point you to a more useful, maintainable technique.
We don't know why you're trying to circumvent the programming language
in this case.  Any solution that works as you described will probably
be unportable between the different Pythons (CPython, Jython,
IronPython, etc).

Please note that the following code should work, but I've only run it
through the interpreter in my brain.  My brain's interpreter is full
of Heisenbugs, so you may need to adjust a few things.  Here's my
thoughts:

Given:
def First( arg ):
Second( arg )
return 5

1)  If you can modify both functions, change the first function to
return a value in certain circumstances:
def AltFirst( arg ):
value = Second( arg )
if value is not None:  return value
return 5

2)  Raise an exception in Second, and catch that exception above
First:

class SecondExcept(Exception):
def __init__(self, value):
Exception.__init__(self, 'Spam!')
self.value = value

def Second(arg):
if arg == my_conditional_value:
raise SecondExcept( 5 )

# The following could even be put in your own function,
# or in a wrapper or decorator for the First function.
try:
myvalue = First( 'Vikings!' )
except SecondExcept, exc:
myvalue = exc.value

When you need to use an exceptional pathway, use an exception.  They
aren't just for reporting errors.

Hope this helps.

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


Re: python library to manipulate PALM documents ?

2008-03-24 Thread Guilherme Polo
24 Mar 2008 13:36:13 GMT, Francesco Bochicchio [EMAIL PROTECTED]:
 Hi all,

  anybody knows a python equivalent of the perl PALM::Doc module (and
  eventually other PALM::).

  I have a e-book device wich reads mobi-pocket format (among others). I
  have downloaded from a forum a set of perl scripts to convert HTML to
  unencripted mobipocket format and vice-versa. It uses the PALM:: package.
  I would attempt (for my convenience and for the fun of it) to make a
  python equivalent of that. Hence my quest for a Palm::Doc equivalent.


I'm not sure if it is what you are after, but it seems to be, check this:
http://pypi.python.org/pypi/PalmDB/1.8.1

  My googling up to now resulted in nothing relevant. Keeping searching ...

  Ciao
  -
  FB

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



-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shortcutting the function call stack

2008-03-24 Thread castironpi
On Mar 24, 9:48 am, Jason [EMAIL PROTECTED] wrote:
 On Mar 24, 5:21 am, Julien [EMAIL PROTECTED] wrote:





  Hello all,

  I would like to do something like:

  def called(arg)
      if arg==True:
          !!magic!!caller.return 1

  def caller(arg)
      called(arg)
      return 2

  Here, the fake !!!magic!!! represents a statement (which I ignore)
  that would make the caller function return a value different from what
  it'd return normally.

  For example, caller(True) would return 1, and caller(False) would
  return 2. The reason I want that is because I don't want the caller
  function to know what's going on in the called function, and be
  shortcut if the called function think it's necessary.

  Would you know if that's possible, and if so, how?

  I've done a bit of research and I think I've found some good pointers,
  in particular using the 'inspect' library:

  import inspect

  def called(arg)
      if arg==True:
          caller_frame = inspect.stack()[1]
          ...

  Here 'caller_frame' contains the frame of the caller function. Now,
  how can I make that frame return a particular value?

  By the way, I'm not really interested in 'called' throwing an
  exception and 'caller' catching it. In fact, I want things to remain
  completely transparent for 'caller'.

  Hope that was clear... :/

  Thanks!

  Julien

 As Steven wrote, it's not very clear.  If we knew the intent of this,
 we could perhaps point you to a more useful, maintainable technique.
 We don't know why you're trying to circumvent the programming language
 in this case.  Any solution that works as you described will probably
 be unportable between the different Pythons (CPython, Jython,
 IronPython, etc).

 Please note that the following code should work, but I've only run it
 through the interpreter in my brain.  My brain's interpreter is full
 of Heisenbugs, so you may need to adjust a few things.  Here's my
 thoughts:

 Given:
     def First( arg ):
         Second( arg )
         return 5

 1)  If you can modify both functions, change the first function to
 return a value in certain circumstances:
     def AltFirst( arg ):
         value = Second( arg )
         if value is not None:  return value
         return 5

 2)  Raise an exception in Second, and catch that exception above
 First:

 class SecondExcept(Exception):
     def __init__(self, value):
         Exception.__init__(self, 'Spam!')
         self.value = value

 def Second(arg):
     if arg == my_conditional_value:
         raise SecondExcept( 5 )

 # The following could even be put in your own function,
 # or in a wrapper or decorator for the First function.
 try:
     myvalue = First( 'Vikings!' )
 except SecondExcept, exc:
     myvalue = exc.value

 When you need to use an exceptional pathway, use an exception.  They
 aren't just for reporting errors.

Exceptions are a control tool.  There was a 'goto using Exceptions'
once in the manuals.  I don't see a problem with a local control-flow
object.  It would appease a number of requests I've read.

for x:
  for y:
control.break( 2 )

if a:
  if b:
control.fail( 2 )

so no need to reduplicate:

  else:
thing()
else:
  thing()

if a:
  if b:
control.mostrecenttest( 0 )

def f():
  def g():
control.return( 2 )( early )

Something tells me generators could solve the problem, but I may be
enamored, so it's a separate post.
-- 
http://mail.python.org/mailman/listinfo/python-list


Element Tree Help

2008-03-24 Thread Robert Rawlins
Hello Guys,I have little to no experiance with element tree and I'm struggling 
to find a way to parse the details from the XML document (attached) into my 
application. Essentialy I'm looking to take the following document and turn it 
into a dict of tuples, each dict element defines a datasource with the key to 
the element being the 'name' which is defined in the XML and then the value of 
the pair is a tuple which contains the details of the datasource, like the host 
and port etc.I've attached a copy of the example XML to this email.Can anyone 
offer some advice on how to get started with this? I've spent a little time 
looking over the documentation of element tree and have struggled to break the 
ice and parse this document.Thanks guys,Robert 
_
The next generation of Windows Live is here
http://www.windowslive.co.uk/get-live?xml version=1.0 encoding=iso-8859-1?
!DOCTYPE datasources SYSTEM datasources.dtd
datasources
datasource
namea name/name
hostlocalhost/host
port3306/port
databasedatabase1/database
usernamesomeusername/username
passwordsomepassword/password
/datasource
datasource
nameanother name/name
hostlocalhost/host
port3306/port
databasedatabase2/database
usernameitsusername/username
passwordandthepassword/password
/datasource
/datasources-- 
http://mail.python.org/mailman/listinfo/python-list

what are generators?

2008-03-24 Thread castironpi
I'm looking for a cool trick using generators.  Know any exercises I
can work?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dividing tuple elements with an int or float

2008-03-24 Thread castironpi
On Mar 23, 12:22 pm, Lie [EMAIL PROTECTED] wrote:
 On Mar 22, 2:23 pm, [EMAIL PROTECTED] wrote:

   Sane programmers don't write such semi-functional things (unless it
   helps expressing the problem in certain domains).
   I now think that deprecating map, lambda  Co. was a good thing after
   all.

  If you write it that way the first time, you need therapy.  Actually,
  at this point, I (for one, personally) want to investigate 'certain
  domains'.  Tell me it's really bad at everything or what it's good
  at.  What can I respect about it?

 If you (castiro..) write it your way, you'll surely win the Obfuscated
 Python Code Contest.

Sometimes you're on a roll and you don't want to back up a step.  What
are good on a roll habits?  (Or, what roll?)
-- 
http://mail.python.org/mailman/listinfo/python-list


pythonweb and Leopard

2008-03-24 Thread brianrpsgt1
I am trying to create a simple web application that is written in
python, using apache and mysql.  It appears as though the python web
modules have been installed, however, whenever I try to run a python
script, it only displays the code in the browser.  It is like the
python code is not getting processed.  I have tried this on a iMac
(Intel) and a PowerBook G4, both running Leopard.

Python Web Modules 0.5.3
Apache 2.2
Python 2.5

I am trying to run the python script from the default web directory on
the Mac, /Library/WebServer/Documents
I updated the httpd.conf for the Directory to say Options +ExecCGI
and AddHandler cgi-script .cgi .py

I know that I am missing something simple.

Any help would be great

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


Re: Element Tree Help

2008-03-24 Thread Stefan Behnel
Robert Rawlins wrote:
 Hello Guys,I have little to no experiance with element tree and I'm
 struggling to find a way to parse the details from the XML document
 (attached) into my application. Essentialy I'm looking to take the
 following document and turn it into a dict of tuples, each dict element
 defines a datasource with the key to the element being the 'name' which is
 defined in the XML and then the value of the pair is a tuple which contains
 the details of the datasource, like the host and port etc.I've attached a
 copy of the example XML to this email.Can anyone offer some advice on how
 to get started with this? I've spent a little time looking over the
 documentation of element tree and have struggled to break the ice and parse
 this document.Thanks guys,Robert

Given this document:

?xml version=1.0 encoding=iso-8859-1?
!DOCTYPE datasources SYSTEM datasources.dtd
datasources
datasource
namea name/name
hostlocalhost/host
port3306/port
databasedatabase1/database
usernamesomeusername/username
passwordsomepassword/password
/datasource
datasource
nameanother name/name
hostlocalhost/host
port3306/port
databasedatabase2/database
usernameitsusername/username
passwordandthepassword/password
/datasource
/datasources

I would do something like this:

  d = {}
  for event, element in ET.iterparse(thefile.xml):
  if element.tag == datasource:
  d[element.find(name)] = tuple([ el.text for el in element ])

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


Re: Element Tree Help

2008-03-24 Thread Stefan Behnel
Stefan Behnel schrieb:
 Robert Rawlins wrote:
 Hello Guys,I have little to no experiance with element tree and I'm
 struggling to find a way to parse the details from the XML document
 (attached) into my application. Essentialy I'm looking to take the
 following document and turn it into a dict of tuples, each dict element
 defines a datasource with the key to the element being the 'name' which is
 defined in the XML and then the value of the pair is a tuple which contains
 the details of the datasource, like the host and port etc.I've attached a
 copy of the example XML to this email.Can anyone offer some advice on how
 to get started with this? I've spent a little time looking over the
 documentation of element tree and have struggled to break the ice and parse
 this document.Thanks guys,Robert
 
 Given this document:
 
 ?xml version=1.0 encoding=iso-8859-1?
 !DOCTYPE datasources SYSTEM datasources.dtd
 datasources
   datasource
   namea name/name
   hostlocalhost/host
   port3306/port
   databasedatabase1/database
   usernamesomeusername/username
   passwordsomepassword/password
   /datasource
   datasource
   nameanother name/name
   hostlocalhost/host
   port3306/port
   databasedatabase2/database
   usernameitsusername/username
   passwordandthepassword/password
   /datasource
 /datasources
 
 I would do something like this:
 
   d = {}
   for event, element in ET.iterparse(thefile.xml):
   if element.tag == datasource:
   d[element.find(name)] = tuple([ el.text for el in element ])

Sorry, the last line should be

   d[element.findtext(name)] = tuple([ el.text for el in element ])

but you'll likely have to modify that line anyway.

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


Re: URL encoding

2008-03-24 Thread Stefan Behnel
binaryj wrote:
 On Mar 24, 7:04 pm, [EMAIL PROTECTED] wrote:
 Is there any method in the standard modules that can perform proper
 url encoding according to RFC?
 
 whats wrong with the current encoding ??? it just works fine!!!
 
 or is it that u dont know about urllib.urlencode() ??

I think that was obvious from the question, no need to spill punctuation marks
all over the place.

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


Re: Disable resize button

2008-03-24 Thread Francesco Bochicchio
Il Mon, 24 Mar 2008 04:38:50 -0700, myonov ha scritto:

 Hi!
 
 I need to disable resize button in Tkinter. I inherit the Frame class.
 Then in the constructor i make my buttons, labels, etc. Then I pack them
 and when move borders of the frame everything changes it's location and
 it looks really bad. How can I change that?
 That's my code:
 # -*- coding: cp1251 -*-
 import Tkinter
 
 class App(Tkinter.Frame):
 def click(self):
 pass
 
 def click2(self):
 pass
 
 def __init__(self, master=None):
 Tkinter.Frame.__init__(self, master, width = 700, height =
 400,\
bg = #99)
 self.pack()
 
 #   Buttons
 
 self.b1 = Tkinter.Button(self, text = uДобави Книга,\
  command=self.click, font = Courier,
 \
  fg = red)
 self.b2 = Tkinter.Button(self, text = uДобави читател,\
  command=self.click2, font = Courier,
 \
  fg = red)
 self.b1.place(relx = 0.75, rely = 0.3) self.b2.place(relx =
 0.75, rely = 0.4)
 
 #   Labels
 
 self.l1 = Tkinter.Label(self, font = Courier, height = 4,\
 text = uИнформация, fg = #ff,\
 bg = #99)
 self.l1.place(x = 275, y = 10)
 
 #   Text Control
 #self.txt = Tkinter.Text(self, bg = #124456, ) #   
 self.txt.pack()
 
 


You could try including the frame in a toplevel window (e.g. passing 
Tkinter.Tk() as super) and then doing super.wm_resizable(None, None)

A better idea would be using pack instead of place, leaving to the 
toolkit the job of rearranging the widgets when the window is enlarged
or reduced.

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

Re: python library to manipulate PALM documents ?

2008-03-24 Thread Francesco Bochicchio
Il Mon, 24 Mar 2008 12:08:59 -0300, Guilherme Polo ha scritto:

 24 Mar 2008 13:36:13 GMT, Francesco Bochicchio [EMAIL PROTECTED]:
 Hi all,

  anybody knows a python equivalent of the perl PALM::Doc module (and
  eventually other PALM::).

  I have a e-book device wich reads mobi-pocket format (among others). I
  have downloaded from a forum a set of perl scripts to convert HTML to
  unencripted mobipocket format and vice-versa. It uses the PALM::
  package. I would attempt (for my convenience and for the fun of it) to
  make a python equivalent of that. Hence my quest for a Palm::Doc
  equivalent.


 I'm not sure if it is what you are after, but it seems to be, check
 this: http://pypi.python.org/pypi/PalmDB/1.8.1
 
It could be. I read that mobipocket files may have extension .prc.

Ciao

FB

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


Re: Why I hate lambdas (Re: Do any of you recommend Python as a firstprogramming language?)

2008-03-24 Thread bearophileHUGS
Paul RubinIt's at least pretty good.  It's not ideal, but nothing
ever is.

I agree. At the moment Python is among the best languages for that,
but it's not perfect for that purpose. I think newbies may need a bit
more structured language, where you have to put things in a certain
order to have a working program. I think this may teach them some good
programming habits. Pascal is a bit too much old today, but it helps
learn how to program in a tidy way. I am not sure about this, I'd like
to have more data to be able to sort out this freedom/structure
alternative regarding teaching languages.
Another possible downside of Python is that it doesn't allow you to
know very well what's under the language, so you can't use pointers
and memory very well, so you can't learn those things very well. You
need a different language for that, like C (or Pascal) or assembly,
but such languages are useful later, and less as very first languages,
especially for very young people.


Paul RubinChris Okasaki (of functional data structures fame) has an
interesting blog post about why indentation-based structuring is a big
help for teaching:

I have quite appreciated that article, and other people are doing
similar things for C and C++ (I'd like to do something similar for D):
http://blog.micropledge.com/2007/09/nobraces/
And OCaml:
http://people.csail.mit.edu/mikelin/ocaml+twt/


Arnaud DelobelleMy other 'coming of age' was when I took a lambda-
calculus course at university.  I felt like a man who's had a black
and white TV set all his life and watches colour TV for the first
time.

Scheme-like languages are surely interesting, and eventually a
programmer can learn one of them, but I think as a very first language
Python is fitter, because its syntax is more compatible with a normal
little trained human mind.



7studBeginning programmers in grades 9-12 are not going to understand
issues like that, and it would be a mistake to try and introduce
them.  Beginning programmers should be concentrating their efforts on
learning the syntax of a language and basic constructs like for-loops
and if statements.

This is wrong. Some languages like Scheme are quite fit for young
people, and they don't even need a for loop. A 7-9 years old person is
able to understand quite a lot, and computer science and programming
aren't based on syntax. They are more based on the fun of problem
solving, and similar things. Syntax is important because it's the tool
that allows you to tell the computer how to compute the results of the
problems you have (usually) already solved, but it can't be the
purpose, even in a first course of programming. When you want to teach
painting to a 6 year old child your purpose isn't teaching her/him all
about the structure of the canvas and brushes and the chemistry of the
pigments, but how to have fun putting all the colors on the canvas/
paper, trying to create some image, for fun. (On the other hand you
can teach to love chemistry to a 6-8 year old person, showing how much
it can be fun, if you start talking about the chemistry behind the
colors of fireworks, but that's not panting anymore).


Ben CWhy does Python not have a switch or until statement?

Maybe because it thinks syntax minimalism is a virtue, or maybe
because they aren't easy to add (try to design a do-while using Python-
like syntax).


Ben CWhy are very common objects (stack, queue, linked list) not
builtin? etc.

Because it was a small language, used for scripting purposes, I think.
You need those data structures if you want higher performance (in
speed and/or memory used) but performance was not one of the main
purposes of Python.
Another purpose for those data structures is to teach them, but a good
teaching language is probably one that allows you to write your own
versions of them.
Today the collections module and other built-in modules gives you some
of those data structures, you just need to import them, so using them
isn't much a hassle, even if they aren't built in.


AahzThe problem with lambda is that too often it results in clutter

Probably I am missing your point, but I'd like to remind people the
syntax for lambdas in the last C# versions:
x, y = x * 2 + y
Instead of the Python syntax:
lambda x, y: x * 2 + y
I think that C# syntax is nice and readable enough.


Terry Reedy[lot of things] Yes, fundamentally different categories of
types are (sensibly) treated differently with repect to definition and
namespace names, but calling that 'disharmony' depends on the
listener.

Thank you for your interesting explanation.

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Element Tree Help

2008-03-24 Thread Reedick, Andrew
Robert Rawlins wrote:
 I have little to no experiance with element tree and I'm struggling to 
 find a way to parse the details from the XML document (attached) into 
 my application. Essentialy I'm looking to take the following document 
 and turn it into a dict of tuples, each dict element defines a 
 datasource with the key to the element being the 'name' which is 
 defined in the XML and then the value of the pair is a tuple which 
 contains the details of the datasource, like the host and port etc.


Here's another way to walk an ElementTree.  This one creates a hash of hashes 
which are normally more useful than tuples for property lookups.

import xml.etree.ElementTree as ET

tree = ET.ElementTree(file = foo.xml)
d = {}
for ds in tree.findall(datasource):

name = ds.find('name').text
d[name] = {}
print 'datasource =', name

for i in ds.findall('*'):
#for i in ds.getiterator():  # also works

if i.tag in ('datasource', 'name'):
continue

print '',i.tag, =, i.text
d[name][i.tag] = i.text

print

print d

*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA621


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


Problems with wxPython

2008-03-24 Thread David Anderson
Hi, If ther's anyone who knows pretty much about wxPython can e-mail me? I'm
having some trouble in dealing with some guis here, I would thank u very
much if you could help me
bye
[]'s
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Need help calling a proprietary C DLL from Python

2008-03-24 Thread Craig
On Mar 23, 7:59 pm, Dennis Lee Bieber [EMAIL PROTECTED] wrote:
 On Sun, 23 Mar 2008 14:24:52 -0700 (PDT), Craig [EMAIL PROTECTED]
 declaimed the following in comp.lang.python:



  This dll was designed to be used from either C or Visual Basic 6.

  I have the declare statements for VB6, if that helps.

 Probably not that much -- I'd bet it's full of variant records G



  Based on the results I have so far (and I have tried MANY permutations
  like trying to use the LPSTR for SecKey and PriKey which are returned
  as is TypeDef), it looks like SecKey and PriKey are being used as data
  instead of pointers.

  For this, I try:
  LPSTR = c_char_p
  VmxGet.argtypes = [LPHANDLE, LPSHORT, LPSHORT, LPBSTR, LPSTR, LPBSTR,
  LPSTR]
  SrchKey =
  windll.oleaut32.SysAllocStringByteLen(MSD19DN
  \x00, 41)
  SecKey = create_string_buffer(41)
  SecKey.raw = 1234567890123456789012345678901234567890
  PriKey =
  windll.oleaut32.SysAllocStringByteLen(ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234\x00,
  41)
  TypeDef = create_string_buffer(128)
  TypeDef.raw = X.center(128, X)
  res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
  byref(c_void_p(SrchKey)), SecKey, byref(c_void_p(PriKey)), TypeDef )
  and I get:
  Traceback (most recent call last):
File C:\temp\vbisam_test_2.py, line 158, in module
  res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
  byref(c_void_p(S
  rchKey)), SecKey, byref(c_void_p(PriKey)), TypeDef )
  WindowsError: exception: access violation reading 0x3433322D

  I notice that SecKey.raw starts with 1234 and the exception address
  is 0x3433322D, which is 432-.

 0x2D is 4 less than the expected 0x31...



  And, changing to:
  VmxGet.argtypes = [LPHANDLE, LPSHORT, LPSHORT, LPBSTR, LPBSTR, LPSTR,
  LPSTR]
  PriKey = create_string_buffer(41)
  PriKey.raw = ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234
  res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
  byref(c_void_p(SrchKey)), byref(c_void_p(SecKey)), PriKey, TypeDef )
  I then get:
  Traceback (most recent call last):
File C:\temp\vbisam_test_2.py, line 159, in module
  res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
  byref(c_void_p(S
  rchKey)), byref(c_void_p(SecKey)), PriKey, TypeDef )
  WindowsError: exception: access violation reading 0x4443423D

  I notice that PriKey.raw starts with ABCD and the exception address
  is 0x4443423D, which is DBC=.

 ... and 0x3D is 4 less than the expected 0x41

 Which leads me to suspect that BSTR are a structure, not a plain
 string, in which the address given is supposed to be prefaced with a
 length value. IOWs, something like:

 ||--|
 ^^  C-string data
 ||Address to be passed
 |(address - 4) to get to a length count field

 Confirmed:http://msdn2.microsoft.com/en-us/library/ms221069(VS.85).aspx

 (the URL is from HTTP through to the end, including .aspx)

 Creating such may not be difficult -- but passing it to the DLL
 could be. I don't know if ctypes allows pointer arithmetic.

 ctypes OLESTR is a c_wchar_p, but that is still a c-style string with no
 length prefix.

 The only mention of BSTR in the win32 extensions is in text that
 implies that the win32 extension library takes care of converting
 from/to BSTR and Python strings transparently -- but that won't work for
 your third-party library I suspect.

 Might have to beg the author(s) of ctypes to add a BSTR type to the
 list of those supported... as I can find no means of tweaking the
 address computed by byref() to point somewhere into a structure rather
 than the beginning of the structure.

  pk = ctypes.windll.oleaut32.SysAllocStringByteLen(1234567890, 12)
  pk
 1373844
  id(pk)
 18941724
  ctypes.string_at(pk)
 '1234567890'
  ctypes.string_at(pk-4, 20)

 '\x0c\x00\x00\x001234567890\x00\x01\x00\x00\x00\x00'



 Okay, the return value from SysAlloc... IS the integer representing
 the address of a BSTR structure (IE, the address four bytes in from the
 real memory start)... Note how backing up 4 bytes reveals the BSTR
 length field

 What happens if you just pass that item as-is, no byref(), no
 conversion to ctypes pointer types...

 PriKey = ctypes.windll.oleaut32.SysAllocStringByteLen(1234567890, 41)
 SecKey = ctypes.windll.oleaut32.SysAllocStringByteLen(1234567890, 41)

 res = VmxGet(   byref(hwmcb),
 byref(SecIndex),
 byref(Option),
 byref(c_void_p(SrchKey)),
 SecKey,
 PriKey,
 TypeDef )

  PriKey = ctypes.windll.oleaut32.SysAllocStringByteLen(1234567890, 41)
  ctypes.string_at(PriKey, 41)

 1234567890\x00\x01:\x00\x00\x00\xb6\x01\x00\x000\x99#\x01\xe0\x94\x1a\x1e\x0b\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00'
  ctypes.string_at(PriKey-4, 41+4)

 

python, dbus and pointers help.

2008-03-24 Thread Glich
'''
hello, using pidgin instant messenger I can get the value of 'message'
when one is being sent but,
I dont know how to chage the value of message.

from the documentation (http://developer.pidgin.im/doxygen/dev/html/
conversation-signals.html#sending-im-msg):
_
sending-im-msg:

Emitted before sending an IM to a user. message is a pointer to the
message string, so the plugin can replace the message before being
sent.
_

I think python get's a copy of the message (this is just a guess). How
can I change the message before it is sent?

Thanks.
The code is taken from http://developer.pidgin.im/wiki/DbusHowto#Furtherreading
and changed only a small amount.
'''

#!/usr/bin/env python

def cb_func(account, rec, message):
#change message here somehow?
print message

import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()

bus.add_signal_receiver(cb_func,
 
dbus_interface=im.pidgin.purple.PurpleInterface,
signal_name=SendingImMsg)

loop = gobject.MainLoop()
loop.run()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python, dbus and pointers help.

2008-03-24 Thread Glich
or a way of letting me see the message then cancel sending it then I
could create a new message and send that one. but I cant see this in
the documentation
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with wxPython

2008-03-24 Thread Frank Niessink
Hi David,

2008/3/24, David Anderson [EMAIL PROTECTED]:
 Hi, If ther's anyone who knows pretty much about wxPython can e-mail me? I'm
 having some trouble in dealing with some guis here, I would thank u very
 much if you could help me

You should subscribe to the wxPython users mailinglist and ask there.
It's a very helpful mailinglist. Robin Dunn (wxPython author) is very
active in answering questions from wxPython users.

See http://www.wxpython.org/maillist.php

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


Is IronPython real Python?

2008-03-24 Thread jmDesktop
I know that IronPython and CPython are different in that one does not
use the .net framework, but are they both really the same Python
language.  From my basic understanding, it will depend on what the
programmer's goal is as to which of the two would be used, but I
didn't know if they were really the same language.

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


Re: Is IronPython real Python?

2008-03-24 Thread Mike Driscoll
On Mar 24, 12:00 pm, jmDesktop [EMAIL PROTECTED] wrote:
 I know that IronPython and CPython are different in that one does not
 use the .net framework, but are they both really the same Python
 language.  From my basic understanding, it will depend on what the
 programmer's goal is as to which of the two would be used, but I
 didn't know if they were really the same language.

I would say that they're mostly the same. IronPython allows the
developer to use any of the .NET libraries within their Python
program, much like Jython allows Python to import Java libraries.

The main IronPython website has a wiki that outlines the differences:

http://www.codeplex.com/IronPython/Wiki/View.aspx?title=DifferencesreferringTitle=Home

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


Re: Installing Mutagen Package On Windows

2008-03-24 Thread Gabriel Genellina
En Mon, 24 Mar 2008 03:25:02 -0300, Benjamin Serrato  
[EMAIL PROTECTED] escribió:

 Hey, I've run into another problem. I am trying to install the Mutagen
 package to use as my first useful program, but can't figure out how to
 install it on windows. The README says it is a simple application of--

 Installing
 --
   $ ./setup.py build
   $ su -c ./setup.py install

 --but I ran c:\python c:\python25\tools\scripts\setup.py build and did
 similarly for setup.py. I also added c:\python25 and
 c:\python25\tools\scripts to my path, but this hasn't worked. I have

The setup.by you have to run is the one included in the Mutagen package,  
not that one.
Unless the author provides more specific instructions, the usual way is:

- Unpack the archive into any temporary directory
- Open a console (cmd) and change to that temporary directory (cd  
c:\some\temp\dir)
- Execute this command:
python setup.py install
- That's all

If you get any error, post the whole error message here, but for specific  
help on the package it would be better to contact the author directly.

-- 
Gabriel Genellina

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


Serving an external web site which requires authentication

2008-03-24 Thread Kaze
Hi,

I need your suggestions about the topic.
Actually, I'm not sure where to start but basically, I want to make
something like;
(I have an account on a site which requires log-in)

- I'll be logged-in to that site with my account in my server.
- And when a user connects to my site, I'll forward him/her to that
site, using my account even if he/she doesn't have an account on that
site...

probably, I need to develop a proxy to do this, but I'm not sure...
(I'm developing a django site)

I really appreciate your ideas.
-- 
http://mail.python.org/mailman/listinfo/python-list


importing package contents from multiple places in PYTHONPATH

2008-03-24 Thread joshetomlinson
Hi all,

I'm new to python, and am trying to determine if it's possible to do
the following...

I have a directory structure like this, with both 'dir1' and 'dir2' in
my PYTHONPATH

dir1/
  foo/
__init__.py
a.py
b.py

dir2/
  foo/
__init__.py
a.py
c.py

I'd like to be able to:

python import foo.a, foo.b, foo.c

I'd hope for package 'foo.a' to come from dir1 since it was first on
the path, with 'foo.b' and 'foo.c' coming form dir1 and dir2
respectively.

I understand that python stops once it encounters the first 'foo'
package in PYTHONPATH, but I was wondering if there was a way around
this.  I've had some success modifying __path__ in the foo/__init__.py
files, but am unsure if this is the best approach.  Perhaps there's a
way to do this with import hooks?

Is there a precedent for this type of thing?

Thanks in advance,
Josh
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Tobu 0.4j

2008-03-24 Thread AK
This is an initial announcement.

Tobu is a freeform database / tagger / PIM and more. It works in both 
Linux and Windows and uses wxPython framework and pysqlite.

Comments, suggestions, feature requests and critique are gladly
appreciated.

Tutorial with links to download page and to graphical overview page is 
located at the following link. It's best to start with graphical 
overview page that shows screenshots of main window and menus with 
thorough explanations of functionality of most items.

http://www.lightbird.net/tobu/



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


behavior varied between empty string '' and empty list []

2008-03-24 Thread Tzury Bar Yochay
while I can invoke methods of empty string '' right in typing
(''.join(), etc.) I can't do the same with empty list

example:

 a = [1,2,3]
 b = [].extend(a)
 b
 b = []
 b.extend(a)
 b
[1,2,3]

I would not use b = a since I don't want changes on 'b' to apply on
'a'

do you think this should be available on lists to invoke method
directly?
-- 
http://mail.python.org/mailman/listinfo/python-list


Impersonate another user (Guest) on Windows

2008-03-24 Thread Giampaolo Rodola'
Hi,
I'm trying to write a plug-in for a ftp server of mine to permit the
integration with accounts defined on the Windows system.
What I basically need is impersonating a user, execute e filesystem
call (e.g. create a directory via os.mkdir()) and then switch back to
the original user (Administrator).
I wrote down this simple class which seems to fit pretty well for my
purposes:

class WinNTAuthorizer:

def impersonate_user(self, username, password):
self.impersonated_user_handler = win32security.LogonUser(
   username,
   None,
   password,
   win32con.LOGON32_LOGON_INTERACTIVE,
   win32con.LOGON32_PROVIDER_DEFAULT)
 
win32security.ImpersonateLoggedOnUser(self.impersonated_user_handler)

def terminate_impersonation(self):
win32security.RevertToSelf()
self.impersonated_user_handler.Close()


What I need now is impersonating the Guest user to handle the
anonymous logins (which it's exactly what IIS FTPd does) but I don't
know how to do it.
Does Guest account has a password or do I have to use something
different than LogonUser to manage it?
Could someone point me in the right direction?

Thanks in advance.


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


Re: Problems with wxPython

2008-03-24 Thread David Anderson
Thanx

On Mon, Mar 24, 2008 at 2:00 PM, Frank Niessink [EMAIL PROTECTED] wrote:

 Hi David,

 2008/3/24, David Anderson [EMAIL PROTECTED]:
  Hi, If ther's anyone who knows pretty much about wxPython can e-mail me?
 I'm
  having some trouble in dealing with some guis here, I would thank u very
  much if you could help me

 You should subscribe to the wxPython users mailinglist and ask there.
 It's a very helpful mailinglist. Robin Dunn (wxPython author) is very
 active in answering questions from wxPython users.

 See http://www.wxpython.org/maillist.php

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

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

Re: importing package contents from multiple places in PYTHONPATH

2008-03-24 Thread Gabriel Genellina
En Mon, 24 Mar 2008 15:06:51 -0300, [EMAIL PROTECTED] escribió:

 Hi all,

 I'm new to python, and am trying to determine if it's possible to do
 the following...

 I have a directory structure like this, with both 'dir1' and 'dir2' in
 my PYTHONPATH

 dir1/
   foo/
 __init__.py
 a.py
 b.py

 dir2/
   foo/
 __init__.py
 a.py
 c.py

 I'd like to be able to:

 python import foo.a, foo.b, foo.c

 I'd hope for package 'foo.a' to come from dir1 since it was first on
 the path, with 'foo.b' and 'foo.c' coming form dir1 and dir2
 respectively.

Yes. Note that dir2/foo/__init__.py is not used at all and it's just  
confusing. And a.py (in dir2) won't be found inside the package but any  
import a from c.py will import that one instead of the one at dir1.  
dir2/foo is just a bag, not a package :)

 I understand that python stops once it encounters the first 'foo'
 package in PYTHONPATH, but I was wondering if there was a way around
 this.  I've had some success modifying __path__ in the foo/__init__.py
 files, but am unsure if this is the best approach.

I think it is the simplest approach, if not the only one...

 Perhaps there's a
 way to do this with import hooks?

Perhaps... But appending a single item to __path__ is simple enough to  
stop further thinking from my side :)

Anyway, why do you want to do that? Can't use a different name for  
dir2/foo, and perhaps import its modules from inside dir1/foo/__init__.py?


-- 
Gabriel Genellina

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


New to group

2008-03-24 Thread pythonnubie
Hi  Everyone

I  am new to programming in general although I  have  read alot and
done alot of experimentation  as well  as researched afew languages
namely java python and visual basic . My conclusion  is that  python
is one of the best because it  eliminates the need to learn about
access  modifiers  and  form handlers so  a user can concentrate
primarliy on the nuts and bolts of the language .

i  have  come across my first exeption using randrange . The exeption
is  no such  attribute  in  module random

platform  is xp  home  and the python  build is activestate 2.5

All help much appreciated !

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


Re: behavior varied between empty string '' and empty list []

2008-03-24 Thread Gabriel Genellina
En Mon, 24 Mar 2008 15:22:43 -0300, Tzury Bar Yochay  
[EMAIL PROTECTED] escribió:

 while I can invoke methods of empty string '' right in typing
 (''.join(), etc.) I can't do the same with empty list

 example:

 a = [1,2,3]
 b = [].extend(a)
 b
 b = []
 b.extend(a)
 b
 [1,2,3]

extend() -like most mutating methods- does not return the list, it returns  
None.
Your empty list grow the 3 additional items, but since there were no  
additional references to it, got destroyed.

 I would not use b = a since I don't want changes on 'b' to apply on
 'a'

Try with b = list(a)

 do you think this should be available on lists to invoke method
 directly?

You already can. Your example is misleading because you used b with two  
meanings.
(Compare the *usage* of each variable/value, not their names). This is  
equivalent to the second part of your example:

py a = [1,2,3]
py b = []
py b.extend(a)
py b
[1, 2, 3]

and this is the first part:

py a = [1,2,3]
py b = []
py c = b.extend(a)
py c
py b
[1, 2, 3]

except that in your original example, the empty list had no name so you  
cannot see how it changed.

-- 
Gabriel Genellina

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


Re: New to group

2008-03-24 Thread Jeff
What does the code look like?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to group

2008-03-24 Thread Mike Driscoll
On Mar 24, 1:53 pm, pythonnubie [EMAIL PROTECTED] wrote:
 Hi  Everyone

 I  am new to programming in general although I  have  read alot and
 done alot of experimentation  as well  as researched afew languages
 namely java python and visual basic . My conclusion  is that  python
 is one of the best because it  eliminates the need to learn about
 access  modifiers  and  form handlers so  a user can concentrate
 primarliy on the nuts and bolts of the language .

 i  have  come across my first exeption using randrange . The exeption
 is  no such  attribute  in  module random

 platform  is xp  home  and the python  build is activestate 2.5

 All help much appreciated !

Please post the code that throws this error along with the entire
traceback.

Thanks,

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


Re: New to group

2008-03-24 Thread pythonnubie
On Mar 24, 11:57 am, Jeff [EMAIL PROTECTED] wrote:
 What does the code look like?

# Random Access
# Demonstrates string indexing
# Michael Dawson - 1/27/03

import random

word = index
print The word is: , word, \n

high = len(word)
low = -len(word)
for i in range(10):
position = random.randrange(low, high)
print word[, position, ]\t, word[position]

raw_input(\n\nPress the enter key to exit.)

The  code is an exerp from  a  chm file . I  am petty sutre I  am
nmot  getting  a  char  map error from  the copy/paste ! it looks
simple enough !

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


Re: New to group

2008-03-24 Thread George Sakkis
On Mar 24, 2:53 pm, pythonnubie [EMAIL PROTECTED] wrote:
 Hi  Everyone

 I  am new to programming in general although I  have  read alot and
 done alot of experimentation  as well  as researched afew languages
 namely java python and visual basic . My conclusion  is that  python
 is one of the best because it  eliminates the need to learn about
 access  modifiers  and  form handlers so  a user can concentrate
 primarliy on the nuts and bolts of the language .

 i  have  come across my first exeption using randrange . The exeption
 is  no such  attribute  in  module random

 platform  is xp  home  and the python  build is activestate 2.5

Welcome aboard!

There's definitely a randrange function in the random module, so
something else must be wrong. To get the most out of this list and
minimize wasted bandwidth, the most effective way usually consists of
copying and pasting:
1. The offending code (or just the relevant part if it's too big).
2. The full traceback of the raised exception.

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


Re: New to group

2008-03-24 Thread Robert Kern
pythonnubie wrote:
 On Mar 24, 11:57 am, Jeff [EMAIL PROTECTED] wrote:
 What does the code look like?
 
 # Random Access
 # Demonstrates string indexing
 # Michael Dawson - 1/27/03
 
 import random

Make sure that you do not have a random.py module in the current directory. 
Python checks the current directory for modules before the standard directories.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth.
   -- Umberto Eco

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


Re: New to group

2008-03-24 Thread pythonnubie

  i  have  come across my first exeption using randrange . The exeption
  is  no such  attribute  in  module random

  platform  is xp  home  and the python  build is activestate 2.5

 Welcome aboard!

 There's definitely a randrange function in the random module, so
 something else must be wrong. To get the most out of this list and
 minimize wasted bandwidth, the most effective way usually consists of
 copying and pasting:
 1. The offending code (or just the relevant part if it's too big).
 2. The full traceback of the raised exception.

 Regards,
 George

Hwere is the complete traceback !  The word is:  index

Traceback (most recent call last):
  File F:\Python25\Lib\site-packages\pythonwin\pywin\framework
\scriptutils.py, line 307, in RunScript
debugger.run(codeObject, __main__.__dict__, start_stepping=0)
  File F:\Python25\Lib\site-packages\pythonwin\pywin\debugger
\__init__.py, line 60, in run
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  File F:\Python25\Lib\site-packages\pythonwin\pywin\debugger
\debugger.py, line 631, in run
exec cmd in globals, locals
  File F:\Documents and Settings\Mark\My Documents\rand.py, line 5,
in module
import random
  File F:\Documents and Settings\Mark\My Documents\random.py, line
13, in module
distributions on the real line:
AttributeError: 'module' object has no attribute 'randrange'

Why  would it say  it can't find the function ?

Mark


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


Re: New to group

2008-03-24 Thread George Sakkis
On Mar 24, 3:03 pm, pythonnubie [EMAIL PROTECTED] wrote:
 On Mar 24, 11:57 am, Jeff [EMAIL PROTECTED] wrote:

  What does the code look like?

 # Random Access
 # Demonstrates string indexing
 # Michael Dawson - 1/27/03

 import random

 word = index
 print The word is: , word, \n

 high = len(word)
 low = -len(word)
 for i in range(10):
 position = random.randrange(low, high)
 print word[, position, ]\t, word[position]

 raw_input(\n\nPress the enter key to exit.)

 The  code is an exerp from  a  chm file . I  am petty sutre I  am
 nmot  getting  a  char  map error from  the copy/paste ! it looks
 simple enough !

It works fine on on Windows with standard Python 2.5. Something is
probably wrong with your ActiveState installation.

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


Re: New to group

2008-03-24 Thread Jeffrey Froman
pythonnubie wrote:

 The exeption
 is  no such  attribute  in  module random

Is your own source file named random.py by chance? If so, rename it, and
be sure to remove the leftover random.pyc file as well.


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

Re: New to group

2008-03-24 Thread Peter Otten
pythonnubie wrote:

 On Mar 24, 11:57 am, Jeff [EMAIL PROTECTED] wrote:
 What does the code look like?
 
 # Random Access
 # Demonstrates string indexing
 # Michael Dawson - 1/27/03
 
 import random
 
 word = index
 print The word is: , word, \n
 
 high = len(word)
 low = -len(word)
 for i in range(10):
 position = random.randrange(low, high)
 print word[, position, ]\t, word[position]
 
 raw_input(\n\nPress the enter key to exit.)
 
 The  code is an exerp from  a  chm file . I  am petty sutre I  am
 nmot  getting  a  char  map error from  the copy/paste ! it looks
 simple enough !

You have probably called your script random.py, and now it imports itself
instead of the random.py module in Python's standard library.

Rename your script to myrandom.py, remove the compiled version random.pyc in
the same folder, and you should be able to run it successfully.

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

Re: New to group

2008-03-24 Thread George Sakkis
On Mar 24, 3:13 pm, pythonnubie [EMAIL PROTECTED] wrote:
   i  have  come across my first exeption using randrange . The exeption
   is  no such  attribute  in  module random

   platform  is xp  home  and the python  build is activestate 2.5

  Welcome aboard!

  There's definitely a randrange function in the random module, so
  something else must be wrong. To get the most out of this list and
  minimize wasted bandwidth, the most effective way usually consists of
  copying and pasting:
  1. The offending code (or just the relevant part if it's too big).
  2. The full traceback of the raised exception.

  Regards,
  George

 Hwere is the complete traceback !  The word is:  index

 Traceback (most recent call last):
   File F:\Python25\Lib\site-packages\pythonwin\pywin\framework
 \scriptutils.py, line 307, in RunScript
 debugger.run(codeObject, __main__.__dict__, start_stepping=0)
   File F:\Python25\Lib\site-packages\pythonwin\pywin\debugger
 \__init__.py, line 60, in run
 _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
   File F:\Python25\Lib\site-packages\pythonwin\pywin\debugger
 \debugger.py, line 631, in run
 exec cmd in globals, locals
   File F:\Documents and Settings\Mark\My Documents\rand.py, line 5,
 in module
 import random
   File F:\Documents and Settings\Mark\My Documents\random.py, line
 13, in module
 distributions on the real line:
 AttributeError: 'module' object has no attribute 'randrange'

 Why  would it say  it can't find the function ?

Because you named your file 'random.py' and it shadows the standard
random module! Change the name to something else, say foo.py, and try
it again.

George

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


Re: New to group

2008-03-24 Thread pythonnubie
On Mar 24, 12:18 pm, George Sakkis [EMAIL PROTECTED] wrote:
 On Mar 24, 3:13 pm, pythonnubie [EMAIL PROTECTED] wrote:





i  have  come across my first exeption using randrange . The exeption
is  no such  attribute  in  module random

platform  is xp  home  and the python  build is activestate 2.5

   Welcome aboard!

   There's definitely a randrange function in the random module, so
   something else must be wrong. To get the most out of this list and
   minimize wasted bandwidth, the most effective way usually consists of
   copying and pasting:
   1. The offending code (or just the relevant part if it's too big).
   2. The full traceback of the raised exception.

   Regards,
   George

  Hwere is the complete traceback !  The word is:  index

  Traceback (most recent call last):
    File F:\Python25\Lib\site-packages\pythonwin\pywin\framework
  \scriptutils.py, line 307, in RunScript
      debugger.run(codeObject, __main__.__dict__, start_stepping=0)
    File F:\Python25\Lib\site-packages\pythonwin\pywin\debugger
  \__init__.py, line 60, in run
      _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
    File F:\Python25\Lib\site-packages\pythonwin\pywin\debugger
  \debugger.py, line 631, in run
      exec cmd in globals, locals
    File F:\Documents and Settings\Mark\My Documents\rand.py, line 5,
  in module
      import random
    File F:\Documents and Settings\Mark\My Documents\random.py, line
  13, in module
      distributions on the real line:
  AttributeError: 'module' object has no attribute 'randrange'

  Why  would it say  it can't find the function ?

 Because you named your file 'random.py' and it shadows the standard
 random module! Change the name to something else, say foo.py, and try
 it again.

 George- Hide quoted text -

 - Show quoted text -

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


Re: Need help calling a proprietary C DLL from Python

2008-03-24 Thread Craig
On Mar 24, 12:27 pm, Craig [EMAIL PROTECTED] wrote:
 On Mar 23, 7:59 pm, Dennis Lee Bieber [EMAIL PROTECTED] wrote:



  On Sun, 23 Mar 2008 14:24:52 -0700 (PDT), Craig [EMAIL PROTECTED]
  declaimed the following in comp.lang.python:

   This dll was designed to be used from either C or Visual Basic 6.

   I have the declare statements for VB6, if that helps.

  Probably not that much -- I'd bet it's full of variant records G

   Based on the results I have so far (and I have tried MANY permutations
   like trying to use the LPSTR for SecKey and PriKey which are returned
   as is TypeDef), it looks like SecKey and PriKey are being used as data
   instead of pointers.

   For this, I try:
   LPSTR = c_char_p
   VmxGet.argtypes = [LPHANDLE, LPSHORT, LPSHORT, LPBSTR, LPSTR, LPBSTR,
   LPSTR]
   SrchKey =
   windll.oleaut32.SysAllocStringByteLen(MSD19DN
   \x00, 41)
   SecKey = create_string_buffer(41)
   SecKey.raw = 1234567890123456789012345678901234567890
   PriKey =
   windll.oleaut32.SysAllocStringByteLen(ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234\x00,
   41)
   TypeDef = create_string_buffer(128)
   TypeDef.raw = X.center(128, X)
   res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
   byref(c_void_p(SrchKey)), SecKey, byref(c_void_p(PriKey)), TypeDef )
   and I get:
   Traceback (most recent call last):
 File C:\temp\vbisam_test_2.py, line 158, in module
   res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
   byref(c_void_p(S
   rchKey)), SecKey, byref(c_void_p(PriKey)), TypeDef )
   WindowsError: exception: access violation reading 0x3433322D

   I notice that SecKey.raw starts with 1234 and the exception address
   is 0x3433322D, which is 432-.

  0x2D is 4 less than the expected 0x31...

   And, changing to:
   VmxGet.argtypes = [LPHANDLE, LPSHORT, LPSHORT, LPBSTR, LPBSTR, LPSTR,
   LPSTR]
   PriKey = create_string_buffer(41)
   PriKey.raw = ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234
   res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
   byref(c_void_p(SrchKey)), byref(c_void_p(SecKey)), PriKey, TypeDef )
   I then get:
   Traceback (most recent call last):
 File C:\temp\vbisam_test_2.py, line 159, in module
   res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
   byref(c_void_p(S
   rchKey)), byref(c_void_p(SecKey)), PriKey, TypeDef )
   WindowsError: exception: access violation reading 0x4443423D

   I notice that PriKey.raw starts with ABCD and the exception address
   is 0x4443423D, which is DBC=.

  ... and 0x3D is 4 less than the expected 0x41

  Which leads me to suspect that BSTR are a structure, not a plain
  string, in which the address given is supposed to be prefaced with a
  length value. IOWs, something like:

  ||--|
  ^^  C-string data
  ||Address to be passed
  |(address - 4) to get to a length count field

  Confirmed:http://msdn2.microsoft.com/en-us/library/ms221069(VS.85).aspx

  (the URL is from HTTP through to the end, including .aspx)

  Creating such may not be difficult -- but passing it to the DLL
  could be. I don't know if ctypes allows pointer arithmetic.

  ctypes OLESTR is a c_wchar_p, but that is still a c-style string with no
  length prefix.

  The only mention of BSTR in the win32 extensions is in text that
  implies that the win32 extension library takes care of converting
  from/to BSTR and Python strings transparently -- but that won't work for
  your third-party library I suspect.

  Might have to beg the author(s) of ctypes to add a BSTR type to the
  list of those supported... as I can find no means of tweaking the
  address computed by byref() to point somewhere into a structure rather
  than the beginning of the structure.

   pk = ctypes.windll.oleaut32.SysAllocStringByteLen(1234567890, 12)
   pk
  1373844
   id(pk)
  18941724
   ctypes.string_at(pk)
  '1234567890'
   ctypes.string_at(pk-4, 20)

  '\x0c\x00\x00\x001234567890\x00\x01\x00\x00\x00\x00'

  Okay, the return value from SysAlloc... IS the integer representing
  the address of a BSTR structure (IE, the address four bytes in from the
  real memory start)... Note how backing up 4 bytes reveals the BSTR
  length field

  What happens if you just pass that item as-is, no byref(), no
  conversion to ctypes pointer types...

  PriKey = ctypes.windll.oleaut32.SysAllocStringByteLen(1234567890, 41)
  SecKey = ctypes.windll.oleaut32.SysAllocStringByteLen(1234567890, 41)

  res = VmxGet(   byref(hwmcb),
  byref(SecIndex),
  byref(Option),
  byref(c_void_p(SrchKey)),
  SecKey,
  PriKey,
  TypeDef )

   PriKey = ctypes.windll.oleaut32.SysAllocStringByteLen(1234567890, 41)
   ctypes.string_at(PriKey, 41)

  

Re: beginners question about return value of re.split

2008-03-24 Thread klaus
On Fri, 21 Mar 2008 13:34:27 -0700, John Machin wrote:

 On Mar 22, 2:53 am, klaus [EMAIL PROTECTED] wrote:
 On Fri, 21 Mar 2008 10:31:20 -0500, Tim Chase wrote:

 ..

 Ok thank you !

 I think I got a bit lost in all the possibilities python has to offer.
 
 IMHO you got more than a bit lost. You seem to have stumbled on a
 possibly unintended side effect of re.split.
 
 What is your underlying goal?
 
 If you want merely to split on '-', use datum.split('-').
 
 If you want to verify the split results as matching patterns (4 digits,
 2 digits, 2 digits), use something like this:
 
 |  import re
 |  datum = '2008-03-14'
 |  pattern = r'^(\d\d\d\d)-(\d\d)-(\d\d)\Z' You may notice two
 differences between my pattern and yours ... 
 |  mobj = re.match(pattern, datum) |  mobj.groups()
 | ('2008', '03', '14')
 
 But what are you going to do with the result? If the resemblance between
 '2008-03-14' and a date is not accidental, you may wish to consider
 going straight from a string to a datetime or date object, e.g.
 
 |  import datetime
 |  dt = datetime.datetime.strptime(datum, '%Y-%m-%d') 
 |  dt
 | datetime.datetime(2008, 3, 14, 0, 0) 
 |  d =
  datetime.datetime.date(dt)
 |  d
 | datetime.date(2008, 3, 14)
 
 HTH,
 John

Ok, sorry for my late reply. I got caught up in a fight with easterbunnys
over some extraordinary large, fruitty and fertile eggs. Some creatures 
take Easter just to serious and it is not even mating season ! Can you 
believe that ?

:-)

Anyway, the underlying goal was to verify user input and to split up the 
date so that I could easily convert it to another format. Among others, 
an url and for a database querry. And I have succeeded in that.

Thank you again; for taking the time to explain - and to question.

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


Re: PyCon video editing

2008-03-24 Thread Mike Driscoll
On Mar 18, 10:09 am, amk [EMAIL PROTECTED] wrote:
 On Mar 17, 10:00 pm, dundeemt [EMAIL PROTECTED] wrote:

  Anyone know who is in charge of this?  I'd like to help out if I
  could.

 I am, but haven't set anything up yet, such as a mailing list or a
 host for the video.
 I'll update the wiki pagehttp://wiki.python.org/moin/PyConRecordingBof
 with news/further developments (you can create a wiki account and
 follow the envelope icon at the upper right
 to be notified of changes via e-mail).

 --amk

Somebody has stuck a few videos on Youtube already: 
http://www.youtube.com/user/pycon08

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


Re: Is this doable

2008-03-24 Thread Tobiah
 I have a little problem. I have a script that is in the scheduler
 (win32). But every now and then I update this script and I dont want
 to go to every computer and update it.

Can't you just put the script on a network share?

Tobiah

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

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


SoC project: Python-Haskell bridge - request for feedback

2008-03-24 Thread Michał Janeczek
Hi,

I am a student interested in participating in this year's SoC.
At http://tsk.ch.uj.edu.pl/~janeczek/socapp.html (and also below
in this email) you can find a draft of my project proposal.

I'd like to ask you to comment on it, especially the deliverables
part. Are you interested in such a project, and if yes, what features
would be most important to you? Is anything missing, or should
something get more priority or attention?

Regards,
Michal


Python-Haskell bridge
=

Description
---

This project will seek to provide a comprehensive, high level (and thus
easy to use) binding between Haskell and Python programming languages.
This will allow using libraries of either side from each language.


Benefits for Python
---

* Robust, high assurance components

It might be beneficial to implement safety-critical components
in a strongly, statically typed language, using Python to keep
them together. Cryptography or authentication modules can be
an example.

* Performance improvements for speed-critical code

Haskell compiled to native code is typically an order of magnitude
faster than Python. Aside from that, advanced language features
(such as multicore parallel runtime, very lightweight threads
and software transactional memory) further serve in improving the
performance. Haskell could become a safe, high level alternative
to commonly used C extensions.

* Access to sophisticated libraries

While its set of libraries is not as comprehensive as that of
Python, Haskell can still offer some well tested, efficient
libraries. Examples might be rich parser combinator libraries
(like Parsec) and persistent, functional data structures.
QuickCheck testing library could also be used to drive analysis
of Python code.


Benefits for Haskell


The project would benefit Haskell by providing it with access to
an impressive suite of libraries. It also has a potential to help
Haskell adoption, by mitigating risk of using Haskell in a project.


Deliverables


* A low level library to access Python objects from Haskell

* A set of low level functions to convert built-in data types
  between Haskell and Python (strings, numbers, lists,
  dictionaries, functions, generators etc.)

* A higher level library allowing easy (transparent) access to
  Python functions from Haskell, and wrapping Haskell functions
  for Python to access

* A way to easily derive conversion functions for user-defined
  data types/objects. Functions derived in such a way should
  work well with both low level and high level access libraries

* Documentation and a set of examples for all of above


Optional goals
--

These are of lower priority, and might require a fair amount of work.
I would like to implement most of them, if technically feasible. If
they don't fit into Summer of Code timeframe, I am planning to finish
afterwards.

* A Python module for accessing functions from Haskell modules without
  manual wrapping (such wrapping should be already easy thanks to the
  high level library). It'd be accomplished through GHC api - if it
  allows it. The Haskell side of the high level library will already
  support such mode of operation

* Extend and refactor the code, to make it support other similar
  dynamic languages. This is a lot of work, and definitely out of
  the scope of Summer of Code project, but some design decisions
  may be influenced by this.


Related projects


They (and quite possibly some others) will be referenced for ideas.

* MissingPy

Provides a one way, low level binding to Python. Some of the code
can be possibly reused, especially data conversion functions. It
doesn't seem to export all features, in particular function
callbacks are not supported

* HaXR

XML-RPC binding for Haskell. It could provide inspiration for
reconciling Haskell and Python type systems, resulting in a
friendly interface

* rocaml

A binding between Ruby and OCaml
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: encoding/decoding issue with python2.5 and pymssql

2008-03-24 Thread Rob Williscroft
Tzury Bar Yochay wrote in news:3a6c32fe-e7c1-4230-882d-efb3415196c1
@b1g2000hsg.googlegroups.com in comp.lang.python:

 for example:
 the value
 'EE604EE3-4AB0-4EE7-AF4D-018124393CD7'
 is represent as
 '\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9\xd7'
 

from uuid import *

u = UUID( bytes = '\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9\xd7')
print u

u = UUID( bytes_le = '\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9\xd7')
print u

The bytes_le version prints: ee604ee3-4ab0-4ee7-af4d-018124393cd7
so I guess, this is what mysql is returning.

http://docs.python.org/lib/module-uuid.html

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Paramiko bugs out on windows 2003 server

2008-03-24 Thread Tarun Kapoor
I am using the paramiko library to pull a data from a server using SFTP.
It works perfect on a windows xp machine but bugs out a windows 2003
server. I get the following error:
Traceback (most recent call last):
  File S:\Temp\ftpBOA.py, line 5, in ?
import paramiko
  File C:\Python23\lib\paramiko\__init__.py, line 69, in ?
from transport import randpool, SecurityOptions, Transport
  File C:\Python23\lib\paramiko\transport.py, line 32, in ?
from paramiko import util
  File C:\Python23\lib\paramiko\util.py, line 31, in ?
from paramiko.common import *
  File C:\Python23\lib\paramiko\common.py, line 98, in ?
from osrandom import OSRandomPool
  File C:\Python23\lib\paramiko\osrandom.py, line 54, in ?
raise ImportError(Cannot find OS entropy source)
ImportError: Cannot find OS entropy source

Anyone knows how to solve it ?
Tarun Kapoor



Disclaimer

This e-mail and any attachments is confidential and intended solely for the use 
of the individual(s) to whom it is addressed. Any views or opinions presented 
are solely those of the author and do not necessarily represent those of 
Waterstone Capital Management, L.P and affiliates. If you are not the intended 
recipient, be advised that you have received this e-mail in error and that any 
use, dissemination, printing, forwarding or copying of this email is strictly 
prohibited. Please contact the sender if you have received this e-mail in 
error. You should also be aware that e-mails are susceptible to interference 
and you should not assume that the contents of this e-mail originated from the 
sender above or that they have been accurately reproduced in their original 
form. Waterstone Capital Management, L.P. and affiliates accepts no 
responsibility for information, or errors or omissions in this e-mail or use or 
misuse thereof. If in doubt, please verify the authenticity with the!
  sender.


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


Reading new mail from outlook

2008-03-24 Thread SPJ
Hi,I am trying to create new tickets in the ticketing system using python. When I receive new email from a particular address, I have to trigger the python script and parse the mail in required format. The main hurdle here is, how to invoke the script on arrival of new mail? I checked the outlook settings and found that it supports only microsoft _vbscript_ and Jscript. Is there any other way? I mean, if I make a daemon, how will it be notified of new mail? Is there any python module that does this? I am not sure if this is the right place to ask this, since it is also a microsoft related question. But any help is appreciated.Thanks,SPJ
  Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reading new mail from outlook using Python

2008-03-24 Thread SPJ
Hi,I am trying to create new tickets in the ticketing system using python. When I receive new email from a particular address, I have to trigger the python script and parse the mail in required format. The main hurdle here is, how to invoke the script on arrival of new mail? I checked the outlook settings and found that it supports only microsoft _vbscript_ and Jscript. Is there any other way? I mean, if I make a daemon, how will it be notified of new mail? Is there any python module that does this? I am not sure if this is the right place to ask this, since it is also a microsoft related question. But any help is appreciated.Thanks,SPJ
  Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.
-- 
http://mail.python.org/mailman/listinfo/python-list

FW:Reading new mail from outlook express using Python

2008-03-24 Thread SPJ
My previous post was not clear, hence resending this.

-
Hi,

I am trying to create new tickets in the ticketing system using python. When I 
receive new email from a particular address, I have to trigger the python 
script and parse the mail  in required format. 

The  main hurdle here is,  how to invoke the script on arrival of new mail? I 
checked the outlook settings and found that it supports only microsoft VB 
script and Jscript. Is there any other way? I mean, if I make a daemon, how 
will it be notified of new mail? Is there any python module that does this? 

I am not sure if this is the right place to ask this, since it is also a 
microsoft related question. But any help is appreciated.

Thanks,
SPJ



  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading new mail from outlook using Python

2008-03-24 Thread Pete Stapley
Well on a FreeBSD/Unix system you can use the .forward to pipe the 
incoming mail for a user to a program. Below is the contents of my 
.forward that invokes procmail.

|/usr/local/bin/procmail -m /path/to/conf/.procmailrc

So I imagine you could do something like this in a .forward.

|/path/myprogram.py

SPJ wrote:
 Hi,

 I am trying to create new tickets in the ticketing system using 
 python. When I receive new email from a particular address, I have to 
 trigger the python script and parse the mail  in required format.

 The  main hurdle here is,  how to invoke the script on arrival of new 
 mail? I checked the outlook settings and found that it supports only 
 microsoft VB script and Jscript. Is there any other way? I mean, if I 
 make a daemon, how will it be notified of new mail? Is there any 
 python module that does this?

 I am not sure if this is the right place to ask this, since it is also 
 a microsoft related question. But any help is appreciated.

 Thanks,
 SPJ


 
 Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try 
 it now. 
 http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ%20
  


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


Re: Shortcutting the function call stack

2008-03-24 Thread Julien
Hi all, and thanks a lot for your answers!

I'll try to explain a bit more what I'm after, and hopefully that will
be clearer. In fact, what I'm trying to do is to hijack (I'm making
up the term) a function:

def hijacker(arg):
if I_feel_its_necessary:
hijack_caller_function_and_make_it_return(1)

def my_function1(arg):
hijacker(something)
... # Continue as normal
return 2

def my_function2(arg):
... # Maybe do some processing here
hijacker(whatever)
... # Continue as normal
return 3


I have some long functions like my_function1 and my_function2 which
I'd like to alter, but I want to keep the alterations as little as as
possible. I'd like the extra behaviour to be handled by 'hijacker' and
let it decide what the caller function should return. Just adding a
call to 'hijacker' in all of these functions would be ideal for me
because that would be quick to modify them and also easier to
maintain, I believe.

If 'hijacker' thinks it's necessary, it would force the caller
function to return a certain
value, otherwise it would let the caller function do its normal
business.

For while I thought I'd make hijacker a decorator:

@hijacker
def my_function(request):


But that wouldn't work, since some functions need to do some
processing before calling the hijacker. Yet, I think a decorator is
systematically called before the function itself so no prior
processing can be done by the function...

Any idea on how to do that, if that's even possible?

Thanks!

Julien

On Mar 25, 2:06 am, [EMAIL PROTECTED] wrote:
 On Mar 24, 9:48 am, Jason [EMAIL PROTECTED] wrote:



  On Mar 24, 5:21 am, Julien [EMAIL PROTECTED] wrote:

   Hello all,

   I would like to do something like:

   def called(arg)
   if arg==True:
   !!magic!!caller.return 1

   def caller(arg)
   called(arg)
   return 2

   Here, the fake !!!magic!!! represents a statement (which I ignore)
   that would make the caller function return a value different from what
   it'd return normally.

   For example, caller(True) would return 1, and caller(False) would
   return 2. The reason I want that is because I don't want the caller
   function to know what's going on in the called function, and be
   shortcut if the called function think it's necessary.

   Would you know if that's possible, and if so, how?

   I've done a bit of research and I think I've found some good pointers,
   in particular using the 'inspect' library:

   import inspect

   def called(arg)
   if arg==True:
   caller_frame = inspect.stack()[1]
   ...

   Here 'caller_frame' contains the frame of the caller function. Now,
   how can I make that frame return a particular value?

   By the way, I'm not really interested in 'called' throwing an
   exception and 'caller' catching it. In fact, I want things to remain
   completely transparent for 'caller'.

   Hope that was clear... :/

   Thanks!

   Julien

  As Steven wrote, it's not very clear.  If we knew the intent of this,
  we could perhaps point you to a more useful, maintainable technique.
  We don't know why you're trying to circumvent the programming language
  in this case.  Any solution that works as you described will probably
  be unportable between the different Pythons (CPython, Jython,
  IronPython, etc).

  Please note that the following code should work, but I've only run it
  through the interpreter in my brain.  My brain's interpreter is full
  of Heisenbugs, so you may need to adjust a few things.  Here's my
  thoughts:

  Given:
  def First( arg ):
  Second( arg )
  return 5

  1)  If you can modify both functions, change the first function to
  return a value in certain circumstances:
  def AltFirst( arg ):
  value = Second( arg )
  if value is not None:  return value
  return 5

  2)  Raise an exception in Second, and catch that exception above
  First:

  class SecondExcept(Exception):
  def __init__(self, value):
  Exception.__init__(self, 'Spam!')
  self.value = value

  def Second(arg):
  if arg == my_conditional_value:
  raise SecondExcept( 5 )

  # The following could even be put in your own function,
  # or in a wrapper or decorator for the First function.
  try:
  myvalue = First( 'Vikings!' )
  except SecondExcept, exc:
  myvalue = exc.value

  When you need to use an exceptional pathway, use an exception.  They
  aren't just for reporting errors.

 Exceptions are a control tool.  There was a 'goto using Exceptions'
 once in the manuals.  I don't see a problem with a local control-flow
 object.  It would appease a number of requests I've read.

 for x:
   for y:
 control.break( 2 )

 if a:
   if b:
 control.fail( 2 )

 so no need to reduplicate:

   else:
 thing()
 else:
   thing()

 if a:
   if b:
 control.mostrecenttest( 0 )

 def f():
   def g():
 control.return( 2 )( early )

 Something tells me generators could solve 

Python 2.2.1 and select()

2008-03-24 Thread Derek Martin
Hi kids!

I've got some code that uses select.select() to capture all the output
of a subprocess (both stdout and stderr, see below).  This code works
as expected on a variety of Fedora systems running Python  2.4.0, but
on a Debian Sarge system running Python 2.2.1 it's a no-go.  I'm
thinking this is a bug in that particular version of Python, but I'd
like to have confirmation if anyone can provide it.

The behavior I see is this:  the call to select() returns:
[file corresponding to sub-proc's STDOUT] [] []

If and only if the total amount of output is greater than the
specified buffer size, then reading on this file hangs indefinitely.
For what it's worth, the program whose output I need to capture with
this generates about 17k of output to STDERR, and about 1k of output
to STDOUT, at essentially random intervals.  But I also ran it with a
test shell script that generates roughly the same amount of output to
each file object, alternating between STDOUT and STDERR, with the same
results.

Yes, I'm aware that this version of Python is quite old, but I don't
have a great deal of control over that (though if this is indeed a
python bug, as opposed to a problem with my implementation, it might
provide some leverage to get it upgraded)...  Thanks in advance for
any help you can provide.  The code in question (quite short) follows:

def capture(cmd):
buffsize = 8192
inlist = []
inbuf = 
errbuf = 

io = popen2.Popen3(cmd, True, buffsize)
inlist.append(io.fromchild)
inlist.append(io.childerr)
while True:
ins, outs, excepts = select.select(inlist, [], [])
for i in ins:
x = i.read()
if not x:
inlist.remove(i)
else:
if i == io.fromchild:
inbuf += x
if i == io.childerr:
errbuf += x
if not inlist:
break
if io.wait():
raise FailedExitStatus, errbuf
return (inbuf, errbuf)

If anyone would like, I could also provide a shell script and a main
program one could use to test this function...

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D



pgpuxR0RACuHg.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: FW:Reading new mail from outlook express using Python

2008-03-24 Thread Grant Edwards
On 2008-03-24, SPJ [EMAIL PROTECTED] wrote:

 I am trying to create new tickets in the ticketing system
 using python. When I receive new email from a particular
 address, I have to trigger the python script and parse the
 mail in required format. 

 The main hurdle here is, how to invoke the script on arrival
 of new mail? I checked the outlook settings and found that it
 supports only microsoft VB script and Jscript. Is there any
 other way? I mean, if I make a daemon, how will it be notified
 of new mail? Is there any python module that does this? 

 I am not sure if this is the right place to ask this, since it
 is also a microsoft related question. But any help is
 appreciated.

You can use Outlook's COM interface from Python.  That allows
you to read messages from a mailbox.  I don't know of any way
to get notified, but you can use the COM interface to poll
the mailbox(es) periodically.

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


Re: Need help calling a proprietary C DLL from Python

2008-03-24 Thread Craig
On Mar 24, 3:45 pm, Craig [EMAIL PROTECTED] wrote:
 On Mar 24, 12:27 pm, Craig [EMAIL PROTECTED] wrote:



  On Mar 23, 7:59 pm, Dennis Lee Bieber [EMAIL PROTECTED] wrote:

   On Sun, 23 Mar 2008 14:24:52 -0700 (PDT), Craig [EMAIL PROTECTED]
   declaimed the following in comp.lang.python:

This dll was designed to be used from either C or Visual Basic 6.

I have the declare statements for VB6, if that helps.

   Probably not that much -- I'd bet it's full of variant records G

Based on the results I have so far (and I have tried MANY permutations
like trying to use the LPSTR for SecKey and PriKey which are returned
as is TypeDef), it looks like SecKey and PriKey are being used as data
instead of pointers.

For this, I try:
LPSTR = c_char_p
VmxGet.argtypes = [LPHANDLE, LPSHORT, LPSHORT, LPBSTR, LPSTR, LPBSTR,
LPSTR]
SrchKey =
windll.oleaut32.SysAllocStringByteLen(MSD19DN
\x00, 41)
SecKey = create_string_buffer(41)
SecKey.raw = 1234567890123456789012345678901234567890
PriKey =
windll.oleaut32.SysAllocStringByteLen(ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234\x00,
41)
TypeDef = create_string_buffer(128)
TypeDef.raw = X.center(128, X)
res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
byref(c_void_p(SrchKey)), SecKey, byref(c_void_p(PriKey)), TypeDef )
and I get:
Traceback (most recent call last):
  File C:\temp\vbisam_test_2.py, line 158, in module
res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
byref(c_void_p(S
rchKey)), SecKey, byref(c_void_p(PriKey)), TypeDef )
WindowsError: exception: access violation reading 0x3433322D

I notice that SecKey.raw starts with 1234 and the exception address
is 0x3433322D, which is 432-.

   0x2D is 4 less than the expected 0x31...

And, changing to:
VmxGet.argtypes = [LPHANDLE, LPSHORT, LPSHORT, LPBSTR, LPBSTR, LPSTR,
LPSTR]
PriKey = create_string_buffer(41)
PriKey.raw = ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234
res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
byref(c_void_p(SrchKey)), byref(c_void_p(SecKey)), PriKey, TypeDef )
I then get:
Traceback (most recent call last):
  File C:\temp\vbisam_test_2.py, line 159, in module
res = VmxGet( byref(hwmcb), byref(SecIndex), byref(Option),
byref(c_void_p(S
rchKey)), byref(c_void_p(SecKey)), PriKey, TypeDef )
WindowsError: exception: access violation reading 0x4443423D

I notice that PriKey.raw starts with ABCD and the exception address
is 0x4443423D, which is DBC=.

   ... and 0x3D is 4 less than the expected 0x41

   Which leads me to suspect that BSTR are a structure, not a plain
   string, in which the address given is supposed to be prefaced with a
   length value. IOWs, something like:

   ||--|
   ^^  C-string data
   ||Address to be passed
   |(address - 4) to get to a length count field

   Confirmed:http://msdn2.microsoft.com/en-us/library/ms221069(VS.85).aspx

   (the URL is from HTTP through to the end, including .aspx)

   Creating such may not be difficult -- but passing it to the DLL
   could be. I don't know if ctypes allows pointer arithmetic.

   ctypes OLESTR is a c_wchar_p, but that is still a c-style string with no
   length prefix.

   The only mention of BSTR in the win32 extensions is in text that
   implies that the win32 extension library takes care of converting
   from/to BSTR and Python strings transparently -- but that won't work for
   your third-party library I suspect.

   Might have to beg the author(s) of ctypes to add a BSTR type to 
   the
   list of those supported... as I can find no means of tweaking the
   address computed by byref() to point somewhere into a structure rather
   than the beginning of the structure.

pk = ctypes.windll.oleaut32.SysAllocStringByteLen(1234567890, 12)
pk
   1373844
id(pk)
   18941724
ctypes.string_at(pk)
   '1234567890'
ctypes.string_at(pk-4, 20)

   '\x0c\x00\x00\x001234567890\x00\x01\x00\x00\x00\x00'

   Okay, the return value from SysAlloc... IS the integer 
   representing
   the address of a BSTR structure (IE, the address four bytes in from the
   real memory start)... Note how backing up 4 bytes reveals the BSTR
   length field

   What happens if you just pass that item as-is, no byref(), no
   conversion to ctypes pointer types...

   PriKey = ctypes.windll.oleaut32.SysAllocStringByteLen(1234567890, 41)
   SecKey = ctypes.windll.oleaut32.SysAllocStringByteLen(1234567890, 41)

   res = VmxGet(   byref(hwmcb),
   byref(SecIndex),
   byref(Option),
   byref(c_void_p(SrchKey)),
   SecKey,
   PriKey,
   TypeDef 

Re: Paramiko bugs out on windows 2003 server

2008-03-24 Thread John Machin
On Mar 25, 7:50 am, Tarun Kapoor [EMAIL PROTECTED] wrote:
 I am using the paramiko library to pull a data from a server using SFTP.
 It works perfect on a windows xp machine but bugs out a windows 2003
 server. I get the following error:
 Traceback (most recent call last):
   File S:\Temp\ftpBOA.py, line 5, in ?
 import paramiko
   File C:\Python23\lib\paramiko\__init__.py, line 69, in ?
 from transport import randpool, SecurityOptions, Transport
   File C:\Python23\lib\paramiko\transport.py, line 32, in ?
 from paramiko import util
   File C:\Python23\lib\paramiko\util.py, line 31, in ?
 from paramiko.common import *
   File C:\Python23\lib\paramiko\common.py, line 98, in ?
 from osrandom import OSRandomPool
   File C:\Python23\lib\paramiko\osrandom.py, line 54, in ?
 raise ImportError(Cannot find OS entropy source)
 ImportError: Cannot find OS entropy source

 Anyone knows how to solve it ?

Here's some meta-help:

paramiko seems to be actively maintained and has a mailing list -- see
http://www.lag.net/mailman/listinfo/paramiko -- consider asking on
that list.

Not only is paramiko open source but also you have the source code on
your machine already -- consider looking at C:\Python23\lib\paramiko
\osrandom.py and see if you can nut out what it is complaining about.
Even if you can't, the experience may help you to better answer
questions from the maintainer, who may well not have a Windows 2003
server box upon which to replicate the problem.

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


Re: Calling a shared library using C types

2008-03-24 Thread Nathan Harmston
Hi,

I know this is a pretty simple question but I've spent a while on this and
can't see whats wrong. I'm trying to access a shared library which I've
created called Simulation.so, its created as such (snip from makefile):

all: simulation

simulation: Simulation.so

Simulation.so: Simulation.o Statistics.o
gcc -shared Simulation.o Statistics.o -L/usr/local/lib -lsbml
-lstdc++ -lm -o Simulation.so

Statistics.o: Statistics.c Statistics.h
gcc -fpic -g -O2 -I/usr/include -c Statistics.c

Simulation.o: Simulation.c
gcc -fpic -g -O2 -I/usr/include  -c Simulation.c

and I can load it properly in python

import ctypes
t = ctypes.CDLL('./Simulation.so')
this works fine, I have a simple function I ve put in for testing which just
returns the integer 4. However when I try to access this function it doesnt
work
t.test()
 File stdin, line 1, in module
  File
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py,
line 325, in __getattr__
func = self.__getitem__(name)
  File
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py,
line 330, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x81e6b0, test): symbol not found

I've tried using
t.__getattr__(test)
but still have the same exception, I've tried loading the library with mode
= RTLD_GLOBAL aswell and still have no luck. As far I as I can see this
should work? But as I am just starting with ctypes I am sure I doing
something sorry very stupid.

Any pointers would be greatly appreciated,

Many thanks in advance,

Nathan


Im hoping python-list is ok for questions regarding ctypes :S
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Shortcutting the function call stack

2008-03-24 Thread John Machin
On Mar 25, 9:05 am, Julien [EMAIL PROTECTED] wrote:
 Hi all, and thanks a lot for your answers!

 I'll try to explain a bit more what I'm after, and hopefully that will
 be clearer. In fact, what I'm trying to do is to hijack (I'm making
 up the term) a function:

 def hijacker(arg):
 if I_feel_its_necessary:
 hijack_caller_function_and_make_it_return(1)

 def my_function1(arg):
 hijacker(something)
 ... # Continue as normal
 return 2


Your end goal (avoiding duplicate code) is laudable. However most folk
manage to do this without needing to invent arcane control structures
like the COME FROM and the COBOL ALTER verb.

def common_code(arg):
if necessary(arg):
return 1
   # assuming None is not a valid return from myfunc1 etc
   return None

def myfunc1(arg):
return_value = common_code(something)
if return_value is not None:
 return return_value
# continue

# Look, Ma! No decorators!

Those functions could be methods of classes, but IMHO you don't need
anything fancier than that.

You mentioned maintainability. To borrow someone else's advice:
Consider that the next person to maintain your code may know where you
live and may possess a chain-saw.

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


Re: Shortcutting the function call stack

2008-03-24 Thread Arnaud Delobelle
On Mar 24, 10:05 pm, Julien [EMAIL PROTECTED] wrote:
 Hi all, and thanks a lot for your answers!

 I'll try to explain a bit more what I'm after, and hopefully that will
 be clearer. In fact, what I'm trying to do is to hijack (I'm making
 up the term) a function:

 def hijacker(arg):
     if I_feel_its_necessary:
         hijack_caller_function_and_make_it_return(1)

 def my_function1(arg):
     hijacker(something)
     ... # Continue as normal
     return 2

 def my_function2(arg):
     ... # Maybe do some processing here
     hijacker(whatever)
     ... # Continue as normal
     return 3

 I have some long functions like my_function1 and my_function2 which
 I'd like to alter, but I want to keep the alterations as little as as
 possible. I'd like the extra behaviour to be handled by 'hijacker' and
 let it decide what the caller function should return. Just adding a
 call to 'hijacker' in all of these functions would be ideal for me
 because that would be quick to modify them and also easier to
 maintain, I believe.

 If 'hijacker' thinks it's necessary, it would force the caller
 function to return a certain
 value, otherwise it would let the caller function do its normal
 business.

 For while I thought I'd make hijacker a decorator:

 @hijacker
 def my_function(request):
 

 But that wouldn't work, since some functions need to do some
 processing before calling the hijacker. Yet, I think a decorator is
 systematically called before the function itself so no prior
 processing can be done by the function...

 Any idea on how to do that, if that's even possible?

Of course it's possible ;), with the combination of an exception and a
decorator.  See example below.  However I would seriously doubt the
maintainability of such practices...

# - hijack.py 
from functools import wraps

class HijackReturn(Exception):
def __init__(self, val):
self.val = val

def hijack(f):
@wraps(f)
def hijacked(*args, **kwargs):
try:
return f(*args, **kwargs)
except HijackReturn, e:
return e.val
return hijacked

@hijack
def foo(x):
x = x + 1
hijacker(x)
return x * 2

def hijacker(x):
if x == 21:
print [Oh no, it's going to be 42!]
raise HijackReturn(41)

# ---

marigold:junk arno$ python -i hijack.py
 foo(10)
22
 foo(20)
[Oh no, it's going to be 42!]
41


HTH

--
Arnaud

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


Beautiful Soup Looping Extraction Question

2008-03-24 Thread Tess
Hello All,

I have a Beautiful Soup question and I'd appreciate any guidance the
forum can provide.

Let's say I have a file that looks at file.html pasted below.

My goal is to extract all elements where the following is true: p
align=left and div align=center.

The lines should be ordered in the same order as they appear in the
file - therefore the output file would look like output.txt below.

I experimented with something similar to this code:
for i in soup.findAll('p', align=left):
print i
for i in soup.findAll('p', align=center):
print i

I get something like this:
p align=leftP4/p
p align=leftP3/p
p align=leftP1/p
div align=centerdiv4b/div
div align=centerdiv3b/div
div align=centerdiv2b/div
div align=centerdiv2a/div

Any guidance would be greatly appreciated.

Best,

Ira











##begin: file.html
html
body

p align=leftP1/p

p align=rightP2/p

div align=centerdiv2a/div
div align=centerdiv2b/div

p align=leftP3/p
div align=rightdiv3a/div
div align=centerdiv3b/div
div align=leftdiv3c/div

p align=leftP4/p
div align=leftdiv4a/div
div align=centerdiv4b/div


/body
/html

##end: file.html


===begin: output.txt===
p align=leftP1/p
div align=centerdiv2a/div
div align=centerdiv2b/div
p align=leftP3/p
div align=centerdiv3b/div
p align=leftP4/p
div align=centerdiv4b/div
===end: output.txt===

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


Re: urllib leaves connections/sockets waiting. BIG problem!!!

2008-03-24 Thread Jonathan Gardner
On Mar 24, 6:57 am, binaryj [EMAIL PROTECTED] wrote:
 hi i am using urllib2 to do some automated web thing.
 basically i hit on sites and check the price what they are offering
 for their product and then decide if i want to lower or increase my
 pricing.so in short i have to hit hundreds of sites!

 for the problem:
 =
 i run 20 threads all do the same stuff. (hit and run :) )
 after around 10-15 hits(per thread) hits the thread does nothing. it
 freezes. slowely but STEADILY all the threads end up with the same
 fate :(

 i did some netstat and found out that the connecton(sockets) the
 program had opened are waiting the CLOSE_WAIT state !!

 netstat -t
 tcp        1      0 192.168.1.2:4882        host-blabla:www
 CLOSE_WAIT
 tcp        1      0 192.168.1.2:4884        host-blabla:www
 CLOSE_WAIT
 tcp        1      0 192.168.1.2:4375        host-blabla:www
 CLOSE_WAIT

 OUTPUT OF PROGRAM:
 THREAD: #Thread-2 getting price from webi-d  7511975 DONE !!!
 THREAD: #Thread-1 getting price from webi-d  4449152 DONE !!!
 THREAD: #Thread-2 getting price from webi-d  7466091 DONE !!!
 THREAD: #Thread-1 getting price from webi-d  8641914 DONE !!!
 THREAD: #Thread-2 getting price from webi-d  7745289 DONE !!!
 THREAD: #Thread-1 getting price from webi-d  6032442 DONE !!!
 THREAD: #Thread-2 getting price from webi-d  8149873 DONE !!!
 no-price-on-page error
 THREAD: #Thread-1 getting price from webi-d  5842934 DONE !!!
 no-price-on-page error
 THREAD: #Thread-2 getting price from webi-d  3385778 DONE !!!
 THREAD: #Thread-1 getting price from webi-d  4610122 DONE !!!
 THREAD: #Thread-2 getting price from webi-d  8641536 DONE !!!
 THREAD: #Thread-1 getting price from webi-d  4219935 DONE !!!
 -and thats it, it freezes. i have waited 1hr the sockets have
 not changed their states! :(

 please help :)

I think we'll need more details before being able to assess what is
wrong. Can you supply some sample code that has the same bug?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Serving another web site which requires authentication

2008-03-24 Thread hasnihon . support
Hi binaryj,

Yeah I feel lucky, thanks...
Well, actually, I want my users to be able to see the auction
information about some vehicles.
It's a Japanese site (https://www.iauc.co.jp/)

I've no experience about the proxy staff, but when I googled I found;
- Twisted
- pyCurl

but, I don't know how to all the proxy thing... especially, serving
the password protected
area of the site..

hoping to feel lucky again :)


On 24 Mart, 23:01, binaryj [EMAIL PROTECTED] wrote:
 ur in luck i am an expert at this!
 tell me the details , site name etc

 you would have to proxy everything, basically the urls in the copied
 page have to be changed to point to ur site.

 its highly possible. a minor adjustment to ur urlconf and it will work.

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


PyGTK localisation on Win32

2008-03-24 Thread jwesonga
I've built an app on linux which we have managed to localise into at
least three languages, the app runs well using this command LANG=fr_FR
python app.py which would translate the app into french. We've tried
the replicate the same principle on windows but so far nothing works,
the app will need to be translated into other languages that have no
locale, in windows is there a way to have Glade load values from a
textfile instead of trying to use the .mo files?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beautiful Soup Looping Extraction Question

2008-03-24 Thread Paul McGuire
On Mar 24, 6:32 pm, Tess [EMAIL PROTECTED] wrote:
 Hello All,

 I have a Beautiful Soup question and I'd appreciate any guidance the
 forum can provide.


I *know* you're using Beautiful Soup, and I *know* that BS is the de
facto HTML parser/processor library.  Buut, I just couldn't help
myself in trying a pyparsing scanning approach to your problem.  See
the program below for a pyparsing treatment of your question.

-- Paul



My goal is to extract all elements where the following is true: p
align=left and div align=center.

from pyparsing import makeHTMLTags, withAttribute, keepOriginalText,
SkipTo

p,pEnd = makeHTMLTags(P)
p.setParseAction( withAttribute(align=left) )
div,divEnd = makeHTMLTags(DIV)
div.setParseAction( withAttribute(align=center) )

# basic scanner for matching either p or div with desired attrib
value
patt = ( p + SkipTo(pEnd) + pEnd ) | ( div + SkipTo(divEnd) + divEnd )
patt.setParseAction( keepOriginalText )

print \nBasic scanning
for match in patt.searchString(html):
print match[0]

# simplified data access, by adding some results names
patt = ( p + SkipTo(pEnd)(body) + pEnd )(P) | \
( div + SkipTo(divEnd)(body) + divEnd )(DIV)
patt.setParseAction( keepOriginalText )

print \nSimplified field access using results names
for match in patt.searchString(html):
if match.P:
print P -, match.body
if match.DIV:
print DIV -, match.body

Prints:

Basic scanning
p align=leftP1/p
div align=centerdiv2a/div
div align=centerdiv2b/div
p align=leftP3/p
div align=centerdiv3b/div
p align=leftP4/p
div align=centerdiv4b/div

Simplified field access using results names
P - P1
DIV - div2a
DIV - div2b
P - P3
DIV - div3b
P - P4
DIV - div4b
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why I hate lambdas (Re: Do any of you recommend Python as afirst programming language?)

2008-03-24 Thread Terry Reedy

Arnaud Delobelle [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
From what I remember when I looked at the source: stack frames execute
code objects, not functions.  They don't know what function has
spawned them, only what code object they are executing.  In fact when
one thinks of it, it makes more sense for code objects to have a name
(taken from the def statement) than for function objects, as there is
exactly one code object for every def statement.

This is what I tried to say before.  Function objects have the attributes 
needed to call the code.  Code objects have attributes needed to execute 
the code.  Both have a name for str() and repr().

tjr



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


Re: New to group

2008-03-24 Thread pythonnubie
On Mar 24, 12:18 pm, George Sakkis [EMAIL PROTECTED] wrote:
 On Mar 24, 3:13 pm, pythonnubie [EMAIL PROTECTED] wrote:





i  have  come across my first exeption using randrange . The exeption
is  no such  attribute  in  module random

platform  is xp  home  and the python  build is activestate 2.5

   Welcome aboard!

   There's definitely a randrange function in the random module, so
   something else must be wrong. To get the most out of this list and
   minimize wasted bandwidth, the most effective way usually consists of
   copying and pasting:
   1. The offending code (or just the relevant part if it's too big).
   2. The full traceback of the raised exception.

   Regards,
   George

  Hwere is the complete traceback !  The word is:  index

  Traceback (most recent call last):
    File F:\Python25\Lib\site-packages\pythonwin\pywin\framework
  \scriptutils.py, line 307, in RunScript
      debugger.run(codeObject, __main__.__dict__, start_stepping=0)
    File F:\Python25\Lib\site-packages\pythonwin\pywin\debugger
  \__init__.py, line 60, in run
      _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
    File F:\Python25\Lib\site-packages\pythonwin\pywin\debugger
  \debugger.py, line 631, in run
      exec cmd in globals, locals
    File F:\Documents and Settings\Mark\My Documents\rand.py, line 5,
  in module
      import random
    File F:\Documents and Settings\Mark\My Documents\random.py, line
  13, in module
      distributions on the real line:
  AttributeError: 'module' object has no attribute 'randrange'

  Why  would it say  it can't find the function ?

 Because you named your file 'random.py' and it shadows the standard
 random module! Change the name to something else, say foo.py, and try
 it again.

 George- Hide quoted text -

 - Show quoted text -

Hi that was the problem  I shoaswoed the  random  module .

Thanks to  everyone for  their support  !

Mark

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


  1   2   >