[python-win32] String weirdness on python 2.4 / windows

2005-10-19 Thread Kinsley Turner


Hey-ho,

I'm having a problem with some binary data read into a string.

Basically I open an icon file "rb", read() it into a string, then
spit it back down on a web request for /favicon.ico.

It works fine under unix, but under Win32 Python 2.4.2 (#67, Sep 28 2005 
...
It comes back corrupted.

Similiarly I have a string with the IBM-extended-ASCII degrees symbol 
(ascii 0xb0) 
that is read in from a network-connected field device.  Somehow this ends 
up with 
an extended 'A' (with a single dot over it.) prepended before it.

Is there some sort of new 2.4 string encoding option I've missed ?
Never seen anything like this before.

I have the "# -*- coding: iso-8859-1 -*-" atop my files.


-kt



Please consider our environment before printing this email.

WARNING - This email and any attachments may be confidential. If received in 
error, please delete and inform us by return email. Because emails and 
attachments may be interfered with, may contain computer viruses or other 
defects and may not be successfully replicated on other systems, you must be 
cautious. Westpac cannot guarantee that what you receive is what we sent. If 
you have any doubts about the authenticity of an email by Westpac, please 
contact us immediately.

It is also important to check for viruses and defects before opening or using 
attachments. Westpac's liability is limited to resupplying any affected 
attachments.


This email and its attachments are not intended to constitute any form of 
financial advice or recommendation of, or an offer to buy or offer to sell, any 
security or other financial product. We recommend that you seek your own 
independent legal or financial advice before proceeding with any investment 
decision.

Westpac Institutional Bank is a division of Westpac Banking Corporation, a 
company registered in New South Wales in Australia under the Corporations Act 
2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the 
Financial Services Authority and is registered at Cardiff in the United Kingdom 
as Branch No. BR 106. Westpac operates in the United States of America as a 
federally chartered branch, regulated by the Office of the Comptroller of the 
Currency.

Westpac Banking Corporation ABN 33 007 457 141.
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] win32com calling C++ COM interface

2005-10-19 Thread Shad Muegge
Hi,
 
I've just started looking at Python.  I am trying to resolve an issue a user is having trying to access the COM interface in our application from Python.
 
C++ code:
 
STDMETHODIMP   
CMyClass::Read(  const int   x,
  VARIANT  *indexlist,  // IN:  "safe" array of  4-byte integers  VARIANT  *results)
 
 
Python code:
 
    def read(self, x, addr):    try:    addr = buffer(array.array('L', addr))data = "" addr)...
 
x.read(0, 0x12345678)
 
The variant that shows up on the C++ code is a safearray of 1-byte integers with 4 elements: 12, 34, 56, 78.
 
The API treats them each as individual "addresses"...
 
Here's the COM definition from the .py file.
 
 def Read(self, x=defaultNamedNotOptArg, indexlist=defaultNamedNotOptArg, results=pythoncom.Missing):  """method Read"""  return self._ApplyTypes_(2, 1, (24, 0), ((3, 1), (16396, 1), (16396, 2)), 'Read', None,x
   , indexlist, results) 
Thanks,
Shad
 
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com calling C++ COM interface

2005-10-19 Thread bob
At 01:22 PM 10/19/2005, Shad Muegge wrote:
>Hi,
>
>I've just started looking at Python.  I am trying to resolve an issue a 
>user is having trying to access the COM interface in our application from 
>Python.
>
>C++ code:
>
>STDMETHODIMP
>CMyClass::Read(
>   const int   x,
>   VARIANT  *indexlist,  // IN:  "safe" array of  4-byte integers
>   VARIANT  *results)
>
>
>Python code:
>
> def read(self, x, addr):
> try:
> addr = buffer(array.array('L', addr))
> data = self.__Api.Read(x, addr)
>...
>
>x.read(0, 0x12345678)
>
>The variant that shows up on the C++ code is a safearray of 1-byte 
>integers with 4 elements: 12, 34, 56, 78.
>
>The API treats them each as individual "addresses"...
>
>Here's the COM definition from the .py file.
>
>  def Read(self, x=defaultNamedNotOptArg, indexlist=defaultNamedNotOptArg, 
> results=pythoncom.Missing):
>   """method Read"""
>   return self._ApplyTypes_(2, 1, (24, 0), ((3, 1), (16396, 1), (16396, 
> 2)), 'Read', None,x
>, indexlist, results)
>
Since I don't know the C++ side of COM I probably can't help. And perhaps 
it is for that reason that I don't even know what the user's issue is. If 
it is obvious to the cognoscenti, fine. For my sake could you elaborate. 
What is the "issue"? 

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com calling C++ COM interface

2005-10-19 Thread Shad Muegge
Sorry, the interface is expecting a safearray of 4-byte integers, instead it's getting a safearray of 1-byte integers. On 10/19/05, bob <
[EMAIL PROTECTED]> wrote:At 01:22 PM 10/19/2005, Shad Muegge wrote:>Hi,
>>I've just started looking at Python.  I am trying to resolve an issue a>user is having trying to access the COM interface in our application from>Python.>>C++ code:>>STDMETHODIMP
>CMyClass::Read(>   const int   x,>  
VARIANT  *indexlist,  //
IN:  "safe" array of  4-byte integers>   VARIANT  *results)>>>Python code:>> def read(self, x, addr):> try:> addr = buffer(array.array
('L', addr))> data = "" addr)>...>>x.read(0, 0x12345678)>>The variant that shows up on the C++ code is a safearray of 1-byte>integers with 4 elements: 12, 34, 56, 78.
>>The API treats them each as individual "addresses"...>>Here's the COM definition from the .py file.>>  def Read(self, x=defaultNamedNotOptArg, indexlist=defaultNamedNotOptArg,
> results=pythoncom.Missing):>   """method Read""">   return self._ApplyTypes_(2, 1, (24, 0), ((3, 1), (16396, 1), (16396,> 2)), 'Read', None,x>, indexlist, results)
>Since I don't know the C++ side of COM I probably can't help. And perhapsit is for that reason that I don't even know what the user's issue is. Ifit is obvious to the cognoscenti, fine. For my sake could you elaborate.
What is the "issue"?
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com calling C++ COM interface

2005-10-19 Thread Mark Hammond



Your 
code is explicitly creating a buffer object, which the win32com framework 
translates as "array of bytes".  Try just passing a list (or tuple) of 
integers instead of the buffer.
 
Mark

  -Original Message-From: 
  [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On 
  Behalf Of Shad MueggeSent: Thursday, 20 October 2005 6:23 
  AMTo: python-win32@python.orgSubject: [python-win32] 
  win32com calling C++ COM interface
  Hi,
   
  I've just started looking at Python.  I am trying to resolve an 
  issue a user is having trying to access the COM interface in our application 
  from Python.
   
  C++ code:
   
  STDMETHODIMP   
  CMyClass::Read(  const int   
  x,
    VARIANT  
  *indexlist,  
  // IN:  "safe" array of  4-byte 
  integers  VARIANT  *results)
   
   
  Python code:
   
      def read(self, x, 
  addr):    
  try:    
  addr = buffer(array.array('L', 
  addr))data 
  = "" addr)...
   
  x.read(0, 0x12345678)
   
  The variant that shows up on the C++ code is a safearray of 1-byte 
  integers with 4 elements: 12, 34, 56, 78.
   
  The API treats them each as individual "addresses"...
   
  Here's the COM definition from the .py file.
   
   def Read(self, x=defaultNamedNotOptArg, 
  indexlist=defaultNamedNotOptArg, 
  results=pythoncom.Missing):  """method 
  Read"""  return self._ApplyTypes_(2, 1, (24, 0), ((3, 1), 
  (16396, 1), (16396, 2)), 'Read', None,x    , indexlist, 
  results) 
  Thanks,
  Shad
   
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] msoScaleFromTopLeft

2005-10-19 Thread kimwaic888-pythonwin32
Hi list,

Could someone please tell me what I should do with
values such as msoScaleFromTopLeft?  I tried:

constants.msoScaleFromTopLeft

and that didn't work.

Thanks,

--
John
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] String weirdness on python 2.4 / windows

2005-10-19 Thread Kinsley Turner


Emlyn Jones <[EMAIL PROTECTED]> wrote on 20/10/2005 02:46:54 AM:

> In what way is it corrupted? Are you 100% sure that no extra output 
> is being prepended/appended when you output the icon file data via 
> HTTP? Have a look at it in emacs/notepad just to check there are no 
> stray HTTP Headers or other output ending up in your file.

I checked the icon, it seemed to be ok.  I'm unfamiliar with win32
tools, but it seemed that the data being delivered from the socket
rendered differently from a python print() compared to a terminal
'type icon.ico'.  I cut the code out and tested it in isolation - this 
showed it to be flawless.  Despite appearing correct in other software
the binary identical icon appears broken in IE 6..

I think you might be correct with the headers suggestion, that was
going to be my next point of investigation.  I don't think the
MIME type of image/bmp is acceptable to IE.

thanks,
-kt




















--



Please consider our environment before printing this email.

WARNING - This email and any attachments may be confidential. If received in 
error, please delete and inform us by return email. Because emails and 
attachments may be interfered with, may contain computer viruses or other 
defects and may not be successfully replicated on other systems, you must be 
cautious. Westpac cannot guarantee that what you receive is what we sent. If 
you have any doubts about the authenticity of an email by Westpac, please 
contact us immediately.

It is also important to check for viruses and defects before opening or using 
attachments. Westpac's liability is limited to resupplying any affected 
attachments.


This email and its attachments are not intended to constitute any form of 
financial advice or recommendation of, or an offer to buy or offer to sell, any 
security or other financial product. We recommend that you seek your own 
independent legal or financial advice before proceeding with any investment 
decision.

Westpac Institutional Bank is a division of Westpac Banking Corporation, a 
company registered in New South Wales in Australia under the Corporations Act 
2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the 
Financial Services Authority and is registered at Cardiff in the United Kingdom 
as Branch No. BR 106. Westpac operates in the United States of America as a 
federally chartered branch, regulated by the Office of the Comptroller of the 
Currency.

Westpac Banking Corporation ABN 33 007 457 141.
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] String weirdness on python 2.4 / windows

2005-10-19 Thread Kinsley Turner


> >Similarly I have a string with the IBM-extended-ASCII degrees symbol
> >(ascii 0xb0)
> >that is read in from a network-connected field device.  Somehow this
ends
> >up with
> >an extended 'A' (with a single dot over it.) prepended before it.

> This question is inappropriate for this mailing list, which is for the
> pywin32 extensions, which you don't appear to be using. You should send
> the question to python-list.

Really?  Ok.
The list index (http://mail.python.org/mailman/listinfo) says
this list is for "Python on win32".

> What does "spit it back down on a web request for /favicon.ico" mean???
> What "it" comes back from "where" corrupted?

When I say 'spit', you can read this as "transmits to the requesting
web-browser using HTTP protocol over a BSD-style socket layering
atop TCP/IP".

> What does corrupted mean?

No longer in it's original form.
In this case it looks like bytes have been removed & changed.

> It would help greatly if you showed the actual code that causes the
> alleged problem. Even better would be to cut that out and make it
> into a small standalone script that demonstrates the problem. Also
> stating the expected or preferred result would be a good idea.

Yes I agree, but not all problems can be rendered down into a simple
example easily.  You see in this case the string is rendered into
an image and served back to a web browser.  I had hoped for a simple
answer like "Add encoding header XYZ to your script". Alas.

> AFAIK ASCII describes only characters with ordinals in range(0x80).

Yes that's true, original ASCII was only 7 bit.
Obviously I was referring to ISO-8859-1, commonly referred to as
'Extended ASCII' and IIRC popularised by IBM in the 80's (70's?).
It's been the dominant latin character set for 20 years or so.
But you knew this already.

> Perhaps you mean that you have a string which contains '\xb0'.

No.
The string is encoded as a single symbol within the python string,
not a trigraph (quadgraph?).

> "Somehow" -- unless you have pixies at the bottom of your garden, it
> got mangled because *YOU* did something to it. If you can't tell us
> what you did to it, we can't help you.

The string in question is a test-string.  Basically it contains a
few words, then "1234567890 !C" where the '!' is the degrees-symbol
as specified in Extended ASCII / ISO-8859-*.  The text is then rendered
into an image (using a supplied GNU TTF font) via the Python Imaging
Library
(PIL).  Under UNIX this comes out as expected, with the degrees symbol
rendered appropriately.  When run as a Win32 service the rendering
comes out with an accented 'A' in front of it.

> "Extended A with a single dot over it"?? Are you sure that's a dot? I'd
> like to know what language uses A with dot above *and* what the pixies
> are using to render it on your screen. Could it possibly be a circumflex

> accent?

I thought it was a 'Å' (pasted in an 'A' with a dot above it,
well, ok, maybe I should have said 'circle above it') Depending
on your font & size sometimes the dot is connected to the top of
the A, in other's it hovers.  Try it: print u'\xc5'.  This is from an
ISO-8859-1 encoding, YMMV.  Sorry, I don't know what language
uses this character either.  It's being rendered by the PIL.


> Hint (1):  u'\xb0'.encode('utf-8') produces '\xc2\xb0'. If that is
> displayed by a gadget that's expecting iso-8859-1 (or cp1252) instead of

> utf-8, '\xc2' will show as Latin capital A with circumflex.

Hmmm, I wonder if PIL is doing some kind of modification to the string
before rendering it.  This question might better be posed to the PIL list.
I can't really control what the device sends back, but I think this
is not the only Extended ASCII / ISO-8859-* character it delivers.

Ahhh... I think I've got it.

> Hint (2): print repr(allegedly_mangled_string)

This gives me '1234567890\xb0C' from a UNIX python (2.4.2 #1)
Win32 (python 2.4.2 #64) gives the same.  So it mustn't be something
to do with the python / string representation.

> "prepended before it" -- as opposed to "prepended after it"?

That would be "'appended' after it", wouldn't it?
(or are you just trying to pick a spoonerism)


> Perhaps we should avoid Westpac ATMs until you sound the all-clear :-)

Last time I looked these ran on OS/2[1], so I think you'll be safe.



thanks for the hints,
-kt



[1] At least the old ones anyway.















(unremovable disclaimer below)
--



Please consider our environment before printing this email.

WARNING - This email and any attachments may be confidential. If received in 
error, please delete and inform us by return email. Because emails and 
attachments may be interfered with, may contain computer viruses or other 
defects and may not be successfully replicated on other systems, you must be 
cautious. Westpac cannot guarantee that what you receive is what we sent. If 
you have any doubts about the authenticity of an email by Westpac, please 
contact us immediately.

It is also important to check for

Re: [python-win32] String weirdness on python 2.4 / windows

2005-10-19 Thread Justin Ezequiel
> Date: Thu, 20 Oct 2005 10:04:24 +1000
> From: Kinsley Turner <[EMAIL PROTECTED]>
>
> I checked the icon, it seemed to be ok.  I'm unfamiliar with win32
> tools, but it seemed that the data being delivered from the socket
> rendered differently from a python print() compared to a terminal
> 'type icon.ico'.  I cut the code out and tested it in isolation - this
> showed it to be flawless.  Despite appearing correct in other software
> the binary identical icon appears broken in IE 6..

for what its worth, had a similar problem serving up images from a
Python CGI script running on Apache on WinXP.

what worked for me was adding the "-u" switch to the shebang
#!E:\Python23\python.exe -u

-u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)
 see man page for details on internal buffering relating to '-u'

hope this helps
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] String weirdness on python 2.4 / windows

2005-10-19 Thread Gabriel Genellina
At Wednesday 19/10/2005 21:04, you wrote:

>I think you might be correct with the headers suggestion, that was
>going to be my next point of investigation.  I don't think the
>MIME type of image/bmp is acceptable to IE.

Should be image/vnd.microsoft.icon or image/x-icon, but NOT image/bmp
(icon files having different format than bmp files)


Gabriel Genellina
Softlab SRL 

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32