[z3-checkins] r51391 - z3/deliverance/DeliveranceVHoster/trunk/utils

ejucovy at codespeak.net ejucovy at codespeak.net
Mon Feb 11 17:44:39 CET 2008


Author: ejucovy
Date: Mon Feb 11 17:44:37 2008
New Revision: 51391

Modified:
   z3/deliverance/DeliveranceVHoster/trunk/utils/embed_url.py
Log:
Add support for IE conditional comments...


Modified: z3/deliverance/DeliveranceVHoster/trunk/utils/embed_url.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/utils/embed_url.py	(original)
+++ z3/deliverance/DeliveranceVHoster/trunk/utils/embed_url.py	Mon Feb 11 17:44:37 2008
@@ -31,6 +31,11 @@
        Save the downloaded file(s) to a file based on the file name from the
        URL.
 
+    -c
+    --comment-hack
+       Hack IE conditional comments so that their internal resources will be
+       embedded as well.
+
     -i
     --image-strip
        Strip any img tags from the document, since the are links to external
@@ -95,10 +100,10 @@
     from sys import argv, exit, stderr
 
     try:
-        options, arguments = getopt(argv[1:], "hso:fdip", ["help", "save",
+        options, arguments = getopt(argv[1:], "hso:fdipc", ["help", "save",
                                                          "output=", "force",
                                                          "disable", "image-strip",
-                                                         "percent-escape"])
+                                                         "percent-escape", "comment-hack"])
     except GetoptError:
         __usage()
         exit(2)
@@ -106,6 +111,7 @@
     output = None
     image_strip = False
     percent_escape = False
+    comment_hack = False
     save = False
     force = False
     disable = False
@@ -118,6 +124,8 @@
             save = True
         elif option in ("-o", "--output"):
             output = value
+        elif option in ("-c", "--comment-hack"):
+            comment_hack = True
         elif option in ("-i", "--image-strip"):
             image_strip = True
         elif option in ("-p", "--percent-escape"):
@@ -149,7 +157,7 @@
         exit(2)
 
     for url in arguments:
-        embed_url(url, output, mode, image_strip, percent_escape)
+        embed_url(url, output, mode, image_strip, percent_escape, comment_hack)
 
 
 def __usage():
@@ -382,7 +390,7 @@
         self.parsed += "<?%s>" % data
 
 
-def embed_url(url, output_file=None, mode='Auto', image_strip=False, percent_escape=False):
+def embed_url(url, output_file=None, mode='Auto', image_strip=False, percent_escape=False, comment_hack=False):
     """
     Download a file from the internet, and process the links if it is HTML.
 
@@ -434,8 +442,16 @@
         # without changing links.
         embed_parser = EmbedParser(base_url, image_strip)
 
+        source = remote_file.read()
+        if comment_hack:
+            from re import sub
+            source = sub(r'(<!--\s*\[\s*if\s*([gl]te?\s*)?IE\s*(\d(\.\d+)?\s*)?\]>)',
+                         r'\1 comment_hack_begin -->', source)
+            source = sub(r'(<!\s*\[\s*endif\s*\]\s*-->)',
+                         r'<!-- comment_hack_end \1', source)
+
         try:
-            embed_parser.feed(remote_file.read())
+            embed_parser.feed(source)
         except HTMLParser.HTMLParseError:
             from sys import stderr
             output = remote_file.read()
@@ -444,6 +460,12 @@
         else:
             embed_parser.close()
             output = embed_parser.read()
+            if comment_hack:
+                from re import sub
+                output = sub(r'(<!--\s*\[\s*if\s*([gl]te?\s*)?IE\s*(\d(\.\d+)?\s*)?\]>)\s*comment_hack_begin\s*-->',
+                             r'\1', output)
+                output = sub(r'<!--\s*comment_hack_end\s*(<!\s*\[\s*endif\s*\]\s*-->)',
+                             r'\1', output)
     else:
         output = remote_file.read()
 


More information about the z3-checkins mailing list