2 # Copyright 2010 Joshua Roesslein
3 # See LICENSE for details.
5 from datetime import datetime
9 from urllib import quote
10 from email.utils import parsedate
13 def parse_datetime(string):
14 return datetime(*(parsedate(string)[:6]))
17 def parse_html_value(html):
19 return html[html.find('>')+1:html.rfind('<')]
22 def parse_a_href(atag):
24 start = atag.find('"') + 1
25 end = atag.find('"', start)
26 return atag[start:end]
29 def convert_to_utf8_str(arg):
30 # written by Michael Norton (http://docondev.blogspot.com/)
31 if isinstance(arg, unicode):
32 arg = arg.encode('utf-8')
33 elif not isinstance(arg, str):
39 def import_simplejson():
41 import simplejson as json
44 import json # Python 2.6+
47 from django.utils import simplejson as json # Google App Engine
49 raise ImportError("Can't load a json library")
53 def list_to_csv(item_list):
55 return ','.join([str(i) for i in item_list])
57 def urlencode_noplus(query):
58 return '&'.join(['%s=%s' % (quote(str(k), ''), quote(str(v), '')) \
59 for k, v in query.iteritems()])