Re: post xml payload with urllib

2007-08-14 Thread mirandacascade
On Aug 14, 11:57 am, brad [EMAIL PROTECTED] wrote:
 Has anyone sent an xml payload via post using urllib?

Haven't used urllib, but have used urllib2 to do a POST.

Might something like this work...

import urllib2

logon_request = LoginRequest
passwordthe_password/password
userthe_user/user
 /LoginRequest

req = urllib2.Request(https://127.0.0.1/api/version/xml;,
data=logon_request)
openObj = urllib2.urlopen(req)
response = openObj.read()




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


socket module - recv() method

2007-04-30 Thread mirandacascade
Currently using the following technique in serveral client
applications to send a request message and receive a response:

import socket
bufferSize = 50
connectionHandle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connectionHandle.connect(sa)
connectionHandle.sendall(requestMessage)
fullResponse = ''
# use while loop in case the entire response not sent in one chunk
while (1):
response = connectionHandle.recv(bufferSize)
fullResponse = fullResponse + response
if fullResponse.find(endOfMessageText) != -1:
break

where:
sa = 2-element tuple; 1st elem is string denoting ip address; 2nd elem
is int denoting port
requestMessage = string containing request message
endOfMessageText = string that unambiguously denotes the end of
response message

All of the client apps on which this technique is employed are very
predictable in the sense that  the client apps always know in advance
the value of endOfMessageText.

Questions:
1) is it theoretically possible that a client app will want to send a
request and receive a response where the response message does not
have something that unambigusously marks its end?
2) if so, are there any best-practices techniques for constructing the
code such that the client app knows that there is nothing else in the
response message?

Thank you.

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


SSLCrypto package

2007-04-18 Thread mirandacascade
When I review:
 - the site that describes the SSLCrypto package:
  http://www.freenet.org.nz/python/SSLCrypto/
 - the documention for SSLCrypto:
  http://www.freenet.org.nz/python/SSLCrypto/Doco/
 - the examples provided
  http://www.freenet.org.nz/python/SSLCrypto/#examples

It appears as though:
a) SSLCrypto package replaces ezPyCrypto package
b) the ezPyCrypto package provided a wrapper for the PyCrypto package
c) most of the heavy lifting in the SSLCrypto package happens in the
key class

Since SSLCrypto replaced ezPyCrypto and since ezPyCrypto provides a
wrapper for PyCrypto, I guessed (perhaps incorrectly) that one can use
SSLCrypto to accomplish the functions that can be accomplished in
PyCrypto package.  I looked at the documentation for all of SSLCrypto
in general, and for the key() class in particular, yet I am unable to
determine from the material that I reviewed whether certain
functionality can be accomplished in SSLCrypto, specifically:
a) can one use the SSLCrypto package to perform an HMAC message digest
calculation (accomplished in PyCrypto package via Crypto.Hash.HMAC
class)?
b) can one use the SSLCrypto package to perform an SHA256 hash
(accomplished in PyCrypto package via Crypto.Hash.SHA256 class)?

Thank you.

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


on which site or Usenet group should this question be posted?

2007-01-14 Thread mirandacascade
Operating system: Win XP
Version of Python: 2.4

I recognize that this question is not about Python...it has only a
tangential Python connection.  I'm using a Python package to run a
process; that process is issuing an error, and I'm hoping that someone
on this site can point me to the site that has the appropriate
expertise.

Situation is this:
1) using win32com.client.Dispatch to work with the MSXML2.XMLHTTP COM
object
2) I use the open() method of the COM object and specify a POST, then
I use the send() method of the COM object
3) when the url is an http url, able to send and then check the
responseText property without problems
4) when the url is an https url, the open() method works, but when the
send() method is invoked, it raises an exception with the error
message: the download of the specified resource has failed
5) when I use Google with searches such as XMLHTTP, https,
download of the specified resource, I see that other people are
experiencing the issue, but I didn't see any solutions, nor did I see
whether there was a site (perhaps a Usenet group) on which it would
make sense to post this issue

Eventually, I want to learn whether the XMLHTTP COM object can work
with https url's, but what I'm hoping to learn from this post is advice
as to which site I should post this question so that it might be read
by folks with the appropriate subject-matter expertise.

Thank you.

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


Re: AES256 in PyCrypto

2007-01-07 Thread mirandacascade

Marc 'BlackJack' Rintsch wrote:

 `a` must be of length 32 for AES256.  And the length of `plainText` must
 be a multiple of 16 because it's a block cypher algorithm.

Thank you.  I have some follow up questions and 1 tangential question.

Follow up question:
Would it be correct to infer that:
 a) the AES.pyd extension module (plus whatever additional files within
the PyCrypto package that it uses) has the capability to perform AES256
encryption?
 b) the AES256 encryption happens based on the characteristics of the
input to the new() method...if the first argument has a length of 32,
the result will be AES256-style encryption?
 c) will AES256-style encryption also happen if the first argument to
the new() method has a length that is a multiple of 32, e.g. 64?

Tangential question:
Is there functionality available (either in the PyCrypto package or
some other package) that generates an initialization vector that can be
used as input to the new() method?  What prompts this question is that
the original posting referenced a snippet of C# code; some other
related snippets I saw seemed to suggest that:
a) a RijndaelManaged() class gets instantiated
b) that class has a GenerateIV() method which appears to populate
someting in a IV property
c) the application that was employing the AES256 encryption made use of
the left-most 16 characters of the IV property
So, I was curious whether something analgous exists in the Python
world.

Thank you.

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


Re: AES256 in PyCrypto

2007-01-07 Thread mirandacascade
Sebastian 'lunar' Wiesner wrote:

 Since you are apparently unable to read to docstrings of this module, I
 will give you a short hint: yes, pycrypto supports AES with 256 bit
 keys.
Thank you for the information.

The material I consulted was:
a) the PyCrypto manual: http://www.amk.ca/python/writing/pycrypt/
b) the .py files that shipped with the PyCrypto package

Is a docstring is the text between the three consecutive quote
characters in a .py file?  The reason for the question is that I looked
at the .py files that shipped with PyCrypto.  Of the various .py files
that shipped with PyCrypto, there were two files (both __init__.py)
that contained information seemed to pertain to AES.  The stuff between
the 3 consecutive quote chars in:
  Crypto.__init__.py
  Crypto.Cipher.__init__.py
make reference to AES, but I wasn't able to determine from what I read
if that was AES256.
Which .py file contain the docstrings that flesh out the information
summarized in the short hint?

Can docstrings be embedded within the .pyd extension modules as well?
Does the AES.pyd extension module have docstrings?  How does one view
the docstrings in a .pyd file?  When I reference AES from the
interactive of Pythonwin:
 from Crypto.Cipher import AES
 x = AES.new(
As soon as I type the '(' character, the IDE displays:
new(key, [mode], [IV]): Return a new AES encryption object

then when x gets instantiated, and the encrypt method gets called...
 x.encrypt(
As soon as I type the '(' character, the IDE displays:
Encrypt the provided string of binary data

I'm guessing that what the IDE is displaying is the first line of what
may be multiple-line docstring that is embedded within the .pyd
extension module?  Might there be more lines in the docstring?

Thank you.

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


AES256 in PyCrypto

2007-01-06 Thread mirandacascade
Attempting to determine whether the PyCrypto package has the capability
to perform AES256 encryption.  I received the following C# snippet:

CryptoProvider provider = new CryptoProvider();
Encrypted_Type password = new Encrypted_Type();
password.EncryptedData = new EncryptedDataType();
password.EncryptedData.EncryptionMethod = new EncryptionMethodType();
password.EncryptedData.EncryptionMethod.Algorithm = AES256-cbc;

and I was told that it was the setup code for code that later on
performs AES256 encryption.  I'm assuming that setting the Algorithm
property is what informs the system as to the type of encryption to
perform.  I included the above snippet as a reference point, because
I'm attempting to understand how to do something equivalent in Python.

Would the following Python code perform AES256 encryption on plainText
from Crypto.Cipher  import AES
x = AES.new(a, AES.MODE_CBC, iv)
x.encrypt(plainText)

assuming:
a = the key value
iv = an initialization vector
?

If the above Python code does not perform AES256 encryption:
a) is there functionality within PyCrypto that allows one to perform
AES256 encryption?
b) if such functionality does not exist in PyCrypto, does it exist in
some other Python package?

Operating System: Windows XP
Vsn of Python: 2.4

Thank you.

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


terminology question - foreign function library

2006-12-24 Thread mirandacascade
I am prompted to make these inquiries after seeing the following link
to ctypes:

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

in which ctypes is described as a foreign function library.

What is the definition of foreign function library?
Is the concept different from a package?
Is the concept different from a module?

Thank you.

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


httplib and socket.getaddrinfo

2006-12-22 Thread mirandacascade
I noticed the following lines from the connect() method of the
HTTPConnection class within httplib:

for res in socket.getaddrinfo(self.host, self.port, 0,
  socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res

This led me to the docs that describe the socket.getaddrinfo() method:

http://www.python.org/doc/2.4.1/lib/module-socket.html

Which leads me to these questions:
1) Is it correct to infer from the Resolves the host/port argument,
into a sequence of 5-tuples that contain all the necessary argument for
the sockets manipulation description in the docs (in particular the
reference to 'sequence of 5-tuples') that a single host/port
combination may be associated with multiple sets of address
information?

2) In the very limited applications on which I've used
socket.getaddrinfo(), each a host/port combination that my application
passes to socket.getaddrinfo() has always returned a 1-entry list where
the list is a 5-tuple, in other words, each host/port combination has
always been associated with one set of address information.  Can
someone point me to a host/port combination that, when passed to
socket.getaddrinfo() will result in socket.getaddrinfo() returning a
list of  1 entry, where each entry is a 5-tuple?

Thank you.

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


using methods base64 module in conjunction with Crypto.Hash.SHA256

2006-12-19 Thread mirandacascade
I am attempting to implement a process, and I'm pretty sure that a
major roadblock is that I do not understand the nomenclature.  The
specs indicate that the goal is to calculate a message digest using an
SHA-256 algorithm.  There are 2 examples included with the specs.  The
label on the 2 examples are: 'HMAC samples'.  In both examples, the
message on which the digest is to be calculated is (the 33 chars within
the quotes):

'This is a test of VISION services'

In the first example, the value labeled 'Shared key' is the 44
characters within the quotes:
'6lfg2JWdrIR4qkejML0e3YtN4XevHvqowDCDu6XQEFc='
and the value labeled 'Base64 Message Hash' is the 44 characters within
the quotes:
'KF7GkfXkgXFNOgeRud58Oqx2equmKACAwzqQHZnZx9A='

In the second example, the value labeled 'Shared key' is the 44
characters within the quotes:
'jcOv3OBKVNBT8Zk+ZFacrDYNsKlm3D8TGGJyXti//p4='
and the value labeled 'Base64 Message Hash' is the 44 characters within
the quotes:
'XhqneGN0x5I8JVvatXO9z0EBQRre3svFVc+q2lLE3Ik='

My interpretation of the first example is this: when you use an SHA-256
algorithm to calculate a message digest on the message 'This is a test
of VISION services' where the key is
'6lfg2JWdrIR4qkejML0e3YtN4XevHvqowDCDu6XQEFc=', the result should be:
'KF7GkfXkgXFNOgeRud58Oqx2equmKACAwzqQHZnZx9A=' .

Operating system: Win XP
Version of Python: 2.4 (with PyCrypto package installed)

Interactive window of Pythonwin displays how I thought one might
implement the process.

 from Crypto.Hash import SHA256
 import base64
 digestStr = 'This is a test of VISION services'
 from Crypto.Hash import HMAC
 samp1Key = '6lfg2JWdrIR4qkejML0e3YtN4XevHvqowDCDu6XQEFc='
 samp1CalcDigest = HMAC.new(samp1Key, digestStr, SHA256)
 samp1Hash = base64.b64encode(samp1CalcDigest.digest())
 samp1Hash
'35RYYwgt7Bp1Dj9onZiIkSz1PxgKM9UYXCgxlDdWGkA='
 samp2Key = 'jcOv3OBKVNBT8Zk+ZFacrDYNsKlm3D8TGGJyXti//p4='
 samp2CalcDigest = HMAC.new(samp2Key, digestStr, SHA256)
 samp2Hash = base64.b64encode(samp2CalcDigest.digest())
 samp2Hash
'RtmPKhflZ/BX3yrhl83pDsdCR5A2kwKP6dVnAyBl9tc='


I was hoping that samp1Hash and samp2Hash would be the same as the
values labled 'Base64 Message Has' in the examples...they are not the
same.

My questions are:
1) Given the terminology identified above, do you think my
interpreation of the first example is accurate? If not, what is a more
accurate interpretation?
2) If the interpretation of the first example is on target, do you see
anything above in the use of the SHA256, HMAC and base64
classes/methods that indicates that I did not correctly implement the
process?  


Thank you.

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


sha, PyCrypto, SHA-256

2006-12-16 Thread mirandacascade
Operating system: Win XP
Vsn of Python: 2.4

Situation is this: Required to calcluate a message digest.  The process
for calcluating the digest must use an SHA-256 algorithm.

Questions:
1) Is it correct that the sha module comes with python 2.4?
2) Is it correct that the sha module that ships with python 2.4 does
NOT have the SHA-256 capability as part of the module?
3) It looks like PyCrypto is a package that, among other things,
permits one to calculate a message digest using an SHA-256
algorithm...is that correct?
4) It looks like there are a couple couple possibilities available for
the download...either download the source code and run the setup which
(I'm assuming) compiles the various extension modules, or download the
pycrypto-2.0.1.win32-py2.4.zip which extracts out to a .exe; when one
runs the just-extracted .exe, it installs the stuff on one's
workstation.  I'm leaning toward the second option because it seems
like most of the work has been done for me.  A quick search on this
site didn't turn up anything that suggested there were problems with
running the installer.  So, my question is this: are you aware of any
problems running the installer?
5) Besides PyCrypto, are there any other Python packages that permit
one to calculate a message digest using an SHA-256 algorithm?

Thank you.

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


inquiry about installing Python 2.5

2006-12-16 Thread mirandacascade
Apologies in advance for what I'm sure seems like a trivial question.

Operating system: Win XP
Current version of Python: 2.4

If possible, I would like to have both Python 2.4 and Python 2.5
installed on my workstaiton.  I downloaded the .msi for Python 2.5 from
the python.org site. If I run the 2.5 installer, will it give me the
option of keeping Python 2.4 installed on my workstation?

Thank you.

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


elementtree terminology + tangential questions

2006-11-04 Thread mirandacascade
Was prompted to ask these questions when reading the following link:

http://effbot.org/zone/element-infoset.htm#mixed-content

provides a clear explanation of what the tail member is in the
elementtree package.

Questions:
1) In the xml world, is the text between an element's end tag and the
next tag referred to as the tail?
2) None of the xml documents to which I've had exposure (a very, very
small set) have had text between an element's end tag and the next tag,
hence the following question: are there some 'best practices' advice
available to help one decide when it's a good idea to put text between
an element's end tag and the next tag as opposed to putting text in the
text property of an element?
3) Are these questions appropriate for the comp.lang.python group, or
should they be directed to a different group?

Thank you.

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


ElementSOAP tutorial / HTTPClient

2006-10-22 Thread mirandacascade
Operating system: Windows XP Home
Version of Python: 2.4

While looking through the tutorial on ElementSOAP at the following
link:

http://effbot.org/zone/element-soap.htm

I observed sample code that included:

from HTTPClient import HTTPClient

When I get into Pythonwin and attempt the import statement above:

 from HTTPClient import HTTPClient
Traceback (most recent call last):
  File interactive input, line 1, in ?
ImportError: No module named HTTPClient

In addition:
1) a case-insensitive search for any files with 'HTTPClient' where the
search begins in the c:\python24\ and includes all sub-folders results
in a: Search is complete. There are not results to dsiplay. message
2) a search of this Google group for HTTPClient didn't result in any
links that appeared to point me to where I could find a package that
includes HTTPClient
3) a search in the python.org home page for HTTPClient didn't result in
any links that appeared to point me to where I could find a package
that includes HTTPClient

I noticed that there is a file httplib.py in which the docstring begins
HTTP/1.1 client library, but I couldn't figure out whether what was
in httplib.py replaced HTTPClient.py, and if so, how.

So, my questions are:
1) is there a package available which, when installed, will allow the

from HTTPClient import HTTPClient

statement to execute without ImportError?

2) how should I have constructed my searches when attempting to resolve
this issue such that I wouldn't have had to post this question?

Thank you.

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


Re: win32com.client.Dispatch - understanding error messages

2006-07-18 Thread mirandacascade
Duncan Booth wrote:
 wrote:

 Does using an absolute URL for the url parameter help any? You've specified
 a relative URL (i.e. the folder 12.5.81.49 under the current location).

I don't know the answer to that question.  I know that when I'm on the
same workstation and I copy/paste the string that is the url parameter
into my browser and press Enter, that a reply appears within the
browser, and that reply has content that suggests that the browser app
was able to 'talk' to an application on the other end.  The error
message being received in reply to the open method make me think that
the open method wasn't able to talk to any app on the other end.  I'm
not sure what can be inferred from that observation other than the url
parameter appears to be valid when it is used in a browser application.

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


Re: win32com.client.Dispatch - understanding error messages

2006-07-18 Thread mirandacascade

Duncan Booth wrote:
 Are you really sure that the browser isn't making guesses about what you
 meant and correcting the error for you? Does what remains in the address
 bar when the page is retrieved really match *exactly* what you copied and
 pasted?

Thank you for that pointer.  The answer is: no, it does not match
exactly.  The browser did indeed, as you surmised, make a guess and
correct the error.  The browser added 'http://' to the beginning.  When
'http://' gets added to the beginning of the url parameter, all is well.

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


win32com.client.Dispatch - understanding error messages

2006-07-17 Thread mirandacascade
O/S : Win2K
vsn of Python: 2.4

Hoping to find information that provide information about error
messages being encountered.

Pythonwin session:

 import win32com.client
 blah = win32com.client.Dispatch('MSXML2.XMLHTTP')
 blah.open(POST, 12.5.81.49/crg_cbsil_vtest_52/crg.aspx, 0)
Traceback (most recent call last):
  File interactive input, line 1, in ?
  File COMObject MSXML2.XMLHTTP, line 4, in open
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None,
0, -2147467259), None)

I tried various combinations in Google involving
win32com.client.Dispatch, MSXML2, XMLHTTP and the 2 different
error codes: -2147352567 and -2147467259.  So far, I haven't been able
to locate anything that has helped me zero in on the error.

The fact that no error was issued after the blah = ... statement plus
the fact that as soon as I typed the '(' character after blah.open,
that the arguments for the open method were displayed; those two things
make me think that the COM object is installed/registered on the
workstation.  Is that a reasonable conclusion?

I observed that there are a few other similarly named objects/methods,
so I tried them as well.  The error messages reference some different
dll's, but those error message seemed as inscrutable as the first set
of error messages above.

 blah = win32com.client.Dispatch('MSXML2.XMLHTTP.4.0')
 blah.open(POST, 12.5.81.49/crg_cbsil_vtest_52/crg.aspx, 0)
Traceback (most recent call last):
  File interactive input, line 1, in ?
  File COMObject MSXML2.XMLHTTP.4.0, line 4, in open
com_error: (-2147352567, 'Exception occurred.', (0, 'msxml4.dll',
'System error: -2147012890.\r\n', None, 0, -2147012890), None)

and

 blah = win32com.client.Dispatch('MSXML2.ServerXMLHTTP')
 blah.open(POST, 12.5.81.49/crg_cbsil_vtest_52/crg.aspx, 0)
Traceback (most recent call last):
  File interactive input, line 1, in ?
  File COMObject MSXML2.ServerXMLHTTP, line 4, in open
com_error: (-2147352567, 'Exception occurred.', (0, 'msxml3.dll',
'Unspecified error\r\n', None, 0, -2147467259), None)

Also tried varying the 3rd argument...instead of using 0 to represent
False, I tried:

 False
False
 blah = win32com.client.Dispatch('MSXML2.XMLHTTP')
 blah.open(POST, 12.5.81.49/crg_cbsil_vtest_52/crg.aspx, False)
Traceback (most recent call last):
  File interactive input, line 1, in ?
  File COMObject MSXML2.XMLHTTP, line 4, in open
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None,
0, -2147467259), None)

So, if possible, it would be nice to know two different types of
things:
1) what steps to take to correct these errors
2) where one can locate information about these types of errors

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


insert method in ElementTree

2006-07-16 Thread mirandacascade
O/S: Win2K
Vsn of Python: 2.4

Example:

a
  b createAnotherWhenCondition=x
ctext for c/c
dtext for d/d
  /b
  e
ftext for f/f
gtext for g/g
  /e
  h
itext for i/i
j createAnotherWhenCondition=y
  ktext for k/k
  ltext for l/l
/j
mtext for m/m
  /h
/a

Python script reads XML document above into ElementTree. The script
outputs an XML document that is based on the XML document above.  The
output XML will contain all of the elements in the XML document above.
If there is a parent element that does not have the
createAnotherWhencondition attribute, then that element and its
descendants will be part of the output XML.  If there is a parent
element with atribute createAnotherWhenCondition and that condition is
true, then the output XML should contain another instance of the parent
element below the original instance.  For example if x were true when
the script ran, the output XML document would be:

a
  b
ctext for c/c
dtext for d/d
  /b
  b
ctext for c/c
dtext for d/d
  /b
  e
ftext for f/f
gtext for g/g
  /e
  h
itext for i/i
j
  ktext for k/k
  ltext for l/l
/j
mtext for m/m
  /h
/a

The example attempts to illustrate that the createAnotherWhenCondition
attribute may appear in parent elements that are at different levels in
the hierarchy; the b element is at the 2nd level in the hierarchy,
and the j element is at the 3rd level.  There will never be
'nesting', i.e. a parent element with the
createAnotherWhenCondition attribute that is a descendant of a parent
element with a createAnotherWhenCondition attribute.

I'm pretty sure I can figure out how to create the output XML by
creating a second XML document.  It would be created by iterating
through the input XML.  When a new element is encountered, an element
or subelement would be created in the output XML.  When a parent
element with the createAnotherWhenCondition is encountered and that
condition is true, I think I can figure out how to propagate another
instance of that parent element and all its descendants.

My request for advice is this: instead of creating a second XML
document that represents the output, would it be possible to expand the
input XML document as needed?  I was thinking that the program could
iterate through all the elements.  As it is iterating, it would check
for the createAnotherWhenCondition attribute.  If encountered and if
the condition were true, the program would:
- make a copy of the parent element (perhaps with copy.copy)
- use the insert method to insert the just-created copy
Where I'm struggling is figuring out what the index argument should
be in the insert method.  Using the example above

# assume rootElement is the root of the input XML
xList = rootElement.getiterator()
idx = 0
for x in xList:
# mix of pseudo-code and Python code
if (this element has createAnotherWhenCondition attribute)
and
 (y is true):
jcopy = copy.copy(x)
??.insert(??, jcopy)
idx = idx + 1

If the program were run when y was true, then I believe it would
encounter the j element when idx has a value of 9.  Conceptually, I
think that jcopy should be inserted after the j element and before
the m element.  But I'm not sure that 9 (the index in the list
created from rootElement.getiterator()) has any relevance for this
insert task.  Assuming that I want to insert jcopy after the j
element and before the m element:
a) would the insert need to be done relative to the h element, which
is the parent of j
b) if so, would the index argument in the insert method be relative
index within the h element?

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


request for advice - possible ElementTree nexus

2006-07-04 Thread mirandacascade
Situation is this:
1) I have inherited some python code that accepts a string object, the
contents of which is an XML document, and produces a data structure
that represents some of the content of the XML document
2) The inherited code is somewhat 'brittle' in that some well-formed
XML documents are not correctly processed by the code; the brittleness
is caused by how the parser portion of the code handles whitespace.
3) I would like to change the code to make it less brittle.  Whatever
changes I make must continue to produce the same data structure that is
currently being produced.
4) Rather than attempt to fix the parser portion of the code, I would
prefer to use ElementTree.  ElementTree handles parsing XML documents
flawlessly, so the brittle portion of the code goes away.  In addition,
the ElementTree model is very sweet to work with, so it is a relatively
easy task using the information in ElementTree to produce the same data
structure that is currently being produced.
5) The existing data structure--the structure that must be
maintained--that gets produced does NOT include any {xmlns=whatever}
information that may appear in the source XML document.
6) Based on a review of several posts in this group, I understand why
ElementTree hanldes xmlns=whatever information the way it does.  This
is an oversimplification, but one of the things it does is to
incorporate the {whatever} within the tag property of the element and
of any descendent elements.
7) One of the pieces of information in the data structure that gets
produced by this code is the tag...the tag in the data structure should
not have any xmlns=whatever information.

So, given that the goal is to produce the same data structure and given
that I really want to use ElementTree, I need to find a way to remove
the xmlns=whatever information.  It seems like there are 2 general
methods for accomplishing this:
1) before feeding the string object to the ElementTree.XML() method,
remove the xmlns=whatever information from the string.
2) keep the xmlns=whatever information in the string that feeds
ElementTree.XML(), but when building the data structure, ensure that
the {whatever} information in the tag property of the element should
NOT be included in the data structure.

My requests for advice are:
a) What are the pros/cons of each of the 2 general methods described
above?
b) If I want to remove the xmlns information before feeding it to the
ElementTree.XML() method, and I don't want to be aware of what is to
the right of the equal sign, what is the best way to remove all the
substrings that are of the form xmlns=whatever?  Would this require
learning the nuances of regular expressions?
c) If I want to leave the xmlns information in the string that gets fed
to ElementTree.XML, and I want to remove the {whatever} from the tag
before building the data structure, what is the best way to find
{whatever} from the tag property...is this another case where one
should be using regular expressions?

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


Amara installation

2006-06-19 Thread mirandacascade
O/S WinXP Home
Vsn of Python: 2.4

Wish to install Amara.  Using amara-allinone-1.0.win32-py2.4.exe
(2965KB)

Forder structure before installation:

c:
  python24
DLLs
Doc
Include
Lib
  site-packages
[previously installed stuff]
libs
scripts
tcl
tools

When I run install, the install program indicates:

Python directory: c:\python24\
Installation directory: c:\python24\lib\site-packages\

After install, folder structrue is:

Vsn of Python: 2.4

Wish to install Amara.  Using amara-allinone-1.0.win32-py2.4.exe
(2965KB)

Forder structure after installation:

c:
  python24
DLLs
Doc
Include
Lib
  site-packages
[previously installed stuff]
libs
python24 --
  lib --
site-packages--  new amara files/folders appear
  amara   --  to be installed here
  ft   --
scripts--
share  --
scripts
tcl
tools

I was expecting the new amara files/folders to be installed within the
existing c:\python24\ folder structure...wasn't expecting it to create
a new ...\python24\ folder within the parent ...\python24\ folder.

My questions:
1) has anyone else observed this when installing?
2) should I move the newly installed files/folders into the
previously-existing folder structure?  as long as I don't remove
files/folders, is there any risk of causing a previously installed site
package that worked to no longer work?

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


the tostring and XML methods in ElementTree

2006-05-07 Thread mirandacascade
O/S: Windows XP Home
Vsn of Python: 2.4

Copy/paste of interactive window is immediately below; the
text/questions toward the bottom of this post will refer to the content
of the copy/paste

 from elementtree import ElementTree
 beforeRoot = ElementTree.Element('beforeRoot')
 beforeCtag = ElementTree.SubElement(beforeRoot, 'C')
 beforeCtag.text = 'I\x92m confused'
 type(beforeCtag.text)
type 'str'
 print beforeCtag.text
I'm confused
 resultToStr = ElementTree.tostring(beforeRoot)
 resultToStr
'beforeRootCI#146;m confused/C/beforeRoot'
 afterRoot = ElementTree.XML(resultToStr)
 afterCtag = afterRoot[0]
 type(afterCtag.text)
type 'unicode'
 print afterCtag.text
I?m confused


I wanted to see what would happen if one used the results of a tostring
method as input into the XML method.  What I observed is this:
a) beforeCtag.text is of type type 'str'
b) beforeCtag.text when printed displays: I'm confused
c) afterCtag.text is of type type 'unicode'
d) afterCtag.text when printed displays: I?m confused

Question 1: assuming the following:
 a) beforeCtag.text gets assigned a value of 'I\x92m confused'
 b) afterRoot is built using the XML() method where the input to the
XML() method is the results of a tostring() method from beforeRoot
Are there any settings/arguments that could have been modified that
would have resulted in afterCtag.text being of type type 'str' and
afterCtag.text when printed displays:
 I'm confused

?

Another snippet from interactive window

 resultToStr2 = ElementTree.tostring(beforeRoot, encoding=utf-8)
 resultToStr2
'beforeRootCI#146;m confused/C/beforeRoot'
 if resultToStr == resultToStr2:
... print 'equal'
...
equal


If I'm reading the signature of the tostring method in ElementTree.py
correctly, it looks like encoding gets assigned a value of None if the
tostring method gets called without a 2nd argument.  In the specific
examples above, the result of the tostring method was the same when an
encoding of utf-8 was specified as it was when no encoding was
specified.

Question 2: Does the fact that resultToStr is equal to resultToStr2
mean that an encoding of utf-8 is the defacto default when no encoding
is passed as an argument to the tostring method, or does it only mean
that in this particular example, they happened to be the same?

Another snippet

 fileHandle = open('c:/output1.text', 'w')
 fileHandle.write(beforeCtag.text)
 fileHandle.write(afterCtag.text)
Traceback (most recent call last):
  File interactive input, line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u'\x92' in
position 1: ordinal not in range(128)
 encodedCtagtext = afterCtag.text.encode(utf-8)
 type(encodedCtagtext)
type 'str'
 encodedCtagtext
'I\xc2\x92m confused'
 print encodedCtagtext
IÂ'm confused
 fileHandle.write(encodedCtagtext)
 ord(encodedCtagtext[1])
194


In this snippet, I am trying to discern what can be written  to a file
without raising an exception.  The variable beforeCtag.text can be
written, but an exception is raised when an attempt is made to write
the unicode variable afterCtag.text to the file.  The statement

encodedCtagtext = afterCtag.text.encode(utf-8)

was a shot-in-the-dark attempt to transform afterCtag.text to something
that can be written to a file without raising an exception.  What I
observed is that:
a) encodedCtagtext can be written to a file without raising an
exception
b) the second character in encodedCtagtext has an ordinal value of 194

Questions 3 and 4:
3) would it be possible to construct a statement of the form

newResult = afterCtag.text.encode(?? some argument ??)

where newResult was the same as beforeCtag.text?  If so, what should
the argument be to the encode method?

4) what is the second character in encodedCtagtext (the character with
an ordinal value of 194)?

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


the print statement

2006-05-06 Thread mirandacascade
O/S: Win2K
Vsn of Python: 2.4

Here is copy/paste from interactive window of pythonwin:

 x = Joe's desk
 y = 'Joe\x92s desk'
 type(x)
type 'str'
 type(y)
type 'str'
 print x
Joe's desk
 print y
Joe's desk
 if x == y:
... print 'equal'
... else:
... print 'not equal'
...
not equal
 len(x)
10
 len(y)
10
 ord(x[3])
39
 ord(y[3])
146


My questions are:
1) is the 'x' character within the variable y a signal that what
follows is a hex value?
2) is it more than just a coincidence that 146 (the result of
ord(y[3])) is the decimal equivalent of the hex number 92?
3) is there any character set in which 146 represents the
single-quote/apostrophe character? if so, which character set?
4) what is the role/function of the backslash character in the variable
y?
5) how did the print statement know to transform the contents of y
('Joe\x92s desk') to something that gets displayed as:

Joe's desk

?

6) Would it be correct to infer that the print statement is aware of
characters beyond the 128 characters in the ascii character set?

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


Re: the print statement

2006-05-06 Thread mirandacascade
Thank you.  Yes, that post answers most of the questions.  I now have a
bit of an understanding of the \xhh pattern.  It's still unclear to me,
however, how one can go from the \x92 pattern and arrive at the
apostrophe character.  Is \x92 theh apostrophe character in another
character set?  If so, which character set?

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


Two ElementTree questions

2006-04-27 Thread mirandacascade
1) It appears as if the following logic works for determining whether
an element is a parent:

# assume elem is an ElementTree element
if (elem.getchildren() == None):
print 'this element is not a parent'
else:
print 'this element is a parent'

My question is this: are there any other ways of determining whether an
element is a parent, and if so, are they preferable to the method
above? (I don't have a definition for 'preferable'; I'm hoping the
reply to this question will suggest why a different method may be
preferable.)

2) At one time, I thought I saw some notes indicating that the
getchildren() method will be deprecated.  Now, however, I cannot locate
those notes.  Has the getchildren() method been deprecated, or will it
be deprecated?

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


python equivalent of VB code sample

2006-04-21 Thread mirandacascade
Situation is this:
1) must write application that does the following:
 a) creates an xml document, the contents of which, is a request
transaction
 b) send xml document to destination; I am assuming that a process
at destination side processes the request and sends back a response
 c) the application I'm writing must receive response and then
examine contents of response
2) hope to write client application in python
3) was provided VB code sample that does steps 1a, 1b and 1c; the
sample code is:

' section of code that builds the string sXML; the contents of which
is a request transaction
set objXML = Server.CreateObject(MSXML2.ServerXMLHTTP)
 'Bank table image address field, location of Comm Admin.
sServer = Session(ImageAddress)
 'NT AUTH
' note: I believe the next 2 lines in this post are really one line in
VB code that wrapped
' because they didn't fit on one line in the post
objXML.open
POST,sServer,false,Session(WebServerUserAuth),Session(WebServerPassword)
objXML.send sXML
sXMLRs = objXML.responseText

It appears as though much of the work is handled within methods and
properties of the objXML object:
 a) the open method appears to establish the connection with the
destination side
 b) the send method appears to handle both sending the request and not
returning control back to program until a response has been provided
 c) the .responseText property appears to be the contents of the
response

My questions are:
1) is it possible to develop a python script that does the equivalent
of the code sample above?
2) is the code sample above an example of what's referred to as an
'HTTP POST'?
3) I looked in the python documentation that describes urllib, urllib2
and httplib; am I looking in the right place?
4) are there other places I should be looking, particularly if I am
seeking samples of python code that are functionally similar to the
sample code above?

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


Re: python equivalent of VB code sample

2006-04-21 Thread mirandacascade
Thank you for pointing me in the direction of XMLHTTP.  I'm still
thinking about this in terms of creating a python script that is
functionally equivalent to the VB code in the original post. The
information I reviewed about XMLHTTP makes me think that it may be
possible to use the win32com.client to provide the python script with
the same methods and properties that the VB program is using.

Is win32com.client what I should be using?  The Dispatch method of
win32com.client?

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


Re: PATH environment variable

2005-11-20 Thread mirandacascade
I observed something tangential to this topic, and that is the reason
for this reply.  I don't understand when os.environ gets updated.  The
'...captured the first time the os mdule is imported...' verbiage from
the following link:

http://www.python.org/dev/doc/newstyle/lib/os-procinfo.html

provides some information, but it's not clear how to make that fit with
the following observations:

Sequence of steps...observation 1:
1) open Pythonwin interactive window
2) import os
3) os.environ['PATH'] - this presents the contents of the PATH variable
4) using Windows system properties/environment variables, change
contents of PATH variable; apply the changes (after closing, I got back
in to verify that the PATH variable was, in fact, changed)
5) in interactive window, reload(os)
6) os.environ['PATH'] - presents same value is in #3

Sequence of steps...observation 2:
1) open Pythonwin interactive window
2) import os
3) os.environ['PATH'] - this presents the contents of the PATH variable
4) using Windows system properties/environment variables, change
contents of PATH variable; apply the changes (after closing, I got back
in to verify that the PATH variable was, in fact, changed)
5) in interactive window, del os
6) in interactive window, import os
7) os.environ['PATH'] - presents the same value as in #3

I also observed that if I exit the interactive window, and then go back
into the interactive window, the os.environ['PATH'] reflects changes to
the PATH environment variable that happened while in the interactive
window the first time.

Do these observations fit with what is stated in section 6.1.1 of the
Python Library Reference?

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


Re: PATH environment variable

2005-11-20 Thread mirandacascade
Fredrik Lundh wrote:
 what part of your observations makes you think that the environment isn't 
 captured (i.e.  copied from the process environment) when the os module is 
 imported ?

Answer: the part that was informed by a fundamental misunderstanding on
my part of how the os module obtains information.

Based on Mr. Lundh's 'copied from the process environment' remark and
his hint, I would infer the following:

1) In the observations I detailed, the 'process' is the pythonwin
application
2) When the pythonwin application is invoked, it obtains a copy of the
current environment
3) the import os statement obtains information from the copy of the
current environment that was obtained when the pythonwin process began
4) a reload(os) or a combination of del os followed by import os also
get information from the copy of the current environment that was
obtained when the pythonwin process began

My questions:
a) are the above inferences (albeit oversimplified) correct?
b) when the hint refers to a new process, does the term 'process' refer
to the same concept that is described in secion 6.1.5 of the Python
Library Reference?

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


PATH environment variable

2005-11-19 Thread mirandacascade
O/S: Win2K
Vsn of Python:2.4

Based on a search of other posts in this group, it appears as though
os.environ['PATH'] is one way to obtain the PATH environment variable.

My questions:
1) is it correct that os.environ['PATH'] contains the PATH environment
variable?
2) are there other ways to obtain the PATH environment variable? if so,
is one way of obtaining the PATH environment variable preferable to
another way?

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


import statement / ElementTree

2005-11-04 Thread mirandacascade
O/S: Windows 2K
Vsn of Python: 2.4

Currently:

1) Folder structure:

\workarea\ - ElementTree files reside here
  \xml\
\dom\
\parsers\
\sax\

2) The folder \workarea\ is in the path.

3) A script (which is working) makes calls to the Element(),
SubElement(), tostring() and XML() methods within ElementTree.py; the
script is organized as follows:

# top of file; not within any function/mehtod
import ElementTree

examples of various calls within the module

root = ElementTree.Element('request')
pscifinq = ElementTree.SubElement(root, 'pscifinq')
bank = ElementTree.SubElement(pscifinq, 'bank')
bank.text = '1'
inquiryString = ElementTree.tostring(root)

4) the term 'ElementTree files' referenced above refers to the
following files:
__init__.py (this file contains only comments)
ElementInclude.py
ElementPath.py
ElementTree.py
HTMLTreeBuilder.py
SgmlopXMLTreeBuilder.py
SimpleXMLTreeBuilder.py
SimpleXMLWriter.py
TidyHTMLTreeBuilder.py
TidyTools.py
XMLTreeBuilder.py

Want to change things as follows:

Folder structure:

\workarea\ - ElementTree files no longer here
  \xml\
\dom\
\elementtree\ - ElementTree files reside here
\parsers\
\sax\

I tried changing the

import ElementTree

statement to:

import xml.elementtree.ElementTree

The result of changing the folder structure and the import statement
was the following error:

import xml.elementtree.ElementTree

ImportError: No module named elementtree.ElementTree

I verified that the file ElementTree.py really does reside in the
\workarea\xml\elementtree\ folder.  Assuming that I really want the
ElementTree files to reside in the \workarea\xml\elementtree\ folder,
what changes must I make such that the script can locate the
ElementTree.py file? I have a hunch that there is something obvious
that I am missing in the import statement; is it possible to accomplish
this by changing only the import statement rather than changing each of
the calls to the Element(), SubElement(), XML() and tostring() methods.

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


Understanding the arguments for SubElement factory in ElementTree

2005-10-29 Thread mirandacascade
Can the **extra argument in the SubElement() factory in ElementTree be
used to set the text property? Example:

Want the text associated with the subroot tag to be xyz.

root
  subrootxyz/subroot
/root

rather than:
root = Element('root')
subroot = SubElement(root, 'subroot')
subroot.text = 'xyz'

Was wondering whether this code accomplish that
root = Element('root')
subroot = SubElement(root, 'subroot', text='xyz')

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


Re: handling ExpatError exception raised from ElementTree.XML() method

2005-10-27 Thread mirandacascade
Mr. Boddie's suggestions work as indicated...many thanks.

It's not clear how a grep of the site-packages directory revealed the
most likely location of the ExpatError class is xml.parsers.expat.

Using XP's search utility, I searched for any files within the
c:\python24\ folder structure that had 'ExpatError' somewhere in the
file (I specified a case sensitive search.)  That search found nothing.
 I modified the search to look for any files with 'expat' (not case
sensitive.)...it located the file Mr. Boddie
mentioned...\lib\xml\parsers\expat.py.  That file has only a few lines
of code...it appears to import all the objects from what I'm guessing
is the pyexpat extension module.  I'm guessing that ExpatError is
embedded within that extension module...is that a correct guess?

It's not clear how Mr. Boddie was able to surmise where ExpatError
resides given that a case sensitive search of the folder structure
didn't find any files containing 'ExpatError'.

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


handling ExpatError exception raised from ElementTree.XML() method

2005-10-26 Thread mirandacascade
Verion of Python: 2.4
O/S: Windows XP
ElementTree resides in the c:\python24\lib\site-packages\elementtree\
folder

When a string that does not contain well-formed XML is passed as an
argument to the XML() method in ElementTree.py, an ExpatError exception
is raised.  I can trap the exception with a try/except where the except
does not specify a specific exception, but I cannot figure out how to
construct the except clause in a try/except statement to catch the
ExpatError exception.  Interactive window illustrates

 import elementtree.ElementTree as ElemTree
 badxml = 'responseabc/responsez'
 root = ElemTree.XML(badxml)
Traceback (most recent call last):
  File interactive input, line 1, in ?
  File C:\Python24\Lib\site-packages\elementtree\ElementTree.py, line
960, in XML
parser.feed(text)
  File C:\Python24\Lib\site-packages\elementtree\ElementTree.py, line
1242, in feed
self._parser.Parse(data, 0)
ExpatError: mismatched tag: line 1, column 15
 try:
... root = ElemTree.XML(badxml)
... except:
... print 'some exception raised'
...
some exception raised
 try:
... root = ElemTree.XML(badxml)
... except ExpatError:
... print 'ExpatError exception raised'
...
Traceback (most recent call last):
  File interactive input, line 3, in ?
NameError: name 'ExpatError' is not defined

I'm guessing that I need to define/describe the ExpatError exception
class and then refer to that defined exception class after the keyword
'except' and before the ':', but I cannot figure out how to do that.

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


find() method in ElementTree

2005-10-22 Thread mirandacascade
I do not understand how to use the find() method in ElementTree.

The file 'sample.xml' is:

?xml version=1.0?
SampleRoot
Header
ProductFindMystery/Product
/Header
SpecificInformation
SampleDetailabc/SampleDetail
/SpecificInformation
/SampleRoot

 from elementtree.ElementTree import ElementTree
 doc = ElementTree(file='sample.xml')
 iterList = doc.getiterator()
 iterList
[Element SampleRoot at 1166850, Element Header at 1166878, Element
Product at 11668a0, Element SpecificInformation at 1166940, Element
SampleDetail at 1166990]
 len(iterList)
5
 element = iterList[4]
 element.tag
'SampleDetail'
 x = doc.find('SampleDetail')
 if x == None:
... print 'x is none'
...
x is none


The ElementTree documentation indicates that:
find(pattern) returns the first subelement that matches the given
pattern, or None if there is no matching element.

and

the pattern argument can either be a tag name, or a path expression

Based on the following snippet from the interactive window:

 doc = ElementTree(file='sample.xml')
 iterList = doc.getiterator()
 element = iterList[4]
 element.tag
'SampleDetail'

I inferred (perhaps incorrectly) that within doc there is a subelement
with a tag 'SampleDetail'.

Based on the following snippet:

 x = doc.find('SampleDetail')
 if x == None:
... print 'x is none'
...
x is none

I conclude that there is no subelement in doc with a tag
'SampleDetails'.

My questions:
1) in the example above is there a subelement of doc with a tag
'SampleDetails'?
2) if so, what is the proper way of writing the call to the find()
method to locate that subelement?

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


Minimizing Connection reset by peer exceptions

2005-10-19 Thread mirandacascade
This may be more of a socket question than a python question; not sure.

Using this code to instantiate/connect/set options
connectionHandle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
errorStatus = connectionHandle.connect_ex((ipAddress, port))
connectionHandle.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO,
6)

Using this code to send:
retSendAll = connectionHandle.sendall(messageToHost)

Followed by this code to recv:
bufferSize = 50
responseBuffer = connectionHandle.recv(bufferSize)

Occasionally (perhaps 5% of the time) the following exception gets
raised:

(10054, 'Connection reset by peer')


Are there any changes I can make to the code above to eliminate the
10054 errors or to reduce the probability of encountering the 10054
error?  Are there any settings that make the 'Connection reset by
peer' condition less likely?

Other posts on this subject seem to suggest that this can only be
handled by:
1) detecting the 10054 error
2) issuing a message explaining the 'connection reset' condition
followed by something along the lines of 'try again later'.

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


where to find information about errors/exceptions in socket.py

2005-10-07 Thread mirandacascade
Version of python: 2.4
O/S: Win2K

I will be writing some python scripts to do some client-side
programming that involves socket.py.  I expect that I will be making
calls to the following methods/functions:

connect_ex()
setsockopt()
sendall()
recv()
close()

Where can one find information about whether the functions/methods
above return error codes that provide some indication as to whether the
function/method succeeded?  Is there an exception class for handling
exceptions raised in socket.py?  If so, where can one find information
about it?

I consulted the docstrings and didn't find much about return codes or
exception classes.  Also looked at the Lutz Programming Python
text...it devotes several pages to socket programming, but I didn't
observe much with regard to error/exception handling.

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


accessor/mutator functions

2005-02-25 Thread mirandacascade
When I look at how classes are set up in other languages (e.g. C++), I
often observe the following patterns:
1) for each data member, the class will have an accessor member
function (a Getwhatever function)
2) for each data member, the class will have a mutator member function
(a Setwhatver function)
3) data members are never referenced directly; they are always
referenced with the accessor and mutator functions

My questions are:
a) Are the three things above considered pythonic?
b) What are the tradeoffs of using getattr() and setattr() rather than
creating accessor and mutator functions for each data member?

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


Re: accessor/mutator functions

2005-02-25 Thread mirandacascade
If the class had two attributes--x and y--would the code look like
something lik this:

 class C(object):
def __init__(self):
self.__x = 0
self.__y = 0
def getx(self):
return self.__x
def setx(self, x):
if x  0: x = 0
self.__x = x
def gety(self):
return self.__y
def sety(self, y):
if y  0: y = 0
self.__y = y
x = property(getx, setx)
y = property(gety, sety)

?

Because if so, does the term 'lazy evaluation' refer to the fact that
instead of:

C().getx()
C().gety()
C().setx(10)
C().sety(10)

one would substitute:

C().x
C().y
C().x = 10
C().y = 10

?

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


progress bar controls in status.py

2005-02-22 Thread mirandacascade
O/S - Windows XP Home with Service Pack 2
Vsn of Python: 2.4 (from ActiveState)

This question is with regard to the progress bar controls that are in
the file status.py.  On my workstation, status.py is located in the:

c:\python24\lib\site-packages\pythonwin\pywin\dialogs\

folder.

The only modification I made to status.py was to the demo() method
where I added the type argument and then called either
StatusProgressDialog or ThreadedStatusProgressDialog.  The modified
demo() method looks like this:

def demo(type):
if type == threaded:
d = ThreadedStatusProgressDialog(A Demo, Doing
something...)
else:
d = StatusProgressDialog(A Demo, Doing something...)

import win32api
for i in range(100):
if i == 50:
d.SetText(Getting there...)
if i==90:
d.SetText(Nearly done...)
win32api.Sleep(20)
d.Tick()
d.Close()

Using the interactive window of PythonWin, when I do the following:
 import status
 status.demo('a')
the results are:
 - a progress bar with title 'A Demo' appears
 - ticks appear within the progress bar
 - the message changes from 'Doing something' to 'Getting there...' to
'Nearly done...'
 - the progress bar no longer appears

Using the interactive window of PythonWin, when I do the following:
 import status
 status.demo('threaded')
the results are:
 - the cursor position stays immediately to the right of the ')'
character
 - nothing appears on the screen
 - about 10 seconds later the  appears, a progress bar control
appears with the title 'A Demo' and text 'Doing something'
 - the progress bar remains visible until I close it by clicking on the
X in the top right corner

My questions are:
1) If I want the behavior of ThreadedStatusProgressDialog to emulate
the behavior of StatusProgressDialog, what changes must I make to
status.py to accomplish that? (assume that I want
ThreadedStatusProgressDialog to remain threaded, i.e. I'm not looking
for an answer along the lines of if you want the behavior of
ThreadedStatusProgressDialog to emulate the behavior of
StatusProgressDialog, then have it call StatusProgressDialog.)
2) Can you offer any guidelines or rules of thumb regarding when one
would wish to use ThreadedStatusProgressDialog vs using
StatusProgressDialog?

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


introspection inquiry

2005-02-20 Thread mirandacascade
Where in the language would one find the intropsection capability to
answer the question: what class am I in?

Example:

class ExistentialCrisis:
def __init__(self, text):
self.spam = text
print 'In the constructor of the %s class' % whatever

When the constructor method is invoked, would like to see the following
message:

In the constructor of the ExistentialCrisis class

and I would like to be able to do it without substituting the literal
string 'ExistentialCrisis' for whatever.

My question is this: what can be substituted for whatever that will
make the example above work?

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


newbie question - exception processing

2005-02-19 Thread mirandacascade
O/S: Windows XP Service Pack 2
Python version: 2.4

Unable to understand how to build a class to handle an exception.

Contents of sample01.py:
import exceptions
class SampleMain:
try:
def __init__(self):
print 'in SampleMain constructor'

def Allowed(self):
print 'in allowed'

def NotYetAllowed(self):
UCError = UnderConstructionError('not yet ready')
raise UCError

except UnderConstructionError, e:
print e.msg

class Error(exceptions.Exception):
def __init__(self):
print 'in base class constructor'

class UnderConstructionError(Error):
def __init__(self, message):
print 'in UnderConstructionError constructor'
self.msg = message

Copy/paste of interactive window:
PythonWin 2.4 (#60, Nov 30 2004, 09:34:21) [MSC v.1310 32 bit (Intel)]
on win32.
Portions Copyright 1994-2004 Mark Hammond ([EMAIL PROTECTED]) -
see 'Help/About PythonWin' for further copyright information.
 import sample01
 x = sample01.SampleMain()
in SampleMain constructor
 x.NotYetAllowed()
in UnderConstructionError constructor
Traceback (most recent call last):
  File interactive input, line 1, in ?
  File C:\Python24\sample01.py, line 12, in NotYetAllowed
raise UCError
UnderConstructionError: unprintable instance object


My questions are:
1) What is causing the error described in the Traceback?
2) Given that what I want to happen when the NotYetAllowed() method is
called is:
a) an exception to be raised
b) the exception results in a message getting printed; the message
should come from the place where the exception was raised, and it
should be passed to the exception class as a string object; so in this
case the message that should be printed is 'not yet ready'
c) the exception gets handled with the try/except within the
SampleMain class

My question is: what changes must I make to the code to make that
happen?

Thank you.

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


newbie question - identifying name of method

2005-02-14 Thread mirandacascade
Does Python provide some sort of mechanism for answering the question:
what method am I in?

Example: assume the file example1.py contains the following code:

def driver():
print 'hello world'
print __name__
print 'the name of this method is %s' % str(???)

The output I'd like to see is:

hello world
example1
driver

and I'd like to be able to see it without hardcoding the string
'driver' in the third print statement.  Is there anything I can
substitute for the ??? that answers the question: what method am I in?

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


python-2.4.msi installation issue

2005-02-02 Thread mirandacascade
O/S: Windows XP Home (with Service Pack 2)
Downloaded python-2.4.msi from python.org (10,632KB).  When I double
click on the file from Windows Explorer, the installation process
presents the window in which I am prompted to either install for all
users (the default) or install for just me.  I selected the defaulted
value.  Installation process presents a window in which the user may
select the directory for python 2.4 files.  I selected the default
value of the Python24 folder.  After clicking Next, the process
presents a window with the message, Python 2.4 installer ended
prematurely.  Python 2.4 ended prematurely because of an error.  Your
system has not been modified.  To install this program at a later time,
please run the installation again.

My question is this: how do I determine what the error was that caused
the installation process to end prematurely?

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