2 # Copyright 2010 Joshua Roesslein
3 # See LICENSE for details.
5 from __future__ import print_function
7 from datetime import datetime
10 from six.moves.urllib.parse import quote
12 from email.utils import parsedate
15 def parse_datetime(string):
16 return datetime(*(parsedate(string)[:6]))
19 def parse_html_value(html):
21 return html[html.find('>')+1:html.rfind('<')]
24 def parse_a_href(atag):
26 start = atag.find('"') + 1
27 end = atag.find('"', start)
28 return atag[start:end]
31 def convert_to_utf8_str(arg):
32 # written by Michael Norton (http://docondev.blogspot.com/)
33 if isinstance(arg, six.text_type):
34 arg = arg.encode('utf-8')
35 elif not isinstance(arg, bytes):
36 arg = six.text_type(arg).encode('utf-8')
40 def import_simplejson():
42 import simplejson as json
45 import json # Python 2.6+
49 from django.utils import simplejson as json
51 raise ImportError("Can't load a json library")
56 def list_to_csv(item_list):
58 return ','.join([str(i) for i in item_list])