home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) __all__ = [ 'Profiles'] __docformat__ = 'restructuredtext' __version__ = '$Id: cssproperties.py 1116 2008-03-05 13:52:23Z cthedot $' import re class NoSuchProfileException(Exception): pass class Profiles(object): CSS_LEVEL_2 = 'CSS Level 2.1' CSS3_BOX = CSS_BOX_LEVEL_3 = 'CSS Box Module Level 3' CSS3_COLOR = CSS_COLOR_LEVEL_3 = 'CSS Color Module Level 3' CSS3_FONTS = 'CSS Fonts Module Level 3' CSS3_FONT_FACE = 'CSS Fonts Module Level 3 @font-face properties' CSS3_PAGED_MEDIA = 'CSS3 Paged Media Module' _TOKEN_MACROS = { 'ident': '[-]?{nmstart}{nmchar}*', 'name': '{nmchar}+', 'nmstart': '[_a-z]|{nonascii}|{escape}', 'nonascii': '[^\\0-\\177]', 'unicode': '\\\\[0-9a-f]{1,6}(\\r\\n|[ \\n\\r\\t\\f])?', 'escape': '{unicode}|\\\\[ -~\\200-\\777]', 'int': '[-]?\\d+', 'nmchar': '[\\w-]|{nonascii}|{escape}', 'num': '[-]?\\d+|[-]?\\d*\\.\\d+', 'positivenum': '\\d+|\\d*\\.\\d+', 'number': '{num}', 'string': '{string1}|{string2}', 'string1': '"(\\\\\\"|[^\\"])*"', 'uri': 'url\\({w}({string}|(\\\\\\)|[^\\)])+){w}\\)', 'string2': "'(\\\\\\'|[^\\'])*'", 'nl': '\\n|\\r\\n|\\r|\\f', 'w': '\\s*' } _MACROS = { 'hexcolor': '#[0-9a-f]{3}|#[0-9a-f]{6}', 'rgbcolor': 'rgb\\({w}{int}{w},{w}{int}{w},{w}{int}{w}\\)|rgb\\({w}{num}%{w},{w}{num}%{w},{w}{num}%{w}\\)', 'namedcolor': '(transparent|orange|maroon|red|orange|yellow|olive|purple|fuchsia|white|lime|green|navy|blue|aqua|teal|black|silver|gray)', 'uicolor': '(ActiveBorder|ActiveCaption|AppWorkspace|Background|ButtonFace|ButtonHighlight|ButtonShadow|ButtonText|CaptionText|GrayText|Highlight|HighlightText|InactiveBorder|InactiveCaption|InactiveCaptionText|InfoBackground|InfoText|Menu|MenuText|Scrollbar|ThreeDDarkShadow|ThreeDFace|ThreeDHighlight|ThreeDLightShadow|ThreeDShadow|Window|WindowFrame|WindowText)', 'color': '{namedcolor}|{hexcolor}|{rgbcolor}|{uicolor}', 'integer': '{int}', 'length': '0|{num}(em|ex|px|in|cm|mm|pt|pc)', 'positivelength': '0|{positivenum}(em|ex|px|in|cm|mm|pt|pc)', 'angle': '0|{num}(deg|grad|rad)', 'time': '0|{num}m?s', 'frequency': '0|{num}k?Hz', 'percentage': '{num}%' } def __init__(self, log = None): self._log = log self._profileNames = [] self._profiles = { } self._defaultProfiles = None self.addProfile(self.CSS_LEVEL_2, properties[self.CSS_LEVEL_2], macros[self.CSS_LEVEL_2]) self.addProfile(self.CSS3_BOX, properties[self.CSS3_BOX], macros[self.CSS3_BOX]) self.addProfile(self.CSS3_COLOR, properties[self.CSS3_COLOR], macros[self.CSS3_COLOR]) self.addProfile(self.CSS3_FONTS, properties[self.CSS3_FONTS], macros[self.CSS3_FONTS]) self.addProfile(self.CSS3_FONT_FACE, properties[self.CSS3_FONT_FACE], macros[self.CSS3_FONTS]) self.addProfile(self.CSS3_PAGED_MEDIA, properties[self.CSS3_PAGED_MEDIA], macros[self.CSS3_PAGED_MEDIA]) self._Profiles__update_knownNames() def _expand_macros(self, dictionary, macros): def macro_value(m): return '(?:%s)' % macros[m.groupdict()['macro']] for key, value in dictionary.items(): dictionary[key] = value return dictionary def _compile_regexes(self, dictionary): for key, value in dictionary.items(): if not hasattr(value, '__call__'): value = re.compile('^(?:%s)$' % value, re.I).match dictionary[key] = value return dictionary def __update_knownNames(self): self._knownNames = [] for properties in self._profiles.values(): self._knownNames.extend(properties.keys()) def _getDefaultProfiles(self): if not self._defaultProfiles: return self.profiles return self._defaultProfiles def _setDefaultProfiles(self, profiles): if isinstance(profiles, basestring): self._defaultProfiles = (profiles,) else: self._defaultProfiles = profiles defaultProfiles = property(_getDefaultProfiles, _setDefaultProfiles, doc = u'Names of profiles to use for validation.To use e.g. the CSS2 profile set ``cssutils.profile.defaultProfiles = cssutils.profile.CSS_LEVEL_2``') profiles = property((lambda self: self._profileNames), doc = u'Names of all profiles in order as defined.') knownNames = property((lambda self: self._knownNames), doc = 'All known property names of all profiles.') def addProfile(self, profile, properties, macros = None): if not macros: macros = { } m = Profiles._TOKEN_MACROS.copy() m.update(Profiles._MACROS) m.update(macros) properties = self._expand_macros(properties, m) self._profileNames.append(profile) self._profiles[profile] = self._compile_regexes(properties) self._Profiles__update_knownNames() def removeProfile(self, profile = None, all = False): if all: self._profiles.clear() del self._profileNames[:] else: try: del self._profiles[profile] del self._profileNames[self._profileNames.index(profile)] except KeyError: raise NoSuchProfileException(u'No profile %r.' % profile) self._Profiles__update_knownNames() def propertiesByProfile(self, profiles = None): if not profiles: profiles = self.profiles elif isinstance(profiles, basestring): profiles = (profiles,) try: for profile in sorted(profiles): for name in sorted(self._profiles[profile].keys()): yield name except KeyError: e = None raise NoSuchProfileException(e) def validate(self, name, value): for profile in self.profiles: if name in self._profiles[profile]: try: r = bool(self._profiles[profile][name](value)) except Exception: e = None self._log.error(e, error = Exception) return False if r: return r continue r return False def validateWithProfile(self, name, value, profiles = None): if name not in self.knownNames: return (False, False, []) if not profiles: profiles = self.defaultProfiles elif isinstance(profiles, basestring): profiles = (profiles,) for profilename in profiles: if name in self._profiles[profilename]: validate = self._profiles[profilename][name] try: if validate(value): return (True, True, [ profilename]) except Exception: e = None self._log.error(e, error = Exception) except: None<EXCEPTION MATCH>Exception None<EXCEPTION MATCH>Exception for profilename in (lambda .0: for p in .0: if p not in profiles: pcontinue)(self._profileNames): if name in self._profiles[profilename]: validate = self._profiles[profilename][name] try: if validate(value): return (True, False, [ profilename]) except Exception: (None,) e = (None,) self._log.error(e, error = Exception) except: (None,)<EXCEPTION MATCH>Exception (None,)<EXCEPTION MATCH>Exception names = [] for profilename, properties in self._profiles.items(): if name in properties.keys(): names.append(profilename) continue (None,) names.sort() return (False, False, names) properties = { } macros = { } macros[Profiles.CSS_LEVEL_2] = { 'border-style': 'none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset', 'border-color': '{color}', 'border-width': '{length}|thin|medium|thick', 'background-color': '{color}|transparent|inherit', 'background-image': '{uri}|none|inherit', 'background-position': '({percentage}|{length}|left|center|right)(\\s*({percentage}|{length}|top|center|bottom))?|((top|center|bottom)\\s*(left|center|right)?)|((left|center|right)\\s*(top|center|bottom)?)|inherit', 'background-repeat': 'repeat|repeat-x|repeat-y|no-repeat|inherit', 'background-attachment': 'scroll|fixed|inherit', 'shape': 'rect\\(({w}({length}|auto}){w},){3}{w}({length}|auto){w}\\)', 'counter': 'counter\\({w}{identifier}{w}(?:,{w}{list-style-type}{w})?\\)', 'identifier': '{ident}', 'family-name': '{string}|{identifier}({w}{identifier})*', 'generic-family': 'serif|sans-serif|cursive|fantasy|monospace', 'absolute-size': '(x?x-)?(small|large)|medium', 'relative-size': 'smaller|larger', 'font-family': '(({family-name}|{generic-family}){w},{w})*({family-name}|{generic-family})|inherit', 'font-size': '{absolute-size}|{relative-size}|{positivelength}|{percentage}|inherit', 'font-style': 'normal|italic|oblique|inherit', 'font-variant': 'normal|small-caps|inherit', 'font-weight': 'normal|bold|bolder|lighter|[1-9]00|inherit', 'line-height': 'normal|{number}|{length}|{percentage}|inherit', 'list-style-image': '{uri}|none|inherit', 'list-style-position': 'inside|outside|inherit', 'list-style-type': 'disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-greek|lower-(latin|alpha)|upper-(latin|alpha)|armenian|georgian|none|inherit', 'margin-width': '{length}|{percentage}|auto', 'outline-color': '{color}|invert|inherit', 'outline-style': '{border-style}|inherit', 'outline-width': '{border-width}|inherit', 'padding-width': '{length}|{percentage}', 'specific-voice': '{identifier}', 'generic-voice': 'male|female|child', 'content': '{string}|{uri}|{counter}|attr\\({w}{identifier}{w}\\)|open-quote|close-quote|no-open-quote|no-close-quote', 'border-attrs': '{border-width}|{border-style}|{border-color}', 'background-attrs': '{background-color}|{background-image}|{background-repeat}|{background-attachment}|{background-position}', 'list-attrs': '{list-style-type}|{list-style-position}|{list-style-image}', 'font-attrs': '{font-style}|{font-variant}|{font-weight}', 'outline-attrs': '{outline-color}|{outline-style}|{outline-width}', 'text-attrs': 'underline|overline|line-through|blink', 'overflow': 'visible|hidden|scroll|auto|inherit' } properties[Profiles.CSS_LEVEL_2] = { 'azimuth': '{angle}|(behind\\s+)?(left-side|far-left|left|center-left|center|center-right|right|far-right|right-side)(\\s+behind)?|behind|leftwards|rightwards|inherit', 'background-attachment': '{background-attachment}', 'background-color': '{background-color}', 'background-image': '{background-image}', 'background-position': '{background-position}', 'background-repeat': '{background-repeat}', 'background': '{background-attrs}(\\s+{background-attrs})*|inherit', 'border-collapse': 'collapse|separate|inherit', 'border-color': '({border-color}|transparent)(\\s+({border-color}|transparent)){0,3}|inherit', 'border-spacing': '{length}(\\s+{length})?|inherit', 'border-style': '{border-style}(\\s+{border-style}){0,3}|inherit', 'border-top': '{border-attrs}(\\s+{border-attrs})*|inherit', 'border-right': '{border-attrs}(\\s+{border-attrs})*|inherit', 'border-bottom': '{border-attrs}(\\s+{border-attrs})*|inherit', 'border-left': '{border-attrs}(\\s+{border-attrs})*|inherit', 'border-top-color': '{border-color}|transparent|inherit', 'border-right-color': '{border-color}|transparent|inherit', 'border-bottom-color': '{border-color}|transparent|inherit', 'border-left-color': '{border-color}|transparent|inherit', 'border-top-style': '{border-style}|inherit', 'border-right-style': '{border-style}|inherit', 'border-bottom-style': '{border-style}|inherit', 'border-left-style': '{border-style}|inherit', 'border-top-width': '{border-width}|inherit', 'border-right-width': '{border-width}|inherit', 'border-bottom-width': '{border-width}|inherit', 'border-left-width': '{border-width}|inherit', 'border-width': '{border-width}(\\s+{border-width}){0,3}|inherit', 'border': '{border-attrs}(\\s+{border-attrs})*|inherit', 'bottom': '{length}|{percentage}|auto|inherit', 'caption-side': 'top|bottom|inherit', 'clear': 'none|left|right|both|inherit', 'clip': '{shape}|auto|inherit', 'color': '{color}|inherit', 'content': 'none|normal|{content}(\\s+{content})*|inherit', 'counter-increment': '({identifier}(\\s+{integer})?)(\\s+({identifier}(\\s+{integer})))*|none|inherit', 'counter-reset': '({identifier}(\\s+{integer})?)(\\s+({identifier}(\\s+{integer})))*|none|inherit', 'cue-after': '{uri}|none|inherit', 'cue-before': '{uri}|none|inherit', 'cue': '({uri}|none|inherit){1,2}|inherit', 'cursor': '((({uri}{w},{w})*)?(auto|crosshair|default|pointer|move|(e|ne|nw|n|se|sw|s|w)-resize|text|wait|help|progress))|inherit', 'direction': 'ltr|rtl|inherit', 'display': 'inline|block|list-item|run-in|inline-block|table|inline-table|table-row-group|table-header-group|table-footer-group|table-row|table-column-group|table-column|table-cell|table-caption|none|inherit', 'elevation': '{angle}|below|level|above|higher|lower|inherit', 'empty-cells': 'show|hide|inherit', 'float': 'left|right|none|inherit', 'font-family': '{font-family}', 'font-size': '{font-size}', 'font-style': '{font-style}', 'font-variant': '{font-variant}', 'font-weight': '{font-weight}', 'font': '({font-attrs}\\s+)*{font-size}({w}/{w}{line-height})?\\s+{font-family}|caption|icon|menu|message-box|small-caption|status-bar|inherit', 'height': '{length}|{percentage}|auto|inherit', 'left': '{length}|{percentage}|auto|inherit', 'letter-spacing': 'normal|{length}|inherit', 'line-height': '{line-height}', 'list-style-image': '{list-style-image}', 'list-style-position': '{list-style-position}', 'list-style-type': '{list-style-type}', 'list-style': '{list-attrs}(\\s+{list-attrs})*|inherit', 'margin-right': '{margin-width}|inherit', 'margin-left': '{margin-width}|inherit', 'margin-top': '{margin-width}|inherit', 'margin-bottom': '{margin-width}|inherit', 'margin': '{margin-width}(\\s+{margin-width}){0,3}|inherit', 'max-height': '{length}|{percentage}|none|inherit', 'max-width': '{length}|{percentage}|none|inherit', 'min-height': '{length}|{percentage}|none|inherit', 'min-width': '{length}|{percentage}|none|inherit', 'orphans': '{integer}|inherit', 'outline-color': '{outline-color}', 'outline-style': '{outline-style}', 'outline-width': '{outline-width}', 'outline': '{outline-attrs}(\\s+{outline-attrs})*|inherit', 'overflow': '{overflow}', 'padding-top': '{padding-width}|inherit', 'padding-right': '{padding-width}|inherit', 'padding-bottom': '{padding-width}|inherit', 'padding-left': '{padding-width}|inherit', 'padding': '{padding-width}(\\s+{padding-width}){0,3}|inherit', 'page-break-after': 'auto|always|avoid|left|right|inherit', 'page-break-before': 'auto|always|avoid|left|right|inherit', 'page-break-inside': 'avoid|auto|inherit', 'pause-after': '{time}|{percentage}|inherit', 'pause-before': '{time}|{percentage}|inherit', 'pause': '({time}|{percentage}){1,2}|inherit', 'pitch-range': '{number}|inherit', 'pitch': '{frequency}|x-low|low|medium|high|x-high|inherit', 'play-during': '{uri}(\\s+(mix|repeat))*|auto|none|inherit', 'position': 'static|relative|absolute|fixed|inherit', 'quotes': '({string}\\s+{string})(\\s+{string}\\s+{string})*|none|inherit', 'richness': '{number}|inherit', 'right': '{length}|{percentage}|auto|inherit', 'speak-header': 'once|always|inherit', 'speak-numeral': 'digits|continuous|inherit', 'speak-punctuation': 'code|none|inherit', 'speak': 'normal|none|spell-out|inherit', 'speech-rate': '{number}|x-slow|slow|medium|fast|x-fast|faster|slower|inherit', 'stress': '{number}|inherit', 'table-layout': 'auto|fixed|inherit', 'text-align': 'left|right|center|justify|inherit', 'text-decoration': 'none|{text-attrs}(\\s+{text-attrs})*|inherit', 'text-indent': '{length}|{percentage}|inherit', 'text-transform': 'capitalize|uppercase|lowercase|none|inherit', 'top': '{length}|{percentage}|auto|inherit', 'unicode-bidi': 'normal|embed|bidi-override|inherit', 'vertical-align': 'baseline|sub|super|top|text-top|middle|bottom|text-bottom|{percentage}|{length}|inherit', 'visibility': 'visible|hidden|collapse|inherit', 'voice-family': '({specific-voice}|{generic-voice}{w},{w})*({specific-voice}|{generic-voice})|inherit', 'volume': '{number}|{percentage}|silent|x-soft|soft|medium|loud|x-loud|inherit', 'white-space': 'normal|pre|nowrap|pre-wrap|pre-line|inherit', 'widows': '{integer}|inherit', 'width': '{length}|{percentage}|auto|inherit', 'word-spacing': 'normal|{length}|inherit', 'z-index': 'auto|{integer}|inherit' } macros[Profiles.CSS3_BOX] = { 'overflow': macros[Profiles.CSS_LEVEL_2]['overflow'] } properties[Profiles.CSS3_BOX] = { 'overflow': '{overflow}{w}{overflow}?|inherit', 'overflow-x': '{overflow}|inherit', 'overflow-y': '{overflow}|inherit' } macros[Profiles.CSS3_COLOR] = { 'namedcolor': '(currentcolor|transparent|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow)', 'rgbacolor': 'rgba\\({w}{int}{w},{w}{int}{w},{w}{int}{w},{w}{int}{w}\\)|rgba\\({w}{num}%{w},{w}{num}%{w},{w}{num}%{w},{w}{num}{w}\\)', 'hslcolor': 'hsl\\({w}{int}{w},{w}{num}%{w},{w}{num}%{w}\\)|hsla\\({w}{int}{w},{w}{num}%{w},{w}{num}%{w},{w}{num}{w}\\)', 'x11color': 'aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen', 'uicolor': '(ActiveBorder|ActiveCaption|AppWorkspace|Background|ButtonFace|ButtonHighlight|ButtonShadow|ButtonText|CaptionText|GrayText|Highlight|HighlightText|InactiveBorder|InactiveCaption|InactiveCaptionText|InfoBackground|InfoText|Menu|MenuText|Scrollbar|ThreeDDarkShadow|ThreeDFace|ThreeDHighlight|ThreeDLightShadow|ThreeDShadow|Window|WindowFrame|WindowText)' } properties[Profiles.CSS3_COLOR] = { 'color': '{namedcolor}|{hexcolor}|{rgbcolor}|{rgbacolor}|{hslcolor}|inherit', 'opacity': '{num}|inherit' } macros[Profiles.CSS3_FONTS] = { 'family-name': '{string}|{ident}', 'font-face-name': 'local\\({w}{ident}{w}\\)', 'font-stretch-names': '(ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded)', 'unicode-range': '[uU]\\+[0-9A-Fa-f?]{1,6}(\\-[0-9A-Fa-f]{1,6})?' } properties[Profiles.CSS3_FONTS] = { 'font-size-adjust': '{number}|none|inherit', 'font-stretch': 'normal|wider|narrower|{font-stretch-names}|inherit' } properties[Profiles.CSS3_FONT_FACE] = { 'font-family': '{family-name}', 'font-stretch': '{font-stretch-names}', 'font-style': 'normal|italic|oblique', 'font-weight': 'normal|bold|[1-9]00', 'src': '({uri}{w}(format\\({w}{string}{w}(\\,{w}{string}{w})*\\))?|{font-face-name})({w},{w}({uri}{w}(format\\({w}{string}{w}(\\,{w}{string}{w})*\\))?|{font-face-name}))*', 'unicode-range': '{unicode-range}({w},{w}{unicode-range})*' } macros[Profiles.CSS3_PAGED_MEDIA] = { 'pagesize': 'a5|a4|a3|b5|b4|letter|legal|ledger', 'pagebreak': 'auto|always|avoid|left|right' } properties[Profiles.CSS3_PAGED_MEDIA] = { 'fit': 'fill|hidden|meet|slice', 'fit-position': 'auto|(({percentage}|{length})(\\s*({percentage}|{length}))?|((top|center|bottom)\\s*(left|center|right)?)|((left|center|right)\\s*(top|center|bottom)?))', 'image-orientation': 'auto|{angle}', 'orphans': '{integer}|inherit', 'page': 'auto|{ident}', 'page-break-before': '{pagebreak}|inherit', 'page-break-after': '{pagebreak}|inherit', 'page-break-inside': 'auto|avoid|inherit', 'size': '({length}{w}){1,2}|auto|{pagesize}{w}(?:portrait|landscape)', 'widows': '{integer}|inherit' }