utils.py
branch3.5
changeset 3101 e75ab3635f07
parent 2936 f35b64718d02
parent 3094 978ed8c2c0e4
child 3146 cfc4344023f2
child 3231 3ee43e2f8560
equal deleted inserted replaced
3100:b0a583156d6d 3101:e75ab3635f07
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 """
     7 """
     8 __docformat__ = "restructuredtext en"
     8 __docformat__ = "restructuredtext en"
       
     9 
       
    10 from logilab.mtconverter import xml_escape
     9 
    11 
    10 import locale
    12 import locale
    11 from md5 import md5
    13 from md5 import md5
    12 from datetime import datetime, timedelta, date
    14 from datetime import datetime, timedelta, date
    13 from time import time, mktime
    15 from time import time, mktime
   260                 w(u'%s = %s;\n' % (var, dumps(value)))
   262                 w(u'%s = %s;\n' % (var, dumps(value)))
   261             w(u'//--><!]]></script>\n')
   263             w(u'//--><!]]></script>\n')
   262         # 2/ css files
   264         # 2/ css files
   263         for cssfile, media in self.cssfiles:
   265         for cssfile, media in self.cssfiles:
   264             w(u'<link rel="stylesheet" type="text/css" media="%s" href="%s"/>\n' %
   266             w(u'<link rel="stylesheet" type="text/css" media="%s" href="%s"/>\n' %
   265               (media, cssfile))
   267               (media, xml_escape(cssfile)))
   266         # 3/ ie css if necessary
   268         # 3/ ie css if necessary
   267         if self.ie_cssfiles:
   269         if self.ie_cssfiles:
   268             w(u'<!--[if lt IE 8]>\n')
   270             w(u'<!--[if lt IE 8]>\n')
   269             for cssfile, media in self.ie_cssfiles:
   271             for cssfile, media in self.ie_cssfiles:
   270                 w(u'<link rel="stylesheet" type="text/css" media="%s" href="%s"/>\n' %
   272                 w(u'<link rel="stylesheet" type="text/css" media="%s" href="%s"/>\n' %
   271                   (media, cssfile))
   273                   (media, xml_escape(cssfile)))
   272             w(u'<![endif]--> \n')
   274             w(u'<![endif]--> \n')
   273         # 4/ js files
   275         # 4/ js files
   274         for jsfile in self.jsfiles:
   276         for jsfile in self.jsfiles:
   275             w(u'<script type="text/javascript" src="%s"></script>\n' % jsfile)
   277             w(u'<script type="text/javascript" src="%s"></script>\n' %
       
   278               xml_escape(jsfile))
   276         # 5/ post inlined scripts (i.e. scripts depending on other JS files)
   279         # 5/ post inlined scripts (i.e. scripts depending on other JS files)
   277         if self.post_inlined_scripts:
   280         if self.post_inlined_scripts:
   278             w(u'<script type="text/javascript">\n')
   281             w(u'<script type="text/javascript">\n')
   279             w(u'\n\n'.join(self.post_inlined_scripts))
   282             w(u'\n\n'.join(self.post_inlined_scripts))
   280             w(u'\n</script>\n')
   283             w(u'\n</script>\n')
   303         # xmldecl and html opening tag
   306         # xmldecl and html opening tag
   304         self.xmldecl = u'<?xml version="1.0" encoding="%s"?>\n' % req.encoding
   307         self.xmldecl = u'<?xml version="1.0" encoding="%s"?>\n' % req.encoding
   305         self.htmltag = u'<html xmlns="http://www.w3.org/1999/xhtml" ' \
   308         self.htmltag = u'<html xmlns="http://www.w3.org/1999/xhtml" ' \
   306                        'xmlns:cubicweb="http://www.logilab.org/2008/cubicweb" ' \
   309                        'xmlns:cubicweb="http://www.logilab.org/2008/cubicweb" ' \
   307                        'xml:lang="%s" lang="%s">' % (req.lang, req.lang)
   310                        'xml:lang="%s" lang="%s">' % (req.lang, req.lang)
   308 
   311         # keep main_stream's reference on req for easier text/html demoting
       
   312         req.main_stream = self
   309 
   313 
   310     def write(self, data):
   314     def write(self, data):
   311         """StringIO interface: this method will be assigned to self.w
   315         """StringIO interface: this method will be assigned to self.w
   312         """
   316         """
   313         self.body.write(data)
   317         self.body.write(data)