2
# Copyright 2010 Joshua Roesslein
3
# See LICENSE for details.
5
from datetime import datetime
12
def parse_datetime(string):
13
# Set locale for date parsing
14
locale.setlocale(locale.LC_TIME, 'C')
16
# We must parse datetime this way to work in python 2.4
17
date = datetime(*(time.strptime(string, '%a %b %d %H:%M:%S +0000 %Y')[0:6]))
19
# Reset locale back to the default setting
20
locale.setlocale(locale.LC_TIME, '')
24
def parse_html_value(html):
26
return html[html.find('>')+1:html.rfind('<')]
29
def parse_a_href(atag):
31
start = atag.find('"') + 1
32
end = atag.find('"', start)
33
return atag[start:end]
36
def parse_search_datetime(string):
37
# Set locale for date parsing
38
locale.setlocale(locale.LC_TIME, 'C')
40
# We must parse datetime this way to work in python 2.4
41
date = datetime(*(time.strptime(string, '%a, %d %b %Y %H:%M:%S +0000')[0:6]))
43
# Reset locale back to the default setting
44
locale.setlocale(locale.LC_TIME, '')
48
def unescape_html(text):
49
"""Created by Fredrik Lundh (http://effbot.org/zone/re-sub.htm#unescape-html)"""
56
return unichr(int(text[3:-1], 16))
58
return unichr(int(text[2:-1]))
64
text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
67
return text # leave as is
68
return re.sub("&#?\w+;", fixup, text)
71
def convert_to_utf8_str(arg):
72
# written by Michael Norton (http://docondev.blogspot.com/)
73
if isinstance(arg, unicode):
74
arg = arg.encode('utf-8')
75
elif not isinstance(arg, str):
81
def import_simplejson():
83
import simplejson as json
86
import json # Python 2.6+
89
from django.utils import simplejson as json # Google App Engine
91
raise ImportError, "Can't load a json library"
95
def list_to_csv(item_list):
97
return ','.join([str(i) for i in item_list])