Exemplo n.º 1
0
def make_bugtracker_name(uri):
    """Return a name string for a bug tracker based on a URI.

    :param uri: The base URI to be used to identify the bug tracker,
        e.g. http://bugs.example.com or mailto:[email protected]
    """
    base_uri = URI(uri)
    if base_uri.scheme == 'mailto':
        if valid_email(base_uri.path):
            base_name = base_uri.path.split('@', 1)[0]
        else:
            raise AssertionError(
                'Not a valid email address: %s' % base_uri.path)
    elif base_uri.host == 'github.com' and base_uri.path.endswith('/issues'):
        repository_id = base_uri.path[:-len('/issues')].lstrip('/')
        base_name = 'github-' + repository_id.replace('/', '-').lower()
    elif (('gitlab' in base_uri.host or
           base_uri.host == 'salsa.debian.org') and
          base_uri.path.endswith('/issues')):
        repository_id = base_uri.path[:-len('/issues')].lstrip('/')
        base_name = '%s-%s' % (
            base_uri.host, repository_id.replace('/', '-').lower())
    else:
        base_name = base_uri.host

    return 'auto-%s' % sanitize_name(base_name)
Exemplo n.º 2
0
    def _buildFromGpgmeKey(self, key):
        self.exists_in_local_keyring = True
        self.key = key
        subkey = key.subkeys[0]
        self.fingerprint = subkey.fpr
        self.revoked = subkey.revoked
        self.keysize = subkey.length

        self.algorithm = GPGKeyAlgorithm.items[subkey.pubkey_algo]
        self.keyid = self.fingerprint[-8:]
        self.expired = key.expired
        self.secret = key.secret
        self.owner_trust = key.owner_trust
        self.can_encrypt = key.can_encrypt
        self.can_sign = key.can_sign
        self.can_certify = key.can_certify
        self.can_authenticate = key.can_authenticate

        self.uids = [PymeUserId(uid) for uid in key.uids]

        # Non-revoked valid email addresses associated with this key
        self.emails = [
            uid.email for uid in self.uids
            if valid_email(uid.email) and not uid.revoked
        ]
Exemplo n.º 3
0
    def new(self, email, person=None, status=EmailAddressStatus.NEW):
        """See IEmailAddressSet."""
        email = email.strip()

        if not valid_email(email):
            raise InvalidEmailAddress("%s is not a valid email address." %
                                      email)

        if self.getByEmail(email) is not None:
            raise EmailAddressAlreadyTaken(
                "The email address '%s' is already registered." % email)
        assert status in EmailAddressStatus.items
        assert person
        return EmailAddress(email=email, status=status, person=person)
Exemplo n.º 4
0
 def new(self, requester, requesteremail, email, tokentype,
         fingerprint=None, redirection_url=None):
     """See ILoginTokenSet."""
     assert valid_email(email)
     if tokentype not in LoginTokenType.items:
         # XXX: Guilherme Salgado, 2005-12-09:
         # Aha! According to our policy, we shouldn't raise ValueError.
         raise ValueError(
             "tokentype is not an item of LoginTokenType: %s" % tokentype)
     token = create_unique_token_for_table(20, LoginToken.token)
     return LoginToken(requester=requester, requesteremail=requesteremail,
                       email=email, token=token, tokentype=tokentype,
                       created=UTC_NOW, fingerprint=fingerprint,
                       redirection_url=redirection_url)
Exemplo n.º 5
0
    def new(self, email, person=None, status=EmailAddressStatus.NEW):
        """See IEmailAddressSet."""
        email = email.strip()

        if not valid_email(email):
            raise InvalidEmailAddress(
                "%s is not a valid email address." % email)

        if self.getByEmail(email) is not None:
            raise EmailAddressAlreadyTaken(
                "The email address '%s' is already registered." % email)
        assert status in EmailAddressStatus.items
        assert person
        return EmailAddress(
            email=email,
            status=status,
            person=person)
Exemplo n.º 6
0
def make_bugtracker_title(uri):
    """Return a title string for a bug tracker based on a URI.

    :param uri: The base URI to be used to identify the bug tracker,
        e.g. http://bugs.example.com or mailto:[email protected]
    """
    base_uri = URI(uri)
    if base_uri.scheme == 'mailto':
        if valid_email(base_uri.path):
            local_part, domain = base_uri.path.split('@', 1)
            domain_parts = domain.split('.')
            return 'Email to %s@%s' % (local_part, domain_parts[0])
        else:
            raise AssertionError('Not a valid email address: %s' %
                                 base_uri.path)
    else:
        return base_uri.host + base_uri.path
Exemplo n.º 7
0
def make_bugtracker_name(uri):
    """Return a name string for a bug tracker based on a URI.

    :param uri: The base URI to be used to identify the bug tracker,
        e.g. http://bugs.example.com or mailto:[email protected]
    """
    base_uri = URI(uri)
    if base_uri.scheme == 'mailto':
        if valid_email(base_uri.path):
            base_name = base_uri.path.split('@', 1)[0]
        else:
            raise AssertionError('Not a valid email address: %s' %
                                 base_uri.path)
    else:
        base_name = base_uri.host

    return 'auto-%s' % sanitize_name(base_name)
Exemplo n.º 8
0
    def parseEmailAddressURL(self, scheme, host, path, query):
        """Extract an email address from a bug URL.

        This method will return (mailto:<email_address>, '') since email
        address bug trackers cannot have bug numbers. We return an empty
        string for the remote bug since BugWatch.remotebug cannot be
        None.
        """
        # We ignore anything that isn't a mailto URL.
        if scheme != 'mailto':
            return None

        # We also reject invalid email addresses.
        if not valid_email(path):
            return None

        return '%s:%s' % (scheme, path), ''
Exemplo n.º 9
0
    def parseEmailAddressURL(self, scheme, host, path, query):
        """Extract an email address from a bug URL.

        This method will return (mailto:<email_address>, '') since email
        address bug trackers cannot have bug numbers. We return an empty
        string for the remote bug since BugWatch.remotebug cannot be
        None.
        """
        # We ignore anything that isn't a mailto URL.
        if scheme != 'mailto':
            return None

        # We also reject invalid email addresses.
        if not valid_email(path):
            return None

        return '%s:%s' % (scheme, path), ''
Exemplo n.º 10
0
    def getPosterForComment(self, remote_bug_id, comment_id):
        """See `ISupportsCommentImport`."""
        bug = self.bugs[int(remote_bug_id)]
        comment = bug['comments'][comment_id]

        display_name, email = parseaddr(comment['user'])

        # If the email isn't valid, return the email address as the
        # display name (a Launchpad Person will be created with this
        # name).
        if not valid_email(email):
            return email, None
        # If the display name is empty, set it to None so that it's
        # useable by IPersonSet.ensurePerson().
        elif display_name == '':
            return None, email
        # Both displayname and email are valid, return both.
        else:
            return display_name, email
Exemplo n.º 11
0
    def getPosterForComment(self, remote_bug_id, comment_id):
        """See `ISupportsCommentImport`."""
        bug = self.bugs[int(remote_bug_id)]
        comment = bug['comments'][comment_id]

        display_name, email = parseaddr(comment['user'])

        # If the email isn't valid, return the email address as the
        # display name (a Launchpad Person will be created with this
        # name).
        if not valid_email(email):
            return email, None
        # If the display name is empty, set it to None so that it's
        # useable by IPersonSet.ensurePerson().
        elif display_name == '':
            return None, email
        # Both displayname and email are valid, return both.
        else:
            return display_name, email
Exemplo n.º 12
0
    def _buildFromGpgmeKey(self, key):
        self.exists_in_local_keyring = True
        subkey = key.subkeys[0]
        self.fingerprint = subkey.fpr
        self.revoked = subkey.revoked
        self.keysize = subkey.length

        self.algorithm = GPGKeyAlgorithm.items[subkey.pubkey_algo].title
        self.keyid = self.fingerprint[-8:]
        self.expired = key.expired
        self.secret = key.secret
        self.owner_trust = key.owner_trust
        self.can_encrypt = key.can_encrypt
        self.can_sign = key.can_sign
        self.can_certify = key.can_certify
        self.can_authenticate = key.can_authenticate

        self.uids = [PymeUserId(uid) for uid in key.uids]

        # Non-revoked valid email addresses associated with this key
        self.emails = [uid.email for uid in self.uids
                       if valid_email(uid.email) and not uid.revoked]
Exemplo n.º 13
0
def _validate_email(email):
    if not valid_email(email):
        raise LaunchpadValidationError(
            _("${email} isn't a valid email address.",
              mapping={'email': email}))
Exemplo n.º 14
0
def _validate_email(email):
    if not valid_email(email):
        raise LaunchpadValidationError(_(
            "${email} isn't a valid email address.",
            mapping={'email': email}))