comparison bitsyblog/utils.py @ 113:8f30c2f702bc

py3
author Jeff Hammel <k0scist@gmail.com>
date Tue, 03 Nov 2020 14:07:56 -0800
parents e5a23f5ea14e
children 73434c2db108
comparison
equal deleted inserted replaced
112:d1114b31aaf1 113:8f30c2f702bc
13 13
14 # format to uniquely label blog posts 14 # format to uniquely label blog posts
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
18 def ReST2html(string): 19 def ReST2html(string):
19 """renders a string with restructured text""" 20 """renders a string with restructured text"""
20 21
21 settings = { 'report_level': 5 } 22 settings = { 'report_level': 5 }
22 string = string.strip() 23 string = string.strip()
23 try: 24 try:
24 parts = docutils.core.publish_parts(string, 25 parts = docutils.core.publish_parts(string,
25 writer_name='html', 26 writer_name='html',
26 settings_overrides=settings) 27 settings_overrides=settings)
27 body = parts['body'] 28 body = parts['body']
28 except (SystemMessage, UnicodeError), e: 29 except (SystemMessage, UnicodeError) as e:
29 lines = [ cgi.escape(i.strip()) for i in string.split('\n') ] 30 lines = [ cgi.escape(i.strip()) for i in string.split('\n') ]
30 body = '<br/>\n'.join(lines) 31 body = '<br/>\n'.join(lines)
31 return body 32 return body
33
32 34
33 def validate_css(css): 35 def validate_css(css):
34 """use a webservice to determine if the argument is valid css""" 36 """use a webservice to determine if the argument is valid css"""
35 url = 'http://jigsaw.w3.org/css-validator/validator?text=%s' 37 url = 'http://jigsaw.w3.org/css-validator/validator?text=%s'
36 url = url % urllib.quote_plus(css) 38 url = url % urllib.quote_plus(css)