prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  PySafetyBear: Add asciinema 
  Content of file on Bear will perform it's action also have to shown in asciinema.
  
  difficulty/newcomer
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `bears/python/requirements/PySafetyBear.py`
  Content:
  ```
  1 import os
  2 from collections import namedtuple
  3 import pkg_resources
  4 import re
  5 
  6 from safety import safety
  7 
  8 from coalib.bears.LocalBear import LocalBear
  9 from dependency_management.requirements.PipRequirement import PipRequirement
  10 from coalib.results.Result import Result
  11 from coalib.settings.Setting import path
  12 from coalib.results.SourceRange import SourceRange
  13 from coalib.settings.Setting import typed_list
  14 
  15 
  16 # It was for old versions of safety and those versions will be allow in future.
  17 def cve_key_checker(vulnerability):
  18     if 'cve' in vulnerability.data:
  19         if vulnerability.data['cve'] is None:
  20             return None
  21         else:
  22             return True
  23     else:
  24         return None
  25 
  26 
  27 # the safety module expects an object that looks like this
  28 # (not importing it from there because it's in a private-ish location)
  29 Package = namedtuple('Package', ('key', 'version'))
  30 
  31 safety_get_vulnerabilities = safety.get_vulnerabilities
  32 _insecure_full_json_url = ('https://raw.githubusercontent.com/pyupio/'
  33                            'safety-db/master/data/insecure_full.json')
  34 
  35 _insecure_json_url = ('https://raw.githubusercontent.com/'
  36                       'pyupio/safety-db/master/data/insecure.json')
  37 
  38 
  39 def _get_vulnerabilities(pkg, spec, db):
  40     for entry in safety_get_vulnerabilities(pkg, spec, db):
  41         entry['cve'] = entry['id'] if entry['cve'] is None else entry['cve']
  42         entry['id'] = entry['cve']
  43         yield entry
  44 
  45 
  46 safety.get_vulnerabilities = _get_vulnerabilities
  47 
  48 
  49 class PySafetyBear(LocalBear):
  50     """
  51     Checks if any of your Python dependencies have known security issues.
  52 
  53     Data is taken from pyup.io's vulnerability database hosted at
  54     https://github.com/pyupio/safety.
  55     """
  56 
  57     LANGUAGES = {
  58         'Python Requirements',
  59         'Python 2 Requirements',
  60         'Python 3 Requirements',
  61     }
  62     AUTHORS = {'Bence Nagy'}
  63     REQUIREMENTS = {PipRequirement('safety', '1.8.2')}
  64     AUTHORS_EMAILS = {'bence@underyx.me'}
  65     LICENSE = 'AGPL'
  66     CAN_DETECT = {'Security'}
  67 
  68     def setup_dependencies(self):
  69         file = self.download_cached_file(_insecure_full_json_url,
  70                                          'insecure_full.json')
  71         self.download_cached_file(_insecure_json_url,
  72                                   'insecure.json')
  73         type(self).db_path = os.path.dirname(file)
  74 
  75     def run(self, filename, file,
  76             db_path: path = '',
  77             cve_ignore: typed_list(str) = []):
  78         """
  79         Checks for vulnerable package versions in requirements files.
  80 
  81         :param db_path:           Path to a local vulnerability database.
  82         :param cve_ignore:        A list of CVE number to be ignore.
  83         """
  84         db_path = self.db_path if not db_path else db_path
  85         packages = list(
  86             Package(key=req.key, version=req.specs[0][1])
  87             for req in self.try_parse_requirements(file)
  88             if len(req.specs) == 1 and req.specs[0][0] == '=='
  89         )
  90 
  91         if not packages:
  92             return
  93 
  94         for vulnerability in safety.check(packages, key=None,
  95                                           db_mirror=db_path, cached=False,
  96                                           ignore_ids=cve_ignore):
  97             if 'cve' in vulnerability.vuln_id.strip().lower():
  98                 message_template = (
  99                     '{vuln.name}{vuln.spec} is vulnerable to {vuln.vuln_id} '
  100                     'and your project is using {vuln.version}.'
  101                 )
  102             else:
  103                 message_template = (
  104                     '{vuln.name}{vuln.spec} is vulnerable to '
  105                     'pyup.io-{vuln.vuln_id} and your project is using '
  106                     '{vuln.version}.'
  107                 )
  108 
  109             # StopIteration should not ever happen so skipping its branch
  110             line_number, line = next(  # pragma: no branch
  111                 (index, line) for index, line in enumerate(file, start=1)
  112                 if vulnerability.name in line
  113             )
  114             version_spec_match = re.search(r'[=<>]+(\S+?)(?:$|\s|#)', line)
  115             source_range = SourceRange.from_values(
  116                 filename,
  117                 line_number,
  118                 version_spec_match.start(1) + 1,
  119                 line_number,
  120                 version_spec_match.end(1) + 1,
  121             )
  122 
  123             yield Result(
  124                 self,
  125                 message_template.format(vuln=vulnerability),
  126                 additional_info=vulnerability.advisory,
  127                 affected_code=(source_range, ),
  128             )
  129 
  130     @staticmethod
  131     def try_parse_requirements(lines: typed_list(str)):
  132         """
  133         Yields all package requirements parsable from the given lines.
  134 
  135         :param lines: An iterable of lines from a requirements file.
  136         """
  137         for line in lines:
  138             try:
  139                 yield from pkg_resources.parse_requirements(line)
  140             except pkg_resources.RequirementParseError:
  141                 # unsupported requirement specification
  142                 pass
  143
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/bears/python/requirements/PySafetyBear.py b/bears/python/requirements/PySafetyBear.py
  --- a/bears/python/requirements/PySafetyBear.py
  +++ b/bears/python/requirements/PySafetyBear.py
  @@ -64,6 +64,7 @@
       AUTHORS_EMAILS = {'bence@underyx.me'}
       LICENSE = 'AGPL'
       CAN_DETECT = {'Security'}
  +    ASCIINEMA_URL = 'https://asciinema.org/a/221386'
   
       def setup_dependencies(self):
           file = self.download_cached_file(_insecure_full_json_url,
  
verification_info: {"golden_diff": "diff --git a/bears/python/requirements/PySafetyBear.py b/bears/python/requirements/PySafetyBear.py\n--- a/bears/python/requirements/PySafetyBear.py\n+++ b/bears/python/requirements/PySafetyBear.py\n@@ -64,6 +64,7 @@\n     AUTHORS_EMAILS = {'bence@underyx.me'}\n     LICENSE = 'AGPL'\n     CAN_DETECT = {'Security'}\n+    ASCIINEMA_URL = 'https://asciinema.org/a/221386'\n \n     def setup_dependencies(self):\n         file = self.download_cached_file(_insecure_full_json_url,\n", "issue": "PySafetyBear: Add asciinema \nContent of file on Bear will perform it's action also have to shown in asciinema.\r\n\r\ndifficulty/newcomer\n", "before_files": [{"content": "import os\nfrom collections import namedtuple\nimport pkg_resources\nimport re\n\nfrom safety import safety\n\nfrom coalib.bears.LocalBear import LocalBear\nfrom dependency_management.requirements.PipRequirement import PipRequirement\nfrom coalib.results.Result import Result\nfrom coalib.settings.Setting import path\nfrom coalib.results.SourceRange import SourceRange\nfrom coalib.settings.Setting import typed_list\n\n\n# It was for old versions of safety and those versions will be allow in future.\ndef cve_key_checker(vulnerability):\n    if 'cve' in vulnerability.data:\n        if vulnerability.data['cve'] is None:\n            return None\n        else:\n            return True\n    else:\n        return None\n\n\n# the safety module expects an object that looks like this\n# (not importing it from there because it's in a private-ish location)\nPackage = namedtuple('Package', ('key', 'version'))\n\nsafety_get_vulnerabilities = safety.get_vulnerabilities\n_insecure_full_json_url = ('https://raw.githubusercontent.com/pyupio/'\n                           'safety-db/master/data/insecure_full.json')\n\n_insecure_json_url = ('https://raw.githubusercontent.com/'\n                      'pyupio/safety-db/master/data/insecure.json')\n\n\ndef _get_vulnerabilities(pkg, spec, db):\n    for entry in safety_get_vulnerabilities(pkg, spec, db):\n        entry['cve'] = entry['id'] if entry['cve'] is None else entry['cve']\n        entry['id'] = entry['cve']\n        yield entry\n\n\nsafety.get_vulnerabilities = _get_vulnerabilities\n\n\nclass PySafetyBear(LocalBear):\n    \"\"\"\n    Checks if any of your Python dependencies have known security issues.\n\n    Data is taken from pyup.io's vulnerability database hosted at\n    https://github.com/pyupio/safety.\n    \"\"\"\n\n    LANGUAGES = {\n        'Python Requirements',\n        'Python 2 Requirements',\n        'Python 3 Requirements',\n    }\n    AUTHORS = {'Bence Nagy'}\n    REQUIREMENTS = {PipRequirement('safety', '1.8.2')}\n    AUTHORS_EMAILS = {'bence@underyx.me'}\n    LICENSE = 'AGPL'\n    CAN_DETECT = {'Security'}\n\n    def setup_dependencies(self):\n        file = self.download_cached_file(_insecure_full_json_url,\n                                         'insecure_full.json')\n        self.download_cached_file(_insecure_json_url,\n                                  'insecure.json')\n        type(self).db_path = os.path.dirname(file)\n\n    def run(self, filename, file,\n            db_path: path = '',\n            cve_ignore: typed_list(str) = []):\n        \"\"\"\n        Checks for vulnerable package versions in requirements files.\n\n        :param db_path:           Path to a local vulnerability database.\n        :param cve_ignore:        A list of CVE number to be ignore.\n        \"\"\"\n        db_path = self.db_path if not db_path else db_path\n        packages = list(\n            Package(key=req.key, version=req.specs[0][1])\n            for req in self.try_parse_requirements(file)\n            if len(req.specs) == 1 and req.specs[0][0] == '=='\n        )\n\n        if not packages:\n            return\n\n        for vulnerability in safety.check(packages, key=None,\n                                          db_mirror=db_path, cached=False,\n                                          ignore_ids=cve_ignore):\n            if 'cve' in vulnerability.vuln_id.strip().lower():\n                message_template = (\n                    '{vuln.name}{vuln.spec} is vulnerable to {vuln.vuln_id} '\n                    'and your project is using {vuln.version}.'\n                )\n            else:\n                message_template = (\n                    '{vuln.name}{vuln.spec} is vulnerable to '\n                    'pyup.io-{vuln.vuln_id} and your project is using '\n                    '{vuln.version}.'\n                )\n\n            # StopIteration should not ever happen so skipping its branch\n            line_number, line = next(  # pragma: no branch\n                (index, line) for index, line in enumerate(file, start=1)\n                if vulnerability.name in line\n            )\n            version_spec_match = re.search(r'[=<>]+(\\S+?)(?:$|\\s|#)', line)\n            source_range = SourceRange.from_values(\n                filename,\n                line_number,\n                version_spec_match.start(1) + 1,\n                line_number,\n                version_spec_match.end(1) + 1,\n            )\n\n            yield Result(\n                self,\n                message_template.format(vuln=vulnerability),\n                additional_info=vulnerability.advisory,\n                affected_code=(source_range, ),\n            )\n\n    @staticmethod\n    def try_parse_requirements(lines: typed_list(str)):\n        \"\"\"\n        Yields all package requirements parsable from the given lines.\n\n        :param lines: An iterable of lines from a requirements file.\n        \"\"\"\n        for line in lines:\n            try:\n                yield from pkg_resources.parse_requirements(line)\n            except pkg_resources.RequirementParseError:\n                # unsupported requirement specification\n                pass\n", "path": "bears/python/requirements/PySafetyBear.py"}], "after_files": [{"content": "import os\nfrom collections import namedtuple\nimport pkg_resources\nimport re\n\nfrom safety import safety\n\nfrom coalib.bears.LocalBear import LocalBear\nfrom dependency_management.requirements.PipRequirement import PipRequirement\nfrom coalib.results.Result import Result\nfrom coalib.settings.Setting import path\nfrom coalib.results.SourceRange import SourceRange\nfrom coalib.settings.Setting import typed_list\n\n\n# It was for old versions of safety and those versions will be allow in future.\ndef cve_key_checker(vulnerability):\n    if 'cve' in vulnerability.data:\n        if vulnerability.data['cve'] is None:\n            return None\n        else:\n            return True\n    else:\n        return None\n\n\n# the safety module expects an object that looks like this\n# (not importing it from there because it's in a private-ish location)\nPackage = namedtuple('Package', ('key', 'version'))\n\nsafety_get_vulnerabilities = safety.get_vulnerabilities\n_insecure_full_json_url = ('https://raw.githubusercontent.com/pyupio/'\n                           'safety-db/master/data/insecure_full.json')\n\n_insecure_json_url = ('https://raw.githubusercontent.com/'\n                      'pyupio/safety-db/master/data/insecure.json')\n\n\ndef _get_vulnerabilities(pkg, spec, db):\n    for entry in safety_get_vulnerabilities(pkg, spec, db):\n        entry['cve'] = entry['id'] if entry['cve'] is None else entry['cve']\n        entry['id'] = entry['cve']\n        yield entry\n\n\nsafety.get_vulnerabilities = _get_vulnerabilities\n\n\nclass PySafetyBear(LocalBear):\n    \"\"\"\n    Checks if any of your Python dependencies have known security issues.\n\n    Data is taken from pyup.io's vulnerability database hosted at\n    https://github.com/pyupio/safety.\n    \"\"\"\n\n    LANGUAGES = {\n        'Python Requirements',\n        'Python 2 Requirements',\n        'Python 3 Requirements',\n    }\n    AUTHORS = {'Bence Nagy'}\n    REQUIREMENTS = {PipRequirement('safety', '1.8.2')}\n    AUTHORS_EMAILS = {'bence@underyx.me'}\n    LICENSE = 'AGPL'\n    CAN_DETECT = {'Security'}\n    ASCIINEMA_URL = 'https://asciinema.org/a/221386'\n\n    def setup_dependencies(self):\n        file = self.download_cached_file(_insecure_full_json_url,\n                                         'insecure_full.json')\n        self.download_cached_file(_insecure_json_url,\n                                  'insecure.json')\n        type(self).db_path = os.path.dirname(file)\n\n    def run(self, filename, file,\n            db_path: path = '',\n            cve_ignore: typed_list(str) = []):\n        \"\"\"\n        Checks for vulnerable package versions in requirements files.\n\n        :param db_path:           Path to a local vulnerability database.\n        :param cve_ignore:        A list of CVE number to be ignore.\n        \"\"\"\n        db_path = self.db_path if not db_path else db_path\n        packages = list(\n            Package(key=req.key, version=req.specs[0][1])\n            for req in self.try_parse_requirements(file)\n            if len(req.specs) == 1 and req.specs[0][0] == '=='\n        )\n\n        if not packages:\n            return\n\n        for vulnerability in safety.check(packages, key=None,\n                                          db_mirror=db_path, cached=False,\n                                          ignore_ids=cve_ignore):\n            if 'cve' in vulnerability.vuln_id.strip().lower():\n                message_template = (\n                    '{vuln.name}{vuln.spec} is vulnerable to {vuln.vuln_id} '\n                    'and your project is using {vuln.version}.'\n                )\n            else:\n                message_template = (\n                    '{vuln.name}{vuln.spec} is vulnerable to '\n                    'pyup.io-{vuln.vuln_id} and your project is using '\n                    '{vuln.version}.'\n                )\n\n            # StopIteration should not ever happen so skipping its branch\n            line_number, line = next(  # pragma: no branch\n                (index, line) for index, line in enumerate(file, start=1)\n                if vulnerability.name in line\n            )\n            version_spec_match = re.search(r'[=<>]+(\\S+?)(?:$|\\s|#)', line)\n            source_range = SourceRange.from_values(\n                filename,\n                line_number,\n                version_spec_match.start(1) + 1,\n                line_number,\n                version_spec_match.end(1) + 1,\n            )\n\n            yield Result(\n                self,\n                message_template.format(vuln=vulnerability),\n                additional_info=vulnerability.advisory,\n                affected_code=(source_range, ),\n            )\n\n    @staticmethod\n    def try_parse_requirements(lines: typed_list(str)):\n        \"\"\"\n        Yields all package requirements parsable from the given lines.\n\n        :param lines: An iterable of lines from a requirements file.\n        \"\"\"\n        for line in lines:\n            try:\n                yield from pkg_resources.parse_requirements(line)\n            except pkg_resources.RequirementParseError:\n                # unsupported requirement specification\n                pass\n", "path": "bears/python/requirements/PySafetyBear.py"}]}