def _spec_from_url(self, url):
        """If `url` is the URL of a specification, return it.

        This implementation is a little fuzzy and will return specs for URLs
        that, for example, don't have the host name right.  This seems
        unlikely to cause confusion in practice, and being too anal probably
        would be confusing (e.g. not accepting production URLs on staging).
        """
        scheme, netloc, path, params, args, fragment = urlparse(url)
        if not scheme or not netloc:
            # Not enough like a URL
            return None
        path_segments = path.strip('/').split('/')
        if len(path_segments) != 3:
            # Can't be a spec url
            return None
        pillar_name, plus_spec, spec_name = path_segments
        if plus_spec != '+spec':
            # Can't be a spec url
            return None
        pillar = getUtility(IPillarNameSet).getByName(
            pillar_name, ignore_inactive=True)
        if pillar is None:
            return None
        return pillar.getSpecification(spec_name)
Exemple #2
0
    def _rewrite_url(self, url):
        """Rewrite the url to the local environment.

        Links with launchpad.net are rewritten to the local hostname,
        except if the domain matches a domain in the url_rewrite_exceptions.
        property.

        :param url: A URL str that may be rewritten to the local
            launchpad environment.
        :return: A URL str.
        """
        url = self._sanitize_query_string(url)
        if self.url_rewrite_hostname == 'launchpad.net':
            # Do not rewrite the url is the hostname is the public hostname.
            return self._strip_trailing_slash(url)
        parts = urlparse(url)
        for netloc in self.url_rewrite_exceptions:
            # The network location is parts[1] in the tuple.
            if netloc in parts[1]:
                return url
        local_scheme = self.url_rewrite_scheme
        local_hostname = parts[1].replace('launchpad.net',
                                          self.url_rewrite_hostname)
        local_parts = tuple([local_scheme] + [local_hostname] +
                            list(parts[2:]))
        url = urlunparse(local_parts)
        return self._strip_trailing_slash(url)
Exemple #3
0
    def feed_id(self):
        """See `IFeed`.

        Override this method if the context used does not create a
        meaningful id.
        """
        # Get the creation date, if available.  Otherwise use a fixed date, as
        # allowed by the RFC.
        if getattr(self.context, 'datecreated', None) is not None:
            datecreated = self.context.datecreated.date().isoformat()
        elif getattr(self.context, 'date_created', None) is not None:
            datecreated = self.context.date_created.date().isoformat()
        else:
            datecreated = "2008"
        url_path = urlparse(self.link_alternate)[2]
        if self.rootsite != 'mainsite':
            id_ = 'tag:launchpad.net,%s:/%s%s' % (
                datecreated,
                self.rootsite,
                url_path)
        else:
            id_ = 'tag:launchpad.net,%s:%s' % (
                datecreated,
                url_path)
        return id_
    def _rewrite_url(self, url):
        """Rewrite the url to the local environment.

        Links with launchpad.net are rewritten to the local hostname,
        except if the domain matches a domain in the url_rewrite_exceptions.
        property.

        :param url: A URL str that may be rewritten to the local
            launchpad environment.
        :return: A URL str.
        """
        url = self._sanitize_query_string(url)
        if self.url_rewrite_hostname == 'launchpad.net':
            # Do not rewrite the url is the hostname is the public hostname.
            return self._strip_trailing_slash(url)
        parts = urlparse(url)
        for netloc in self.url_rewrite_exceptions:
            # The network location is parts[1] in the tuple.
            if netloc in parts[1]:
                return url
        local_scheme = self.url_rewrite_scheme
        local_hostname = parts[1].replace(
            'launchpad.net', self.url_rewrite_hostname)
        local_parts = tuple(
            [local_scheme] + [local_hostname] + list(parts[2:]))
        url = urlunparse(local_parts)
        return self._strip_trailing_slash(url)
    def _spec_from_url(self, url):
        """If `url` is the URL of a specification, return it.

        This implementation is a little fuzzy and will return specs for URLs
        that, for example, don't have the host name right.  This seems
        unlikely to cause confusion in practice, and being too anal probably
        would be confusing (e.g. not accepting production URLs on staging).
        """
        scheme, netloc, path, params, args, fragment = urlparse(url)
        if not scheme or not netloc:
            # Not enough like a URL
            return None
        path_segments = path.strip('/').split('/')
        if len(path_segments) != 3:
            # Can't be a spec url
            return None
        pillar_name, plus_spec, spec_name = path_segments
        if plus_spec != '+spec':
            # Can't be a spec url
            return None
        pillar = getUtility(IPillarNameSet).getByName(
            pillar_name, ignore_inactive=True)
        if pillar is None:
            return None
        return pillar.getSpecification(spec_name)
Exemple #6
0
    def feed_id(self):
        """See `IFeed`.

        Override this method if the context used does not create a
        meaningful id.
        """
        # Get the creation date, if available.  Otherwise use a fixed date, as
        # allowed by the RFC.
        if getattr(self.context, 'datecreated', None) is not None:
            datecreated = self.context.datecreated.date().isoformat()
        elif getattr(self.context, 'date_created', None) is not None:
            datecreated = self.context.date_created.date().isoformat()
        else:
            datecreated = "2008"
        url_path = urlparse(self.link_alternate)[2]
        if self.rootsite != 'mainsite':
            id_ = 'tag:launchpad.net,%s:/%s%s' % (
                datecreated,
                self.rootsite,
                url_path)
        else:
            id_ = 'tag:launchpad.net,%s:%s' % (
                datecreated,
                url_path)
        return id_
Exemple #7
0
 def _sanitize_query_string(self, url):
     """Escapes invalid urls."""
     parts = urlparse(url)
     querydata = parse_qsl(parts.query)
     querystring = urllib.urlencode(querydata)
     urldata = list(parts)
     urldata[-2] = querystring
     return urlunparse(urldata)
Exemple #8
0
 def feed_id(self):
     """See `IFeed`."""
     datecreated = self.context.datecreated.date().isoformat()
     url_path = urlparse(self.link_alternate)[2]
     id_ = 'tag:launchpad.net,%s:%s' % (
         datecreated,
         url_path)
     return id_
 def _sanitize_query_string(self, url):
     """Escapes invalid urls."""
     parts = urlparse(url)
     querydata = parse_qsl(parts.query)
     querystring = urllib.urlencode(querydata)
     urldata = list(parts)
     urldata[-2] = querystring
     return urlunparse(urldata)
Exemple #10
0
 def feed_id(self):
     """See `IFeed`."""
     datecreated = self.context.datecreated.date().isoformat()
     url_path = urlparse(self.link_alternate)[2]
     id_ = 'tag:launchpad.net,%s:%s' % (
         datecreated,
         url_path)
     return id_
Exemple #11
0
 def feed_id(self):
     """See `IFeed`."""
     # Get the creation date, if available.
     if hasattr(self.context, 'date_created'):
         datecreated = self.context.date_created.date().isoformat()
     elif hasattr(self.context, 'datecreated'):
         datecreated = self.context.datecreated.date().isoformat()
     else:
         datecreated = '2008'
     url_path = urlparse(self.link_alternate)[2]
     id_ = 'tag:launchpad.net,%s:/%s%s' % (datecreated, self.rootsite,
                                           url_path)
     return id_
Exemple #12
0
 def feed_id(self):
     """See `IFeed`."""
     # Get the creation date, if available.
     if hasattr(self.context, 'date_created'):
         datecreated = self.context.date_created.date().isoformat()
     elif hasattr(self.context, 'datecreated'):
         datecreated = self.context.datecreated.date().isoformat()
     else:
         datecreated = '2008'
     url_path = urlparse(self.link_alternate)[2]
     id_ = 'tag:launchpad.net,%s:/%s%s' % (
         datecreated,
         self.rootsite,
         url_path)
     return id_
Exemple #13
0
 def construct_id(self):
     url_path = urlparse(self.link_alternate)[2]
     return 'tag:launchpad.net,%s:%s' % (
         self.date_created.date().isoformat(), url_path)
Exemple #14
0
 def construct_id(self):
     url_path = urlparse(self.link_alternate)[2]
     return 'tag:launchpad.net,%s:/code%s' % (
         self.date_created.date().isoformat(),
         url_path)