Example #1
0
  def initFromNDJSON(self, jsonStr):
    obj = libLF.fromNDJSON(jsonStr)
    self.regex = libLF.Regex().initFromDict(obj['regex'])

    if 'slTimeout' in obj:
      self.slTimeout = obj['slTimeout']
    else:
      self.slTimeout = self.MATCH_TIMEOUT_SEC
    if 'powerPumps' in obj:
      self.powerPumps = obj['powerPumps']
    else:
      self.powerPumps = self.POW_PUMPS

    self.detectorOpinions = [
      SLRegexDetectorOpinion().initFromDict(doDict) for doDict in obj['detectorOpinions']
    ]

    # Get the lang_validPattern dict.
    # The keys are bools, easy conversion.
    self.lang_validPattern = obj['lang_validPattern']

    # Get the lang_pump2timedOut dict.
    # The keys on pump2timedOut should be integers, but they may have been
    # converted to strings. Convert back again.
    self.lang_pump2timedOut = obj['lang_pump2timedOut']
    for lang in self.lang_pump2timedOut:
      pump2timedOut = self.lang_pump2timedOut[lang]
      for k in pump2timedOut:
        if type(k) is str:
          pump2timedOut[int(k)] = pump2timedOut[k]
          del pump2timedOut[k]
    def initFromNDJSON(self, jsonStr):
        self.initialized = True

        obj = libLF.fromNDJSON(jsonStr)
        self.fileName = obj['fileName']
        self.language = obj['language']
        self.couldParse = obj['couldParse']
        self.regexes = obj['regexes']
Example #3
0
    def initFromNDJSON(self, jsonStr):
        obj = libLF.fromNDJSON(jsonStr)
        self.pattern = obj['pattern']
        self.input = obj['input']

        self.matchResultToLangs = {}
        for mrJSON, langs in obj['matchResultToLangs'].items():
            mr = MatchResult().initFromNDJSON(mrJSON)
            self.matchResultToLangs[mr] = langs

        return self
Example #4
0
    def initFromNDJSON(self, jsonStr):
        self.initialized = True

        obj = libLF.fromNDJSON(jsonStr)
        self.pattern = obj['pattern']
        self.flags = obj['flags']
        self.inputs = obj['inputs']
        self.regexes = obj['regexes']
        self.relPath = obj['relPath']
        self.basename = obj['basename']
        return self
Example #5
0
    def initFromNDJSON(self, jsonStr):
        self.initialized = True

        obj = libLF.fromNDJSON(jsonStr)
        self.pattern = obj['pattern']
        self.flags = obj['flags']
        self.inputs = obj['inputs']
        self.regexes = obj['regexes']
        self.relPath = obj['relPath']
        self.basename = obj['basename']
        self.lineNumber = obj['lineNumber']
        if 'logHistory' in obj:
            self.logHistory = obj['logHistory']
        else:
            self.logHistory = ''
        return self
def retrieveRegexes(regexOutputFileName):
  """Returns libLF.RegexUsage[]

  (Since regexOutputFileName contains regexes from multiple source files,
  multiple files are represented in the returned libLF.RegexUsage[])

  Duplicates by <file, pattern> are removed.
  """

  libLF.log("Loading regexes from {}".format(regexOutputFileName))
  
  # Bin by file, removing duplicates
  file2uniqRegexes = {} # x[filename][pattern] = record
  with open(regexOutputFileName, mode='r') as regexStream:
    for line in regexStream:
      # Try to parse as NDJSON.
      # In Java we rely on a "poor man's JSON" implementation which may sometimes
      # produce malformed strings. In other languages, this should always work.
      try:
        obj = libLF.fromNDJSON(line)
      except:
        libLF.log("Could not fromNDJSON line: {}".format(line))
        continue

      if obj['file'] not in file2uniqRegexes:
        file2uniqRegexes[obj['file']] = {}
      file2uniqRegexes[obj['file']][obj['pattern']] = \
        {
          'pattern': obj['pattern'],
          'flags': obj['flags']
        }
  
  # Convert to libLF.RegexUsage[] via libLF.SimpleFileWithRegexes
  ruList = []
  for fileName in file2uniqRegexes:
    sfwr = libLF.SimpleFileWithRegexes().initFromRaw(
      fileName, "XXX", True, list(file2uniqRegexes[fileName].values())
    )
    ruList += libLF.sfwrToRegexUsageList(sfwr)

  return ruList
Example #7
0
 def initFromNDJSON(self, jsonStr):
     obj = libLF.fromNDJSON(jsonStr)
     return self.initFromDict(obj)
Example #8
0
 def initFromNDJSON(self, jsonStr):
     obj = libLF.fromNDJSON(jsonStr)
     self.matched = obj['matched']
     self.matchContents = MatchContents().initFromNDJSON(
         obj['matchContents'])
     return self
Example #9
0
 def initFromNDJSON(self, jsonStr):
     obj = libLF.fromNDJSON(jsonStr)
     self.matchedString = obj['matchedString']
     self.captureGroups = obj['captureGroups']
     return self
Example #10
0
 def initFromNDJSON(self, jsonStr):
     self.initialized = True
     obj = libLF.fromNDJSON(jsonStr)
     return self.initFromDict(obj)