I've coded python for a long time, but just recently I've decided to mess around with jython a bit. I notice that jython does not re-implement urlparse.parse_qs so I implemented my own version, if there is an import error.... here is the code:
try:
from urlparse import parse_qs
except ImportError:
import sys
if sys.platform.startswith("java"):
IMPORT_EXCEPTION_TEXT = """
Please ensure that "httpcore-4.1.4.jar" and "httpclient-4.1.3.jar" are in your class path!
These libraries can be found here: http://hc.apache.org/
"""
try:
from org.apache.http.client.utils import URLEncodedUtils
except ImportError:
raise ImportError(IMPORT_EXCEPTION_TEXT)
from java.net import URI
from collections import defaultdict
def parse_qs( qs ):
response = defaultdict(list)
for pair in URLEncodedUtils.parse(URI("http:///?%s" % qs ),'ascii'):
response[ pair.getName() ].append( pair.getValue()
return response.copy() # This is the line causing the problem.
# The problem is:
# SyntaxError: no viable alternative at input 'return'
else:
raise ImportError("This should never happen, could not import urlparse.parse_qs")
I have never seen an error like this in python, ever, so I don't know what's wrong... Any help would be appreciated!
)
after pair.getValue(). This I guess is how jython tells you about an un-expected statement... – john-charles Mar 24 '12 at 2:50