def manage_editForm(self, URL1, REQUEST): '''Display doc template editing form''' return self._manage_editForm(self, mapping=REQUEST, __str__=str(self), URL1=URL1)
def url_unquote_plus(v, name='(Unknown name)', md={}): if six.PY2 and isinstance(v, unicode): # unquote_plus does not handle unicode. Encoding to a "safe" # intermediate encoding before quoting, then unencoding the result. return unquote_plus(v.encode('utf-8')).decode('utf-8') elif six.PY3 and isinstance(v, bytes): return unquote_plus(v.decode('utf-8')).encode('utf-8') return unquote_plus(str(v))
def manage_editForm(self, URL1, REQUEST): '''Display doc template editing form''' return self._manage_editForm( self, mapping=REQUEST, __str__=str(self), URL1=URL1 )
def manage_editForm(self, URL1, REQUEST): '''Display doc template editing form''' return self._manage_editForm( mapping=REQUEST, document_template_edit_width=self.document_template_edit_width, document_template_edit_header=self.document_template_edit_header, document_template_form_header=self.document_template_form_header, document_template_edit_footer=self.document_template_edit_footer, URL1=URL1, __str__=str(self), FactoryDefaultString=FactoryDefaultString, )
def restructured_text(v, name='(Unknown name)', md={}): try: from reStructuredText import HTML except ImportError: logger.info('The reStructuredText package is not available, therefor ' 'the DT_Var.restructured_text function returns None.') return None if isinstance(v, str): txt = v elif aq_base(v).meta_type in ['DTML Document','DTML Method']: txt = aq_base(v).read_raw() else: txt = str(v) return HTML(txt)
def thousands_commas(v, name='(Unknown name)', md={}, thou=re.compile( r"([0-9])([0-9][0-9][0-9]([,.]|$))").search): v=str(v) vl=v.split('.') if not vl: return v v=vl[0] del vl[0] if vl: s='.'+'.'.join(vl) else: s='' mo=thou(v) while mo is not None: l = mo.start(0) v=v[:l+1]+','+v[l+1:] mo=thou(v) return v+s
def restructured_text(v, name='(Unknown name)', md={}): try: from reStructuredText import HTML except ImportError: logger.info('The reStructuredText package is not available, therefor ' 'the DT_Var.restructured_text function returns None.') return None if isinstance(v, str): txt = v elif aq_base(v).meta_type in ['DTML Document', 'DTML Method']: txt = aq_base(v).read_raw() else: txt = str(v) return HTML(txt)
def thousands_commas( v, name='(Unknown name)', md={}, thou=re.compile(r"([0-9])([0-9][0-9][0-9]([,.]|$))").search): v = str(v) vl = v.split('.') if not vl: return v v = vl[0] del vl[0] if vl: s = '.' + '.'.join(vl) else: s = '' mo = thou(v) while mo is not None: l = mo.start(0) v = v[:l + 1] + ',' + v[l + 1:] mo = thou(v) return v + s
def structured_text(v, name='(Unknown name)', md={}): from zope.structuredtext.html import HTML if isinstance(v, str): txt = v elif aq_base(v).meta_type in ['DTML Document', 'DTML Method']: txt = aq_base(v).read_raw() else: txt = str(v) level = 3 try: from App.config import getConfiguration except ImportError: pass else: level = getConfiguration().structured_text_header_level doc = DocumentWithImages()(txt) return HTML()(doc, level, header=False)
def structured_text(v, name='(Unknown name)', md={}): from zope.structuredtext.html import HTML if isinstance(v, str): txt = v elif aq_base(v).meta_type in ['DTML Document','DTML Method']: txt = aq_base(v).read_raw() else: txt = str(v) level = 3 try: from App.config import getConfiguration except ImportError: pass else: level = getConfiguration().structured_text_header_level doc = DocumentWithImages()(txt) return HTML()(doc, level, header=False)
def url_quote(v, name='(Unknown name)', md={}): return quote(str(v))
def len_format(v, name='(Unknown name)', md={}): return str(len(v))
def len_comma(v, name='(Unknown name)', md={}): return thousands_commas(str(len(v)))
def render(self, md): args=self.args have_arg=args.has_key name=self.__name__ val=self.expr if val is None: if md.has_key(name): if have_arg('url'): val=md.getitem(name,0) val=val.absolute_url() else: val = md[name] else: if have_arg('missing'): return args['missing'] else: raise KeyError, name else: val=val.eval(md) if have_arg('url'): val=val.absolute_url() __traceback_info__=name, val, args if have_arg('null') and not val and val != 0: # check for null (false but not zero, including None, [], '') return args['null'] # handle special formats defined using fmt= first if have_arg('fmt'): _get = getattr(md, 'guarded_getattr', None) if _get is None: _get = getattr fmt=args['fmt'] if have_arg('null') and not val and val != 0: try: if hasattr(val, fmt): val = _get(val, fmt)() elif special_formats.has_key(fmt): if fmt == 'html-quote' and \ isinstance(val, TaintedString): # TaintedStrings will be quoted by default, don't # double quote. pass else: val = special_formats[fmt](val, name, md) elif fmt=='': val='' else: if isinstance(val, TaintedString): val = TaintedString(fmt % val) else: val = fmt % val except: t, v= sys.exc_type, sys.exc_value if hasattr(sys, 'exc_info'): t, v = sys.exc_info()[:2] if val is None or not str(val): return args['null'] raise t, v else: # We duplicate the code here to avoid exception handler # which tends to screw up stack or leak if hasattr(val, fmt): val = _get(val, fmt)() elif special_formats.has_key(fmt): if fmt == 'html-quote' and \ isinstance(val, TaintedString): # TaintedStrings will be quoted by default, don't # double quote. pass else: val = special_formats[fmt](val, name, md) elif fmt=='': val='' else: if isinstance(val, TaintedString): val = TaintedString(fmt % val) else: val = fmt % val # finally, pump it through the actual string format... fmt=self.fmt if fmt=='s': # Keep tainted strings as tainted strings here. if not isinstance(val, TaintedString): val=ustr(val) else: # Keep tainted strings as tainted strings here. wastainted = 0 if isinstance(val, TaintedString): wastainted = 1 val = ('%'+self.fmt) % (val,) if wastainted and '<' in val: val = TaintedString(val) # next, look for upper, lower, etc for f in self.modifiers: if f.__name__ == 'html_quote' and isinstance(val, TaintedString): # TaintedStrings will be quoted by default, don't double quote. continue val=f(val) if have_arg('size'): size=args['size'] try: size=int(size) except: raise ValueError,( '''a <code>size</code> attribute was used in a <code>var</code> tag with a non-integer value.''') if len(val) > size: val=val[:size] l=val.rfind(' ') if l > size/2: val=val[:l+1] if have_arg('etc'): l=args['etc'] else: l='...' val=val+l if isinstance(val, TaintedString): val = val.quoted() return val
def url_unquote(v, name='(Unknown name)', md={}): if isinstance(v, unicode): # unquote does not handle unicode. Encoding to a "safe" # intermediate encoding before quoting, then unencoding the result. return unquote(v.encode('utf-8')).decode('UTF-8') return unquote(str(v))
def render(self, md): args = self.args name = self.__name__ val = self.expr if val is None: if name in md: if 'url' in args: val = md.getitem(name, 0) val = val.absolute_url() else: val = md[name] else: if 'missing' in args: return args['missing'] else: raise KeyError(name) else: val = val.eval(md) if 'url' in args: val = val.absolute_url() __traceback_info__ = name, val, args if 'null' in args and not val and val != 0: # check for null (false but not zero, including None, [], '') return args['null'] # handle special formats defined using fmt= first if 'fmt' in args: _get = getattr(md, 'guarded_getattr', None) if _get is None: _get = getattr fmt = args['fmt'] if 'null' in args and not val and val != 0: try: if hasattr(val, fmt): val = _get(val, fmt)() elif fmt in special_formats: if fmt == 'html-quote' and \ isinstance(val, TaintedString): # TaintedStrings will be quoted by default, don't # double quote. pass else: val = special_formats[fmt](val, name, md) elif fmt == '': val = '' else: if isinstance(val, TaintedString): val = TaintedString(fmt % val) else: val = fmt % val except: t, v = sys.exc_type, sys.exc_value if hasattr(sys, 'exc_info'): t, v = sys.exc_info()[:2] if val is None or not str(val): return args['null'] raise t(v) else: # We duplicate the code here to avoid exception handler # which tends to screw up stack or leak if hasattr(val, fmt): val = _get(val, fmt)() elif fmt in special_formats: if (fmt == 'html-quote' and isinstance(val, TaintedString)): # TaintedStrings will be quoted by default, don't # double quote. pass else: val = special_formats[fmt](val, name, md) elif fmt == '': val = '' else: if isinstance(val, TaintedString): val = TaintedString(fmt % val) else: val = fmt % val # finally, pump it through the actual string format... fmt = self.fmt if fmt == 's': # Keep tainted strings as tainted strings here. if not isinstance(val, TaintedString): val = ustr(val) else: # Keep tainted strings as tainted strings here. wastainted = 0 if isinstance(val, TaintedString): wastainted = 1 val = ('%' + self.fmt) % (val, ) if wastainted and '<' in val: val = TaintedString(val) # next, look for upper, lower, etc for f in self.modifiers: if f.__name__ == 'html_quote' and isinstance(val, TaintedString): # TaintedStrings will be quoted by default, don't double quote. continue val = f(val) if 'size' in args: size = args['size'] try: size = int(size) except Exception: raise ValueError( 'a <code>size</code> attribute was used in a ' '<code>var</code> tag with a non-integer value.') if len(val) > size: val = val[:size] l = val.rfind(' ') if l > size / 2: val = val[:l + 1] if 'etc' in args: l = args['etc'] else: l = '...' val = val + l if isinstance(val, TaintedString): val = val.quoted() return val
def url_unquote_plus(v, name='(Unknown name)', md={}): return unquote_plus(str(v))