Ejemplo n.º 1
0
    def manage_editForm(self, URL1, REQUEST):
        '''Display doc template editing form'''  #"

        return self._manage_editForm(self,
                                     mapping=REQUEST,
                                     __str__=str(self),
                                     URL1=URL1)
Ejemplo n.º 2
0
 def manage_editForm(self, URL1, REQUEST):
     '''Display doc template editing form''' #"
     
     return self._manage_editForm(
         self,
         mapping=REQUEST,
         __str__=str(self),
         URL1=URL1
         )
Ejemplo n.º 3
0
def restructured_text(v, name='(Unknown name)', md={}):

    from reStructuredText import HTML

    if isinstance(v,StringType): 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)
Ejemplo n.º 4
0
def restructured_text(v, name='(Unknown name)', md={}):

    from reStructuredText 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)

    return HTML(txt)
Ejemplo n.º 5
0
def structured_text(v, name='(Unknown name)', md={}):

    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 = getConfiguration().structured_text_header_level
    doc = DocumentWithImages()(txt)
    return HTML()(doc, level, header=False)
Ejemplo n.º 6
0
    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,
        )
Ejemplo n.º 7
0
def structured_text(v, name='(Unknown name)', md={}):
    global StructuredText
    if StructuredText is None:
        from StructuredText.StructuredText import HTML

    if isinstance(v,StringType): 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,
                level=int(os.environ.get('STX_DEFAULT_LEVEL',3)),
                header=0)
Ejemplo n.º 8
0
def thousands_commas(v, name='(Unknown name)', md={},
                     thou=regex.compile(
                         "\([0-9]\)\([0-9][0-9][0-9]\([,.]\|$\)\)").search):
    v=str(v)
    vl=split(v,'.')
    if not vl: return v
    v=vl[0]
    del vl[0]
    if vl: s='.'+join(vl,'.')
    else: s=''
    l=thou(v)
    while l >= 0:
        v=v[:l+1]+','+v[l+1:]
        l=thou(v)
    return v+s
Ejemplo n.º 9
0
    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,
                                     )
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
def thousands_commas(
        v,
        name='(Unknown name)',
        md={},
        thou=regex.compile("\([0-9]\)\([0-9][0-9][0-9]\([,.]\|$\)\)").search):
    v = str(v)
    vl = split(v, '.')
    if not vl: return v
    v = vl[0]
    del vl[0]
    if vl: s = '.' + join(vl, '.')
    else: s = ''
    l = thou(v)
    while l >= 0:
        v = v[:l + 1] + ',' + v[l + 1:]
        l = thou(v)
    return v + s
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
def url_unquote_plus(v, name='(Unknown name)', md={}):
    return unquote_plus(str(v))
Ejemplo n.º 14
0
def url_quote(v, name='(Unknown name)', md={}):
    return quote(str(v))
Ejemplo n.º 15
0
    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
Ejemplo n.º 16
0
def structured_text(v, name='(Unknown name)', md={}):
    global StructuredText
    if StructuredText is None: import StructuredText
    return str(StructuredText.html_with_references(str(v), 3))
Ejemplo n.º 17
0
def structured_text(v, name='(Unknown name)', md={}):
    global StructuredText
    if StructuredText is None: import StructuredText
    return str(StructuredText.html_with_references(str(v), 3))
Ejemplo n.º 18
0
    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'):
            fmt = args['fmt']
            if have_arg('null') and not val and val != 0:
                try:
                    if hasattr(val, fmt):
                        val = getattr(val, fmt)()
                    elif special_formats.has_key(fmt):
                        val = special_formats[fmt](val, name, md)
                    elif 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 = getattr(val, fmt)()
                elif special_formats.has_key(fmt):
                    val = special_formats[fmt](val, name, md)
                elif fmt == '':
                    val = ''
                else:
                    val = fmt % val

        # finally, pump it through the actual string format...
        fmt = self.fmt
        if fmt == 's': val = str(val)
        else: val = ('%' + self.fmt) % (val, )

        # next, look for upper, lower, etc
        for f in self.modifiers:
            val = f(val)

        if have_arg('size'):
            size = args['size']
            try:
                size = atoi(size)
            except:
                raise 'Document Error', (
                    '''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 = rfind(val, ' ')
                if l > size / 2:
                    val = val[:l + 1]
                if have_arg('etc'): l = args['etc']
                else: l = '...'
                val = val + l

        return val
Ejemplo n.º 19
0
    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
Ejemplo n.º 20
0
def newline_to_br(v, name='(Unknown name)', md={}):
    v = str(v)
    if find(v, '\r') >= 0: v = join(split(v, '\r'), '')
    if find(v, '\n') >= 0: v = join(split(v, '\n'), '<br>\n')
    return v
Ejemplo n.º 21
0
def url_quote(v, name='(Unknown name)', md={}):
    return quote(str(v))
Ejemplo n.º 22
0
    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'):
            fmt=args['fmt']
            if have_arg('null') and not val and val != 0:
                try:
                    if hasattr(val, fmt):
                        val = getattr(val,fmt)()
                    elif special_formats.has_key(fmt):
                        val = special_formats[fmt](val, name, md)
                    elif 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 = getattr(val,fmt)()
                elif special_formats.has_key(fmt):
                    val = special_formats[fmt](val, name, md)
                elif fmt=='': val=''
                else: val = fmt % val

        # finally, pump it through the actual string format...
        fmt=self.fmt
        if fmt=='s': val=str(val)
        else: val = ('%'+self.fmt) % (val,)

        # next, look for upper, lower, etc
        for f in self.modifiers: val=f(val)

        if have_arg('size'):
            size=args['size']
            try: size=int(size)
            except: raise 'Document Error',(
                '''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

        return val
Ejemplo n.º 23
0
def len_format(v, name='(Unknown name)', md={}):
    return str(len(v))
Ejemplo n.º 24
0
def len_format(v, name='(Unknown name)', md={}):
    return str(len(v))
Ejemplo n.º 25
0
def len_comma(v, name='(Unknown name)', md={}):
    return thousands_commas(str(len(v)))
Ejemplo n.º 26
0
def len_comma(v, name='(Unknown name)', md={}):
    return thousands_commas(str(len(v)))
Ejemplo n.º 27
0
def url_unquote_plus(v, name='(Unknown name)', md={}):
    return unquote_plus(str(v))
Ejemplo n.º 28
0
def newline_to_br(v, name='(Unknown name)', md={}):
    v=str(v)
    if find(v,'\r') >= 0: v=join(split(v,'\r'),'')
    if find(v,'\n') >= 0: v=join(split(v,'\n'),'<br>\n')
    return v
Ejemplo n.º 29
0
def newline_to_br(v, name='(Unknown name)', md={}):
    v=str(v)
    if v.find('\r') >= 0: v=''.join(v.split('\r'))
    if v.find('\n') >= 0: v='<br />\n'.join(v.split('\n'))
    return v
Ejemplo n.º 30
0
def newline_to_br(v, name='(Unknown name)', md={}):
    v = str(v)
    if v.find('\r') >= 0: v = ''.join(v.split('\r'))
    if v.find('\n') >= 0: v = '<br />\n'.join(v.split('\n'))
    return v