Re: Re: HTTP Header Capitalization in urllib.request.AbstractHTTPHandler (Python 3.3)

2013-11-20 Thread Logan

On 11/20/2013 02:05 AM, Chris Angelico wrote:

On Wed, Nov 20, 2013 at 1:14 PM, Logan lo...@s1network.com wrote:

Chris,

That is genius.  Thank you!

Then it works? Awesome!! (Permit me an evil laugh. Muahahah!)

This is why I love working with open source languages. Even if you
don't end up actually changing anything, you can go and snoop the code
and see what happens - sometimes you can tweak your code based on that
knowledge. And hey. This is duck typing at its best!

ChrisA

Not exactly as written, but close enough to get me working.  At one 
point the following code is executed, turning the value into a string to 
be  titled next time it is called:


   name = name.title()


So, I worked around it with the following class, adapted from yours:

   class CaseSensitiveHeader(object):
def __init__(self, name):
self.name = name

def capitalize(self):
return self

def title(self):
return self

def lower(self):
return self.name

def encode(self, encoding):
   return self.name.encode(encoding)


With that, I am now able to post a case sensitive HTTP header.

-- Logan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Re: HTTP Header Capitalization in urllib.request.AbstractHTTPHandler (Python 3.3)

2013-11-20 Thread Chris Angelico
On Thu, Nov 21, 2013 at 10:26 AM, Logan lo...@s1network.com wrote:
 Not exactly as written, but close enough to get me working.

Excellent. Sometimes it's fun to be just that evil. :)

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


Re: HTTP Header Capitalization in urllib.request.AbstractHTTPHandler (Python 3.3)

2013-11-19 Thread Logan

Chris,

That is genius.  Thank you!

-- Logan
--
https://mail.python.org/mailman/listinfo/python-list


Re: HTTP Header Capitalization in urllib.request.AbstractHTTPHandler (Python 3.3)

2013-11-19 Thread Chris Angelico
On Wed, Nov 20, 2013 at 1:14 PM, Logan lo...@s1network.com wrote:
 Chris,

 That is genius.  Thank you!

Then it works? Awesome!! (Permit me an evil laugh. Muahahah!)

This is why I love working with open source languages. Even if you
don't end up actually changing anything, you can go and snoop the code
and see what happens - sometimes you can tweak your code based on that
knowledge. And hey. This is duck typing at its best!

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


HTTP Header Capitalization in urllib.request.AbstractHTTPHandler (Python 3.3)

2013-11-18 Thread Logan Owen
Hello everyone,

I was hoping for some advice in dealing with an edge case related to
Python's HTTP Header handling.  Python is correctly assuming that the
HTTP header field name (eg Content-Type) is case insensitive, but I have
a webservice I am interacting with that does not follow the standards. 
I am passing in the header SOAPAction and do_request of
AbstractHTTPHandler is applying title() to the string, leading to the
field name being Soapaction, which the server does not recognize.

So my question is, what does everyone suggest is the best solution for
being able to pass a case sensitive header to the server?

Thanks!
Logan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HTTP Header Capitalization in urllib.request.AbstractHTTPHandler (Python 3.3)

2013-11-18 Thread Chris Angelico
On Tue, Nov 19, 2013 at 1:25 AM, Logan Owen lo...@s1network.com wrote:
 Hello everyone,

 I was hoping for some advice in dealing with an edge case related to
 Python's HTTP Header handling.  Python is correctly assuming that the
 HTTP header field name (eg Content-Type) is case insensitive, but I have
 a webservice I am interacting with that does not follow the standards.
 I am passing in the header SOAPAction and do_request of
 AbstractHTTPHandler is applying title() to the string, leading to the
 field name being Soapaction, which the server does not recognize.

 So my question is, what does everyone suggest is the best solution for
 being able to pass a case sensitive header to the server?

So what you're asking is: How can Python be made less standards-compliant?

Well! You may be in luck. The evil part of my brain has just gone
digging for a solution. According to cpython/Lib/urllib/request.py
from Python 3.4 alpha (unlikely to be different in 3.3), the code
you're looking for is either line 1193ish:

for name, value in self.parent.addheaders:
name = name.capitalize()
if not request.has_header(name):
request.add_unredirected_header(name, value)

or line 1226:
headers = dict((name.title(), val) for name, val in headers.items())

I'm assuming you're either stuffing stuff into addheaders or passing
it headers. Well, dere's nuffink says it has to be a string...

class SOAPAction:
def capitalize(self):
return SOAPAction
title = capitalize

Just use SOAPAction() instead of SOAPAction as your key, and TYAOOYDAO!

ChrisA

[1] there you are, out of your difficulty at once - cf WS Gilbert's Iolanthe
-- 
https://mail.python.org/mailman/listinfo/python-list