
import hashlib


class CallJob(object):
    """
    Base class for jobs that call SUTs and can find new issues.
    """

    def __init__(self, config, db, listener):
        self.config = config
        self.db = db
        self.listener = listener
        # expects self.sut_section and self.fuzzer_name to be set by descendants

    def add_issue(self, issue, new_issues):
        test = issue['test']

        # Save issue details.
        issue.update(dict(sut=self.sut_section,
                          fuzzer=self.fuzzer_name,
                          test=test,
                          reduced=False,
                          reported=False))

        # Generate default hash ID for the test if does not exist.
        if 'id' not in issue or not issue['id']:
            hasher = hashlib.md5()
            hasher.update(test)
            issue['id'] = hasher.hexdigest()

        # Save new issues.
        if self.db.add_issue(issue):
            new_issues.append(issue)
            self.listener.new_issue(issue=issue)


import hashlib


class CallJob(object):
    """
    Base class for jobs that call SUTs and can find new issues.
    """

    def __init__(self, config, db, listener):
        self.config = config
        self.db = db
        self.listener = listener
        # expects self.sut_section and self.fuzzer_name to be set by descendants

    def add_issue(self, issue, new_issues):
        test = issue['test']

        # Save issue details.
        issue.update(dict(sut=self.sut_section,
                          fuzzer=self.fuzzer_name,
                          test=test,
                          reduced=False,
                          reported=False))

        # Generate default hash ID for the test if does not exist.
        if 'id' not in issue or not issue['id']:
            hasher = hashlib.md5()
            hasher.update(test if isinstance(test, bytes) else str(test).encode('utf-8'))
            issue['id'] = hasher.hexdigest()

        # Save new issues.
        if self.db.add_issue(issue):
            new_issues.append(issue)
            self.listener.new_issue(issue=issue)

Prepare test hashing for complex types.
Prepare test hashing for complex types.

  
  import hashlib
  
  
  class CallJob(object):
      """
      Base class for jobs that call SUTs and can find new issues.
      """
  
      def __init__(self, config, db, listener):
          self.config = config
          self.db = db
          self.listener = listener
          # expects self.sut_section and self.fuzzer_name to be set by descendants
  
      def add_issue(self, issue, new_issues):
          test = issue['test']
  
          # Save issue details.
          issue.update(dict(sut=self.sut_section,
                            fuzzer=self.fuzzer_name,
                            test=test,
                            reduced=False,
                            reported=False))
  
          # Generate default hash ID for the test if does not exist.
          if 'id' not in issue or not issue['id']:
              hasher = hashlib.md5()
-             hasher.update(test)
+             hasher.update(test if isinstance(test, bytes) else str(test).encode('utf-8'))
              issue['id'] = hasher.hexdigest()
  
          # Save new issues.
          if self.db.add_issue(issue):
              new_issues.append(issue)
              self.listener.new_issue(issue=issue)
  
Prepare test hashing for complex types.
## Code Before:

import hashlib


class CallJob(object):
    """
    Base class for jobs that call SUTs and can find new issues.
    """

    def __init__(self, config, db, listener):
        self.config = config
        self.db = db
        self.listener = listener
        # expects self.sut_section and self.fuzzer_name to be set by descendants

    def add_issue(self, issue, new_issues):
        test = issue['test']

        # Save issue details.
        issue.update(dict(sut=self.sut_section,
                          fuzzer=self.fuzzer_name,
                          test=test,
                          reduced=False,
                          reported=False))

        # Generate default hash ID for the test if does not exist.
        if 'id' not in issue or not issue['id']:
            hasher = hashlib.md5()
            hasher.update(test)
            issue['id'] = hasher.hexdigest()

        # Save new issues.
        if self.db.add_issue(issue):
            new_issues.append(issue)
            self.listener.new_issue(issue=issue)

## Instruction:
Prepare test hashing for complex types.
## Code After:

import hashlib


class CallJob(object):
    """
    Base class for jobs that call SUTs and can find new issues.
    """

    def __init__(self, config, db, listener):
        self.config = config
        self.db = db
        self.listener = listener
        # expects self.sut_section and self.fuzzer_name to be set by descendants

    def add_issue(self, issue, new_issues):
        test = issue['test']

        # Save issue details.
        issue.update(dict(sut=self.sut_section,
                          fuzzer=self.fuzzer_name,
                          test=test,
                          reduced=False,
                          reported=False))

        # Generate default hash ID for the test if does not exist.
        if 'id' not in issue or not issue['id']:
            hasher = hashlib.md5()
            hasher.update(test if isinstance(test, bytes) else str(test).encode('utf-8'))
            issue['id'] = hasher.hexdigest()

        # Save new issues.
        if self.db.add_issue(issue):
            new_issues.append(issue)
            self.listener.new_issue(issue=issue)
