from Globals import InitializeClass _excluded_html = [ (('center', 'span', 'tt', 'big', 'small', 'u', 's', 'strike', 'basefont', 'font', 'title', 'meta'), ()), ((), ('dir','lang','valign','halign','border','frame','rules','cellspacing','cellpadding','bgcolor')), (('table','th','td'),('width','height')), ] from OFS.SimpleItem import SimpleItem class TatsKupuLibraryTool(SimpleItem): id = 'kupu_library_tool' meta_type = "Tats Kupu Library Tool" def __init__(self): self.html_exclusions = _excluded_html def getHtmlExclusions(self): return _excluded_html def getStyleWhitelist(self): return ['text-align', 'list-style-type', 'float'] def getClassBlacklist(self): return [] def installBeforeUnload(self): return getattr(self, 'install_beforeunload', True) def isKupuEnabled(self, useragent='', allowAnonymous=False, REQUEST=None, context=None, fieldName=None): def numerics(s): '''Convert a string into a tuple of all digit sequences ''' seq = [''] for c in s: if c.isdigit(): seq[-1] = seq[-1] + c elif seq[-1]: seq.append('') return tuple([ int(val) for val in seq if val]) # Then check whether the current content allows html if context is not None and fieldName and hasattr(context, 'getWrappedField'): field = context.getWrappedField(fieldName) if field: allowedTypes = getattr(field, 'allowable_content_types', None) if allowedTypes is not None and not 'text/html' in [t.lower() for t in allowedTypes]: return False # Then check whether their browser supports it. if not useragent: useragent = REQUEST['HTTP_USER_AGENT'] if 'Opera' in useragent or 'BEOS' in useragent: return False if not useragent.startswith('Mozilla/'): return False try: mozillaver = numerics(useragent[len('Mozilla/'):].split(' ')[0]) if mozillaver > (5,0): return True elif mozillaver == (5,0): rv = useragent.find(' rv:') if rv >= 0: verno = numerics(useragent[rv+4:].split(')')[0]) return verno >= (1,3,1) MSIE = useragent.find('MSIE') if MSIE >= 0: verno = numerics(useragent[MSIE+4:].split(';')[0]) return verno >= (5,5) except: # In case some weird browser makes the test code blow up. pass return False InitializeClass(TatsKupuLibraryTool)