def parse(self, verify_signature=True): """Parse the tag file, optionally verifying the signature. If verify_signature is True, signingkey will be set to the signing `IGPGKey`, and only the verified content will be parsed. Otherwise, any signature will be stripped and the contained content parsed. Will raise an `UploadError` if the tag file was unparsable, or if signature verification was requested but failed. """ try: with open(self.filepath, 'rb') as f: self.raw_content = f.read() except IOError as error: raise UploadError( "Unable to read %s: %s" % (self.filename, error)) if verify_signature: self.signingkey, self.parsed_content = self.verifySignature( self.raw_content, self.filepath) else: self.logger.debug("%s can be unsigned." % self.filename) self.parsed_content = self.raw_content try: self._dict = parse_tagfile_content( self.parsed_content, filename=self.filepath) except TagFileParseError as error: raise UploadError( "Unable to parse %s: %s" % (self.filename, error))
def parse(self, verify_signature=True): """Parse the tag file, optionally verifying the signature. If verify_signature is True, signingkey will be set to the signing `IGPGKey`, and only the verified content will be parsed. Otherwise, any signature will be stripped and the contained content parsed. Will raise an `UploadError` if the tag file was unparsable, or if signature verification was requested but failed. """ try: with open(self.filepath, 'rb') as f: self.raw_content = f.read() except IOError as error: raise UploadError("Unable to read %s: %s" % (self.filename, error)) if verify_signature: self.signingkey, self.parsed_content = self.verifySignature( self.raw_content, self.filepath) else: self.logger.debug("%s can be unsigned." % self.filename) self.parsed_content = self.raw_content try: self._dict = parse_tagfile_content(self.parsed_content, filename=self.filepath) except TagFileParseError as error: raise UploadError("Unable to parse %s: %s" % (self.filename, error))
def get_bug_ids_from_changes_file(changes_file): """Parse the changes file and return a list of bug IDs referenced by it. The bugs is specified in the Launchpad-bugs-fixed header, and are separated by a space character. Nonexistent bug ids are ignored. """ tags = Deb822Dict(parse_tagfile_content(changes_file.read())) bugs_fixed = tags.get('Launchpad-bugs-fixed', '').split() return [int(bug_id) for bug_id in bugs_fixed if bug_id.isdigit()]
def parse(self, verify_signature=True, as_bytes=False): """Parse the tag file, optionally verifying the signature. If verify_signature is True, signingkey will be set to the signing `IGPGKey`, and only the verified content will be parsed. Otherwise, any signature will be stripped and the contained content parsed. Will raise an `UploadError` if the tag file was unparsable, or if signature verification was requested but failed. """ try: with open(self.filepath, 'rb') as f: self.raw_content = f.read() except IOError as error: raise UploadError("Unable to read %s: %s" % (self.filename, error)) if verify_signature: # We set self.signingkey regardless of whether the key is # deactivated or expired, since a deactivated or expired key is # still good enough for determining whom to notify, and raising # UploadError is enough to prevent the upload being accepted. try: self.signingkey, self.parsed_content = self._verifySignature( self.raw_content, self.filepath) if not self.signingkey.active: raise UploadError( "File %s is signed with a deactivated key %s" % (self.filepath, self.signingkey.fingerprint)) except GPGKeyExpired as e: # This may theoretically return None, but the "expired" # error will take precedence anyway. self.signingkey = getUtility(IGPGKeySet).getByFingerprint( e.key.fingerprint) raise UploadError("File %s is signed with an expired key %s" % (self.filepath, e.key.fingerprint)) else: self.logger.debug("%s can be unsigned." % self.filename) self.parsed_content = self.raw_content try: self._dict = parse_tagfile_content(self.parsed_content, filename=self.filepath, as_bytes=as_bytes) except TagFileParseError as error: raise UploadError("Unable to parse %s: %s" % (self.filename, error))