File: inputformat.py

package info (click to toggle)
w3af 1.0-rc3svn3489-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 59,908 kB
  • ctags: 16,916
  • sloc: python: 136,990; xml: 63,472; sh: 153; ruby: 94; makefile: 40; asm: 35; jsp: 32; perl: 18; php: 5
file content (41 lines) | stat: -rw-r--r-- 1,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from sys import stdin

class TextLineInput:
    """ 
    treat the input as lines of text
    
    emit None as key and text line as value
    """

    @staticmethod
    def read_line(file=stdin):
        """
        read and parse input file, for each line, yield a (None, line) pair

        @return: yield a (None, line) pair
        @param file: input file, default to stdin
        """
        for line in file:
        # split the line into words, trailing space truncated
            yield None, line.strip()

class KeyValueInput:
    """ 
    treat the input as lines of (key, value) pair splited by separator
    
    emit text before separator as key and the rest as value
    """

    @staticmethod
    def read_line(file=stdin, separator='\t'):
        """
        read and parse input file, for each line, 
        separate the line and yield a (key, value) pair

        @return: yield a (key, value) pair
        @param file: input file, default to stdin
        @param separator: specify the character to 
        separate a line of input, default to '\t'
        """
        for line in file:
            yield line.rstrip().split(separator, 1)