[Python-checkins] r50750 - sandbox/trunk/seealso/convert-python-faqs.py
andrew.kuchling
python-checkins at python.org
Fri Jul 21 15:04:52 CEST 2006
Author: andrew.kuchling
Date: Fri Jul 21 15:04:52 2006
New Revision: 50750
Modified:
sandbox/trunk/seealso/convert-python-faqs.py
Log:
Do YAML escapes somewhat properly; skip the 'test' category
Modified: sandbox/trunk/seealso/convert-python-faqs.py
==============================================================================
--- sandbox/trunk/seealso/convert-python-faqs.py (original)
+++ sandbox/trunk/seealso/convert-python-faqs.py Fri Jul 21 15:04:52 2006
@@ -13,6 +13,14 @@
DESTDIR = 'pyramid-faq'
+def yaml_escape (S):
+ "Escape S as a YAML string"
+ S = normalize_whitespace(S)
+ S = S.replace("\\", "\\\\")
+ S = S.replace('"', '\\"')
+ S = '"' + S + '"'
+ return S
+
def normalize_whitespace (S):
"""Replace all whitespace by single spaces.
>>> normalize_whitespace('a b\tc\nd')
@@ -45,6 +53,8 @@
if category is None:
##print 'Filename without category:', filename
return
+ if category in ('test',):
+ return
name = get_setting(root, 'name', base)
@@ -72,9 +82,9 @@
global:
metadata: {}
local:
- title: "%s"
+ title: %s
content: !fragment content.yml
- """ % title)
+ """ % yaml_escape(title))
f.close()
f = open(os.path.join(qdir, 'content.yml'), 'w')
@@ -108,15 +118,10 @@
title = normalize_whitespace(title)
i = title.find(':')
category = title[i+1:].strip()
+ idir = os.path.join(DESTDIR, category)
# XXX can there be subsections within a category?
- entries = []
- for para in root.findall('*/p'):
- a = para.find('a')
- if a is not None:
- entries.append(a)
-
- idir = os.path.join(DESTDIR, category)
+ entries = list(root.findall('*/p/a'))
# Write body of question
f = open(os.path.join(idir, 'listing.ht'), 'w')
@@ -132,9 +137,9 @@
template: index.html
# The data to pass to the template
local:
- title: "%s"
+ title: %s
content: !fragment content.yml
- """ % title)
+ """ % yaml_escape(title))
f.close()
f = open(os.path.join(idir, 'content.yml'), 'w')
More information about the Python-checkins
mailing list