def process_rule(self, rule, is_ancestor, maximum_specificities): selector = rule['selector'] sheet_index = rule['sheet_index'] rule_address = rule['rule_address'] or () if selector is not None: try: specificity = [0] + list(parse(selector)[0].specificity()) except (AttributeError, TypeError, SelectorError): specificity = [0, 0, 0, 0] else: # style attribute specificity = [1, 0, 0, 0] specificity.extend((sheet_index, tuple(rule_address))) ancestor_specificity = 0 if is_ancestor else 1 properties = [] for prop in rule['properties']: important = 1 if prop[-1] == 'important' else 0 p = Property(prop, [ancestor_specificity] + [important] + specificity) properties.append(p) if p.specificity > maximum_specificities.get(p.name, (0,0,0,0,0,0)): maximum_specificities[p.name] = p.specificity rule['properties'] = properties href = rule['href'] if hasattr(href, 'startswith') and href.startswith('%s://%s' % (FAKE_PROTOCOL, FAKE_HOST)): qurl = QUrl(href) name = qurl.path()[1:] if name: rule['href'] = name
def process_rule(self, rule, is_ancestor, maximum_specificities): selector = rule['selector'] sheet_index = rule['sheet_index'] rule_address = rule['rule_address'] or () if selector is not None: try: specificity = [0] + list(parse(selector)[0].specificity()) except (AttributeError, TypeError, SelectorError): specificity = [0, 0, 0, 0] else: # style attribute specificity = [1, 0, 0, 0] specificity.extend((sheet_index, tuple(rule_address))) ancestor_specificity = 0 if is_ancestor else 1 properties = [] for prop in rule['properties']: important = 1 if prop[-1] == 'important' else 0 p = Property(prop, [ancestor_specificity] + [important] + specificity) properties.append(p) if p.specificity > maximum_specificities.get( p.name, (0, 0, 0, 0, 0, 0)): maximum_specificities[p.name] = p.specificity rule['properties'] = properties href = rule['href'] if hasattr(href, 'startswith') and href.startswith( '%s://%s' % (FAKE_PROTOCOL, FAKE_HOST)): qurl = QUrl(href) name = qurl.path()[1:] if name: rule['href'] = name
def set_message(self, text, color_, bold=False, is_permanent=False): from vise.view import certificate_error_domains key = (text, color_.name(), bold, is_permanent) if key == self.current_key: return self.current_key = key self.is_permanent = is_permanent prefix = text.partition(':')[0] self.is_address = self.is_permanent and prefix.lower() in { 'http', 'https', 'vise', 'file' } self.is_secure = prefix.lower() in {'https', 'vise', 'file'} color_ = color_ or self.palette().color(self.palette().WindowText) if self.is_address: qurl = QUrl(text) if self.is_secure and qurl.host() in certificate_error_domains: self.is_secure = False if qurl.scheme() in {'vise', 'file'}: host = qurl.path() rest = '' sep = ':' else: host = qurl.host() rest = qurl.toDisplayString(QUrl.PrettyDecoded | QUrl.RemoveScheme | QUrl.RemoveAuthority) sep = '://' self.static_text = QStaticText( '<span style="white-space:nowrap; color: {fg}">' '<span style="color:{emph}; font-weight:bold">{scheme}</span><span style="color:{dull}">{sep}</span>' '<span style="color:{fg}">{host}</span>' '<span style="color:{dull}">{rest}</span>'.format( fg=color_.name(), emph='green' if self.is_secure else 'red', scheme=escape(qurl.scheme()), host=escape(host), dull=color('status bar dull foreground', 'gray'), sep=sep, rest=escape(rest))) else: self.static_text = QStaticText( '<span style="color:{}; font-weight: {}; white-space:nowrap">{}</span>' .format(color_.name(), ('bold' if bold else 'normal'), escape(text))) to = QTextOption(Qt.AlignLeft | Qt.AlignTop) to.setWrapMode(to.NoWrap) self.static_text.setTextOption(to) self.static_text.prepare(font=self.font()) self.update()
def set_message(self, text, color_, bold=False, is_permanent=False): from vise.view import certificate_error_domains key = (text, color_.name(), bold, is_permanent) if key == self.current_key: return self.current_key = key self.is_permanent = is_permanent prefix = text.partition(':')[0] self.is_address = self.is_permanent and prefix.lower() in {'http', 'https', 'vise'} self.is_secure = prefix.lower() in {'https', 'vise'} color_ = color_ or self.palette().color(self.palette().WindowText) if self.is_address: qurl = QUrl(text) if self.is_secure and qurl.host() in certificate_error_domains: self.is_secure = False if qurl.scheme() == 'vise': host = qurl.path() rest = '' sep = ':' else: host = qurl.host() rest = qurl.toDisplayString(QUrl.PrettyDecoded | QUrl.RemoveScheme | QUrl.RemoveAuthority) sep = '://' self.static_text = QStaticText( '<span style="white-space:nowrap; color: {fg}">' '<span style="color:{emph}; font-weight:bold">{scheme}</span><span style="color:{dull}">{sep}</span>' '<span style="color:{fg}">{host}</span>' '<span style="color:{dull}">{rest}</span>'.format( fg=color_.name(), emph='green' if self.is_secure else 'red', scheme=escape(qurl.scheme()), host=escape(host), dull=color('status bar dull foreground', 'gray'), sep=sep, rest=escape(rest) )) else: self.static_text = QStaticText('<span style="color:{}; font-weight: {}; white-space:nowrap">{}</span>'.format( color_.name(), ('bold' if bold else 'normal'), escape(text))) to = QTextOption(Qt.AlignLeft | Qt.AlignTop) to.setWrapMode(to.NoWrap) self.static_text.setTextOption(to) self.static_text.prepare(font=self.font()) self.update()
def getFolderName(self, url): u = QUrl(url) return u.path()[:len(u.path()) - len(u.fileName())]