[Twisted-Python] PATCH: Improved scheme handling in t/lore/latex.py

Cory Dodt corydodt at yahoo.com
Thu Nov 21 14:43:16 MST 2002


This patch uses urlparse to get URLs from html documents in a more
generalizable way.

It also adds the ftp scheme, and handles mailto schemes like the rest of
them.

URLs with no scheme are handled the regular way.

____snip____
diff -u -r1.67 latex.py
--- latex.py    17 Nov 2002 18:32:56 -0000      1.67
+++ latex.py    21 Nov 2002 21:37:41 -0000
@@ -20,6 +20,8 @@
 import os, re
 from cStringIO import StringIO

+import urlparse
+
 import tree

 escapingRE = re.compile(r'([#$%&_{}^~\\])')
@@ -140,13 +142,12 @@
                     % latexEscape(os.path.basename(fileName)))

     def visitNode_a_href(self, node):
+        supported_schemes=['http', 'https', 'ftp', 'mailto']
         self.visitNodeDefault(node)
         href = node.getAttribute('href')
-        if href.startswith('http://') or href.startswith('https://'):
+        if urlparse.urlparse(href)[0] in supported_schemes:
             if node.childNodes[0].data != href:
                 self.writer('\\footnote{%s}' % latexEscape(href))
-        elif href.startswith('mailto:'):
-            pass
         else:
             if href.startswith('#'):
                 href = self.filename + href

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com




More information about the Twisted-Python mailing list