Mercurial > hg > bitsyblog
comparison bitsyblog/utils.py @ 84:e5a23f5ea14e
make cooked bodies depend on file mtime
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 17 Nov 2011 13:18:51 -0800 |
parents | 4df927b0d847 |
children | 8f30c2f702bc |
comparison
equal
deleted
inserted
replaced
83:666f3051ce31 | 84:e5a23f5ea14e |
---|---|
15 timeformat = ( 'YYYY', 'MM', 'DD', 'HH', 'MM', 'SS' ) | 15 timeformat = ( 'YYYY', 'MM', 'DD', 'HH', 'MM', 'SS' ) |
16 timestamp = '%Y%m%d%H%M%S' # strftime representation | 16 timestamp = '%Y%m%d%H%M%S' # strftime representation |
17 | 17 |
18 def ReST2html(string): | 18 def ReST2html(string): |
19 """renders a string with restructured text""" | 19 """renders a string with restructured text""" |
20 | 20 |
21 settings = { 'report_level': 5 } | 21 settings = { 'report_level': 5 } |
22 string = string.strip() | 22 string = string.strip() |
23 try: | 23 try: |
24 | |
25 parts = docutils.core.publish_parts(string, | 24 parts = docutils.core.publish_parts(string, |
26 writer_name='html', | 25 writer_name='html', |
27 settings_overrides=settings) | 26 settings_overrides=settings) |
28 body = parts['body'] | 27 body = parts['body'] |
29 except (SystemMessage, UnicodeError), e: | 28 except (SystemMessage, UnicodeError), e: |
30 lines = [ cgi.escape(i.strip()) for i in string.split('\n') ] | 29 lines = [ cgi.escape(i.strip()) for i in string.split('\n') ] |
31 body = '<br/>\n'.join(lines) | 30 body = '<br/>\n'.join(lines) |
32 return body | 31 return body |
33 | 32 |
34 def validate_css(css): | 33 def validate_css(css): |
35 """use a webservice to determine if the argument is valid css""" | 34 """use a webservice to determine if the argument is valid css""" |
36 url = 'http://jigsaw.w3.org/css-validator/validator?text=%s' | 35 url = 'http://jigsaw.w3.org/css-validator/validator?text=%s' |
37 url = url % urllib.quote_plus(css) | 36 url = url % urllib.quote_plus(css) |
38 foo = urllib2.urlopen(url) | 37 foo = urllib2.urlopen(url) |
39 text = foo.read() | 38 text = foo.read() |
40 return not 'We found the following errors' in text # XXX hacky | 39 return not 'We found the following errors' in text # XXX hacky |
46 retval.append(int(datestamp[:len(i)])) | 45 retval.append(int(datestamp[:len(i)])) |
47 datestamp = datestamp[len(i):] | 46 datestamp = datestamp[len(i):] |
48 return datetime.datetime(*retval) | 47 return datetime.datetime(*retval) |
49 | 48 |
50 def datestamp(date=None): | 49 def datestamp(date=None): |
50 if isinstance(date, float): | |
51 date = datetime.datetime.fromtimestamp(date) | |
51 if date is None: | 52 if date is None: |
52 date = datetime.datetime.now() | 53 date = datetime.datetime.now() |
53 return date.strftime(timestamp) | 54 return date.strftime(timestamp) |