[Tutor] urlparse question

Jaco.Smuts@za.didata.com Jaco.Smuts@za.didata.com
Tue, 27 Aug 2002 09:09:09 +0200


thanks guys, it will definitely help to have this available in the urlparse
library though.

Cheers

-----Original Message-----
From: Danny Yoo [mailto:dyoo@hkn.eecs.berkeley.edu]
Sent: 26 Augustus 2002 10:55
To: Blake Winton
Cc: tutor@python.org
Subject: Re: [Tutor] urlparse question




On Mon, 26 Aug 2002, Blake Winton wrote:

> * Danny Yoo <dyoo@hkn.eecs.berkeley.edu> [020826 14:05]:
> ###
> >>> query_string =
> "hl=en&lr=&ie=UTF-8&oe=utf-8&q=south+africa+travel+cape+town"
> >>> import cgi
> >>> dict = cgi.parse_qs(query_string)
> >>> dict
> {'hl': ['en'], 'ie': ['UTF-8'], 'oe': ['utf-8'],
>  'q': ['south africa travel cape town']}
> ###
>
> You might want to notice that it's completely lost the "lr=" part of the
> query string.  If that's important to you, you may need to reinvent the
> wheel.


Good eye!  I didn't notice that 'lr' didn't have a value in the
dictionary.

Thankfully, we can still take advantage cgi.quote_qs() because it can take
in an optional parameter to keep even the empty parameters:

###
>>> cgi.parse_qs(query_string, keep_blank_values = 1)
{'hl': ['en'], 'ie': ['UTF-8'], 'oe': ['utf-8'], 'lr': [''],
 'q': ['south africa travel cape town']}
###


Hope this helps!


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


This message contains information intended solely for the addressee,
which is confidential or private in nature and subject to legal privilege.
If you are not the intended recipient, you may not peruse, use,
disseminate, distribute or copy this message or any file attached to this
message. Any such unauthorised use is prohibited and may be unlawful. If
you have received this message in error, please notify the sender
immediately by e-mail, facsimile or telephone and thereafter delete the
original message from your machine. 
 
Furthermore, the information contained in this message, and any
attachments thereto, is for information purposes only and may contain the
personal views and opinions of the author, which are not necessarily the
views and opinions of Dimension Data (South Africa) (Proprietary) Limited
or is subsidiaries and associated companies ("Dimension Data"). Dimension
Data therefore does not accept liability for any claims, loss or damages
of whatsoever nature, arising as a result of the reliance on such
information by anyone. 
 
Whilst all reasonable steps are taken to ensure the accuracy and
integrity of information transmitted electronically and to preserve the
confidentiality thereof, Dimension Data accepts no liability or
responsibility whatsoever if information or data is, for whatsoever
reason, incorrect, corrupted or does not reach its intended destination.