Returns newline delimited items contained inside file >>> "SELECT" in getFileItems(paths.SQL_KEYWORDS) True
(filename, commentPrefix='#', unicoded=True, lowercase=False, unique=False)
| 2554 | kb.commonOutputs[key].add(line) |
| 2555 | |
| 2556 | def getFileItems(filename, commentPrefix='#', unicoded=True, lowercase=False, unique=False): |
| 2557 | """ |
| 2558 | Returns newline delimited items contained inside file |
| 2559 | |
| 2560 | >>> "SELECT" in getFileItems(paths.SQL_KEYWORDS) |
| 2561 | True |
| 2562 | """ |
| 2563 | |
| 2564 | retVal = list() if not unique else OrderedDict() |
| 2565 | |
| 2566 | if filename: |
| 2567 | filename = filename.strip('"\'') |
| 2568 | |
| 2569 | checkFile(filename) |
| 2570 | |
| 2571 | try: |
| 2572 | with openFile(filename, 'r', errors="ignore") if unicoded else open(filename, 'r') as f: |
| 2573 | for line in f: |
| 2574 | if commentPrefix: |
| 2575 | if line.find(commentPrefix) != -1: |
| 2576 | line = line[:line.find(commentPrefix)] |
| 2577 | |
| 2578 | line = line.strip() |
| 2579 | |
| 2580 | if line: |
| 2581 | if lowercase: |
| 2582 | line = line.lower() |
| 2583 | |
| 2584 | if unique and line in retVal: |
| 2585 | continue |
| 2586 | |
| 2587 | if unique: |
| 2588 | retVal[line] = True |
| 2589 | else: |
| 2590 | retVal.append(line) |
| 2591 | except (IOError, OSError, MemoryError) as ex: |
| 2592 | errMsg = "something went wrong while trying " |
| 2593 | errMsg += "to read the content of file '%s' ('%s')" % (filename, getSafeExString(ex)) |
| 2594 | raise SqlmapSystemException(errMsg) |
| 2595 | |
| 2596 | return retVal if not unique else list(retVal.keys()) |
| 2597 | |
| 2598 | def goGoodSamaritan(prevValue, originalCharset): |
| 2599 | """ |
no test coverage detected
searching dependent graphs…