Exemplo n.º 1
0
def normalize_url(url, domain_canonical=None):
    """
    Ensure we have a value url - raise exception if not.
    
    If given, we convert the domain to a domain_canonical
    """
    url = url.strip()
    rgURL = list(urlparse.urlsplit(url))
    if rgURL[split.scheme] == '':
        url = r"http://%s" % url
        rgURL = list(urlparse.urlsplit(url))

    # Invalid protocol
    if rgURL[split.scheme] != "http" and rgURL[split.scheme] != "https":
        raise reqfilter.Error("Invalid protocol: %s" % rgURL[split.scheme])

    if domain_canonical is not None:
        rgURL[split.domain] = domain_canonical

    if rgURL[split.domain]:
        rgURL[split.domain] = rgURL[split.domain].lower()

    if not rgURL[split.domain] or not regDomain.search(
            rgURL[split.domain]) or len(rgURL[split.domain]) > 255:
        raise reqfilter.Error("Invalid URL: %s" % urlparse.urlunsplit(rgURL))

    # Always end naked domains with a trailing slash as canonical
    if rgURL[split.path] == '':
        rgURL[split.path] = '/'

    return urlparse.urlunsplit(rgURL)
Exemplo n.º 2
0
    def ensure_cached(self):
        """
        ensures that this instance is in the cache.  If not, it will
        replace any existing instance from the cache - so any local modifications
        will be written to the cache (but not storage).
        
        Any modifications to the previously cached version will be lost!
        """
        model = self._model_from_cache(self.key().name())
        if model is self:
            # Not memcached -> write it so available to other instances/threads
            if not self._is_memcached:
                self._write_to_cache(self)
            return

        if model is not None and model._cache_state != self.cache_state.clean:
            raise reqfilter.Error("Replacing modified model from cache: %s" %
                                  self._model_cache_key())

        self._write_to_cache(self)
Exemplo n.º 3
0
 def migrate(self, schemaNext):
     raise reqfilter.Error("Application error - missing migration for %s" %
                           type(self).__name__)