original_docstring: 
          Scan the specifid WFP and return the JSON object
  
          :param wfp: WFP to scan
          :param context: Context to help with idenification
          :return: JSON result object
          
docstring: Scan the specifid WFP and return the JSON object
docstring_tokens: Scan the specifid WFP and return the JSON object
code: def scan(self, wfp: str, context: str = None, scan_id: int = None):
          """
          Scan the specifid WFP and return the JSON object
  
          :param wfp: WFP to scan
          :param context: Context to help with idenification
          :return: JSON result object
          """
          form_data = {}
          if self.sbom:
              form_data['type'] = self.scan_type
              form_data['assets'] = self.sbom
          if self.scan_format:
              form_data['format'] = self.scan_format
          if self.flags:
              form_data['flags'] = self.flags
          if context:
              form_data['context'] = context
          scan_files = {'file': ("%s.wfp" % uuid.uuid1().hex, wfp)}
          r     = None
          retry = 0    # Add some retry logic to cater for timeouts, etc.
          while retry <= 5:
              retry += 1
              try:
                  r = None
                  r = requests.post(self.url, files=scan_files, data=form_data, headers=self.headers, timeout=self.timeout)
              except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as e:
                  if retry > 5:   # Timed out 5 or more times, fail
                      self.print_stderr(f'ERROR: Timeout/Connection Error POSTing data: {scan_files}')
                      raise Exception(f"ERROR: The SCANOSS API request timed out for {self.url}") from e
                  else:
                      self.print_stderr(f'Warning: Timeout/Connection Error communicating with {self.url}. Retrying...')
                      time.sleep(5)
              except Exception as e:
                  self.print_stderr(f'ERROR: Exception POSTing data: {scan_files}')
                  raise Exception(f"ERROR: The SCANOSS API request failed for {self.url}") from e
              else:
                  if not r:
                      if retry > 5:   # No response 5 or more times, fail
                          raise Exception(f"ERROR: The SCANOSS API request response object is empty for {self.url}")
                      else:
                          self.print_stderr(f'Warning: No response received from {self.url}. Retrying...')
                          time.sleep(5)
                  elif r.status_code >= 400:
                      if retry > 5:   # No response 5 or more times, fail
                          raise Exception(f"ERROR: The SCANOSS API returned the following error: HTTP {r.status_code}, {r.text}")
                      else:
                          self.print_stderr(f'Warning: Error response code {r.status_code} from {self.url}. Retrying...')
                          time.sleep(5)
                  else:
                      retry = 6
                      break     # Valid response, break out of the retry loop
          # End of while loop
          if not r:
              raise Exception(f"ERROR: The SCANOSS API request response object is empty for {self.url}")
          try:
              if 'xml' in self.scan_format:
                  return r.text
              json_resp = r.json()
              return json_resp
          except (JSONDecodeError, Exception) as e:
              self.print_stderr(f'ERROR: The SCANOSS API returned an invalid JSON: {e}')
              ctime = int(time.time())
              bad_json_file = f'bad_json-{scan_id}-{ctime}.txt' if scan_id else f'bad_json-{ctime}.txt'
              self.print_stderr(f'Ignoring result. Please look in "{bad_json_file}" for more details.')
              try:
                  with open(bad_json_file, 'w') as f:
                      f.write(f"---WFP Begin---\n{scan_files}\n---WFP End---\n---Bad JSON Begin---\n")
                      f.write(r.text)
                      f.write("---Bad JSON End---\n")
              except Exception as ee:
                  self.print_stderr(f'Warning: Issue writing bad json file - {bad_json_file}: {ee}')
              return None
code_tokens: def scan ( self , wfp : str , context : str = None , scan_id : int = None ) : form_data = { } if self . sbom : form_data [ 'type' ] = self . scan_type form_data [ 'assets' ] = self . sbom if self . scan_format : form_data [ 'format' ] = self . scan_format if self . flags : form_data [ 'flags' ] = self . flags if context : form_data [ 'context' ] = context scan_files = { 'file' : ( "%s.wfp" % uuid . uuid1 ( ) . hex , wfp ) } r = None retry = 0 while retry <= 5 : retry += 1 try : r = None r = requests . post ( self . url , files = scan_files , data = form_data , headers = self . headers , timeout = self . timeout ) except ( requests . exceptions . Timeout , requests . exceptions . ConnectionError ) as e : if retry > 5 : self . print_stderr ( f'ERROR: Timeout/Connection Error POSTing data: {scan_files}' ) raise Exception ( f"ERROR: The SCANOSS API request timed out for {self.url}" ) from e else : self . print_stderr ( f'Warning: Timeout/Connection Error communicating with {self.url}. Retrying...' ) time . sleep ( 5 ) except Exception as e : self . print_stderr ( f'ERROR: Exception POSTing data: {scan_files}' ) raise Exception ( f"ERROR: The SCANOSS API request failed for {self.url}" ) from e else : if not r : if retry > 5 : raise Exception ( f"ERROR: The SCANOSS API request response object is empty for {self.url}" ) else : self . print_stderr ( f'Warning: No response received from {self.url}. Retrying...' ) time . sleep ( 5 ) elif r . status_code >= 400 : if retry > 5 : raise Exception ( f"ERROR: The SCANOSS API returned the following error: HTTP {r.status_code}, {r.text}" ) else : self . print_stderr ( f'Warning: Error response code {r.status_code} from {self.url}. Retrying...' ) time . sleep ( 5 ) else : retry = 6 break if not r : raise Exception ( f"ERROR: The SCANOSS API request response object is empty for {self.url}" ) try : if 'xml' in self . scan_format : return r . text json_resp = r . json ( ) return json_resp except ( JSONDecodeError , Exception ) as e : self . print_stderr ( f'ERROR: The SCANOSS API returned an invalid JSON: {e}' ) ctime = int ( time . time ( ) ) bad_json_file = f'bad_json-{scan_id}-{ctime}.txt' if scan_id else f'bad_json-{ctime}.txt' self . print_stderr ( f'Ignoring result. Please look in "{bad_json_file}" for more details.' ) try : with open ( bad_json_file , 'w' ) as f : f . write ( f"---WFP Begin---\n{scan_files}\n---WFP End---\n---Bad JSON Begin---\n" ) f . write ( r . text ) f . write ( "---Bad JSON End---\n" ) except Exception as ee : self . print_stderr ( f'Warning: Issue writing bad json file - {bad_json_file}: {ee}' ) return None
short_docstring: Scan the specifid WFP and return the JSON object
short_docstring_tokens: Scan the specifid WFP and return the JSON object
comment: """
          Scan the specifid WFP and return the JSON object
  
          :param wfp: WFP to scan
          :param context: Context to help with idenification
          :return: JSON result object
          """$SEP$# Add some retry logic to cater for timeouts, etc.$SEP$# Timed out 5 or more times, fail$SEP$# No response 5 or more times, fail$SEP$# No response 5 or more times, fail$SEP$# Valid response, break out of the retry loop$SEP$# End of while loop