def write_shield(self, status, colour='brightgreen'):
        '''Obtain and write the shield to the response.'''
        shield_url = SHIELD_URL % (
            self.shield_subject,
            status,
            colour,
            self.format,
        )
        style = self.request.args.get('style', 'flat')
        if style is not None and style[0] in ['flat', 'flat-square', 'plastic' ]:
            style = style[0]
        shield_url += "?style={0}".format(style)
        shield_url = shield_url.replace(" ", "_")

        ihash = self.hash(shield_url)
        cache = os.path.join(FILE_CACHE, ihash)
        if os.path.exists(cache) and self.cacheable:
            mtime = os.stat(cache).st_mtime + CACHE_TIME
            if mtime > time.time():
                return open(cache).read()

        shield_response = requests.get(shield_url, stream=True)
        img = BytesIO()
        for chunk in shield_response.iter_content(1024):
            if not chunk:
                break
            img.write(chunk)
        if self.cacheable:
            with open(cache, 'w') as ifile:
                img.seek(0)
                ifile.write(img.read())
        img.seek(0)
        return img.read()
dataset/ETHPy150Open badges/pypipins/shields/shields.py/PypiHandler.write_shield/original