[Checkins] SVN: lovely.tal/trunk/ finishing preparations for egg

Michael Zauchner auon at lovelysystems.com
Mon Mar 3 06:22:46 EST 2008


Log message for revision 84435:
  finishing preparations for egg

Changed:
  U   lovely.tal/trunk/CHANGES.txt
  U   lovely.tal/trunk/setup.py
  U   lovely.tal/trunk/src/lovely/tal/README.txt
  U   lovely.tal/trunk/src/lovely/tal/textformatter.py

-=-
Modified: lovely.tal/trunk/CHANGES.txt
===================================================================
--- lovely.tal/trunk/CHANGES.txt	2008-03-03 06:06:21 UTC (rev 84434)
+++ lovely.tal/trunk/CHANGES.txt	2008-03-03 11:22:45 UTC (rev 84435)
@@ -2,6 +2,11 @@
 lovely.tal
 ==========
 
+2008/03/03 0.3a:
+================
+ - urlparse condition added
+
+
 2007/08/29 0.2.1:
 =================
  - prepare checkin on zope.org

Modified: lovely.tal/trunk/setup.py
===================================================================
--- lovely.tal/trunk/setup.py	2008-03-03 06:06:21 UTC (rev 84434)
+++ lovely.tal/trunk/setup.py	2008-03-03 11:22:45 UTC (rev 84435)
@@ -5,18 +5,14 @@
     return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
 long_description=(
-        read('src', 'lovely', 'tal', 'README.txt'))
-        + '\n' +
-        read('CHANGES.txt')
-        + '\n' +
-        'Download\n'
-        '**********************\n'
+        read('src', 'lovely', 'tal', 'README.txt')
         )
+#long_description=()
 
 name='lovely.tal'
 setup(
     name = name,
-    version = '0.2.1',
+    version = '0.3a',
     author = "Lovely Systems GmbH",
     author_email = "office at lovelysystems.com",
     description = "the lovely tal enables new tal expressions",

Modified: lovely.tal/trunk/src/lovely/tal/README.txt
===================================================================
--- lovely.tal/trunk/src/lovely/tal/README.txt	2008-03-03 06:06:21 UTC (rev 84434)
+++ lovely.tal/trunk/src/lovely/tal/README.txt	2008-03-03 11:22:45 UTC (rev 84435)
@@ -33,12 +33,19 @@
   works only together with option ``cut``, attaches the given string to the 
   expression, if this is longer than number of characters given in option 
   ``cut``
-  
+
+option urlparse:
+  parsing of http:// or www. strings to hyperlinks, got a dictonary of parameters 
+  e.g. urlparse python:{'rel':'nofollow','target':'_blank', allready existing
+  anchor tags are extended with the parameters in the dictionary, image tags
+  stay untouched in this whole parsing process
+
 Example::
 			
   <span tal:define="replace python:[('\n', '<br />')];
                     allow python:['a', 'br'];
                     break-string python:25;
+                    urlparse python:{'rel':'nofollow','target':'_blank'};
                     cut python 25;
                     attach '...'"
         tal:content="structure textFormatter: view/description">Description</span>
@@ -199,3 +206,23 @@
   >>> context = Context({'cut':20, 'attach':'...'})
   >>> tf._doFormat('ein superlangerstring mit ein paar kurzen strings', context)
   'ein superlangerstrin...'
+
+
+Option 'urlparse'
+=================
+
+parse the urls in the expression:
+
+    >>> context = Context({})
+    >>> context = Context({'urlparse':{'rel':'nofollow','target':'_blank'},'allow':['a', 'br']})
+    >>> tf._doFormat('<a href="http://www.lovelysystems.com/~auon/index.html">lovelysystems</a> rocks your zope', context)
+    '<a href="http://www.lovelysystems.com/~auon/index.html" target="_blank" rel="nofollow">lovelysystems</a> rocks your zope'
+
+    >>> tf._doFormat('ha ha hell yeah http://www.lovelysystems.com/ rocks your zope', context)
+    '...<a href="http://www.lovelysystems.com/" target="_blank" rel="nofollow">http://www.lovelysystems.com/</a>...'
+
+    >>> tf._doFormat('ha ha hell yeah www.lovelysystems.com/ rocks your zope', context)
+    '...<a href="http://www.lovelysystems.com/" target="_blank" rel="nofollow">www.lovelysystems.com/</a>...'
+
+    >>> tf._doFormat('ha ha hell yeah <img src="http://www.lovelysystems.com/image.jpg" /> rocks your zope', context)
+    '...&lt;img src="http://www.lovelysystems.com/image.jpg" /&gt;...'

Modified: lovely.tal/trunk/src/lovely/tal/textformatter.py
===================================================================
--- lovely.tal/trunk/src/lovely/tal/textformatter.py	2008-03-03 06:06:21 UTC (rev 84434)
+++ lovely.tal/trunk/src/lovely/tal/textformatter.py	2008-03-03 11:22:45 UTC (rev 84435)
@@ -51,6 +51,9 @@
         if 'cut' in context.vars:
             rendered = self._cut(rendered, context)
 
+        if 'urlparse' in context.vars:
+            rendered = self._urlparse(rendered, context)
+
         return rendered
 
     def _replace(self, rendered, context):
@@ -84,7 +87,6 @@
 
 
             #find tags with no closing tag like <input type="submit" value="bla" />
-            reg = re.compile('<%s[^>]*/>' %al, re.VERBOSE)
             found = reg.findall(rendered)
             for f in found:
                 f_rep = f.replace('<', '__LOWER__')
@@ -151,3 +153,48 @@
             return rendered + attach
         return rendered
 
+    def _urlparse(self, rendered, context):
+        #searches for urls coded with www. or http:
+
+        vars = context.vars['urlparse']
+        parameters=""
+        
+        if vars:
+            for k, v in vars.items():
+                parameters +='%s="%s" ' % (k, v)
+        else:
+            parameters ='rel="nofollow" target="_blank"'
+
+        search = re.compile(
+               '(((<a\s*href\s*=\s*")?|(\s*src\s*=\s*")?)'\
+               '(http:\\/\\/|www)[-A-Za-z0-9]*\\.[-A-Za-z0-9\\.]+'\
+               '(~/|/|\\./)?([-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:'\
+               '@&=\\?/~\\#\\%]+|\\\\ )+"?)'
+                )
+
+        results = search.findall(rendered)
+        searchLink = re.compile('^(<a\s*href\s*=\s*")')
+
+
+        for url in results:
+            if url[1] == '':
+                newurl = ' <a href="%s%s" %s>%s</a> ' % (
+                        'http://', 
+                        url[0].lstrip(), 
+                        parameters.rstrip(), 
+                        url[0].lstrip())
+
+                if url[4] == "http://":
+                    newurl = '<a href="%s" %s>%s</a>' % (
+                            url[0], 
+                            parameters.rstrip(), 
+                            url[0])
+
+                rendered = rendered.replace(url[0],newurl)
+
+            if searchLink.search(url[1]) and parameters !="":
+                link = '%s %s' % (url[0], parameters.rstrip())
+                rendered = rendered.replace(url[0],link)
+
+        return rendered
+



More information about the Checkins mailing list