Example #1
0
def main():
    w = 0
    txt = stdin.detach().readlines()
    for line in txt:
        for word in line.decode('windows-1252').strip().split():
            for c in word:
                if (c.isalpha() or c.isdigit()):
                    w += 1
                    break
    print(w)
Example #2
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    if '--overlay' in args:
        args.remove('--overlay')
        overlay = True
    else:
        overlay = False

    if len(args) < 1 or args[0] == '-':
        if overlay:
            print("Can't decompress overlays from stdin", file=stderr)
            return 2

        if hasattr(stdin, 'detach'):
            f = stdin.detach()
        else:
            f = stdin
    else:
        try:
            f = open(args[0], "rb")
        except IOError as e:
            print(e, file=stderr)
            return 2

    stdout = sys.stdout
    if hasattr(stdout, 'detach'):
        # grab the underlying binary stream
        stdout = stdout.detach()

    try:
        if overlay:
            decompress_overlay(f, stdout)
        else:
            stdout.write(decompress_file(f))
    except IOError as e:
        if e.errno == EPIPE:
            # don't complain about a broken pipe
            pass
        else:
            raise
    except (DecompressionError,) as e:
        print(e, file=stderr)
        return 1

    return 0
Example #3
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    if '--overlay' in args:
        args.remove('--overlay')
        overlay = True
    else:
        overlay = False

    if len(args) < 1 or args[0] == '-':
        if overlay:
            print("Can't decompress overlays from stdin", file=stderr)
            return 2

        if hasattr(stdin, 'detach'):
            f = stdin.detach()
        else:
            f = stdin
    else:
        try:
            f = open(args[0], "rb")
        except IOError as e:
            print(e, file=stderr)
            return 2

    stdout = sys.stdout
    if hasattr(stdout, 'detach'):
        # grab the underlying binary stream
        stdout = stdout.detach()

    try:
        if overlay:
            decompress_overlay(f, stdout)
        else:
            stdout.write(decompress_file(f))
    except IOError as e:
        if e.errno == EPIPE:
            # don't complain about a broken pipe
            pass
        else:
            raise
    except (DecompressionError, ) as e:
        print(e, file=stderr)
        return 1

    return 0
Example #4
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    if '--overlay' in args:
        args.remove('--overlay')
        overlay = True
    else:
        overlay = False

    if len(args) < 1 or args[0] == '-':
        if overlay:
            print("Can't verify overlays from stdin", file=stderr)
            return 2

        if hasattr(stdin, 'detach'):
            f = stdin.detach()
        else:
            f = stdin
    else:
        try:
            f = open(args[0], "rb")
        except IOError as e:
            print(e, file=stderr)
            return 2

    try:
        if overlay:
            print("Can't verify overlays", file=stderr)
        else:
            #verify_file(f)
            dump_file(f)
    except (VerificationError,) as e:
        print(e, file=stderr)
        return 1

    return 0
Example #5
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    if "--overlay" in args:
        args.remove("--overlay")
        overlay = True
    else:
        overlay = False

    if len(args) < 1 or args[0] == "-":
        if overlay:
            print("Can't verify overlays from stdin", file=stderr)
            return 2

        if hasattr(stdin, "detach"):
            f = stdin.detach()
        else:
            f = stdin
    else:
        try:
            f = open(args[0], "rb")
        except IOError as e:
            print(e, file=stderr)
            return 2

    try:
        if overlay:
            print("Can't verify overlays", file=stderr)
        else:
            # verify_file(f)
            dump_file(f)
    except (VerificationError,) as e:
        print(e, file=stderr)
        return 1

    return 0
Example #6
0
    print_proportion("SACK", tcp_sack_s)
    print()
    
    all_sources = ip4_sources(df)
    ws_sources = ip4_sources_characteristic(df, qof.QOF_WS)
    print("WS   observed from %8u sources (%8.5f%%)" % 
          (len(ws_sources), len(ws_sources) * 100 / len(all_sources)))
    ts_sources = ip4_sources_characteristic(df, qof.QOF_TS)
    print("TS   observed from %8u sources (%8.5f%%)" % 
          (len(ts_sources), len(ts_sources) * 100 / len(all_sources)))
    sack_sources = ip4_sources_characteristic(df, qof.QOF_SACK)
    print("SACK observed from %8u sources (%8.5f%%)" % 
          (len(sack_sources), len(sack_sources) * 100 / len(all_sources)))

    nego_sources = ip4_sources_given(df, ecn_nego_s, ecn_nego_s)
    print("ECN nego involved %8u sources (%8.5f%%)" % 
          (len(nego_sources), len(nego_sources) * 100 / len(all_sources)))

parse_args()
init_ipfix(args.spec)

if args.file:
    if args.bzip2:
        with bz2.open (args.file, mode="rb") as f:
            opts_report_stream(f)
    else:
        with open (args.file, mode="rb") as f:
            opts_report_stream(f)
else:
    stdin = stdin.detach()
    opts_report_stream(stdin)
Example #7
0
    if timeslice:
        lossy_flows = np.where(df["lossy"], 1, 0)
        lossy_flows.index = df["flowEndMilliseconds"]
        total_flows = pd.Series(1, index=lossy_flows.index)
        lossy_flows = lossy_flows.resample(str(timeslice) + "S", how='sum')
        total_flows = total_flows.resample(str(timeslice) + "S", how='sum')
        lossy_flow_rate = lossy_flows / total_flows
        dfout = pd.DataFrame({
            'total': total_flows,
            'lossy': lossy_flows,
            'rate': lossy_flow_rate
        })
        dfout.to_csv(stdout)


## begin main ##

parse_args()
init_ipfix(args.spec)

if args.file:
    if args.bzip2:
        with bz2.open(args.file, mode="rb") as f:
            obsloss_report_stream_biflow(f, args.bin)
    else:
        with open(args.file, mode="rb") as f:
            obsloss_report_stream_biflow(f, args.bin)
else:
    stdin = stdin.detach()
    obsloss_report_stream_biflow(stdin, args.bin)
Example #8
0
#!/usr/bin/env python3
from collections import defaultdict
from sys import stdin
import codecs

stdin = codecs.getreader('utf8')(stdin.detach(), errors='ignore')


def word_count():
    counter = defaultdict(int)
    for l in stdin:
        for word in bytes(l, 'utf8').split():
            counter[word] += 1
    for word, cnt in sorted(counter.items(), key=lambda x: (-x[1], x[0])):
        print('{0}\t{1}'.format(word.decode('utf8'), cnt))

if __name__ == '__main__':
    word_count()
Example #9
0
#!/usr/bin/env python3
from collections import defaultdict
from sys import stdin
import codecs

stdin = codecs.getreader('utf8')(stdin.detach(), errors='ignore')


def word_count():
    counter = defaultdict(int)
    for l in stdin:
        for word in bytes(l, 'utf8').split():
            counter[word] += 1
    for word, cnt in sorted(counter.items(), key=lambda x: (-x[1], x[0])):
        print('{0}\t{1}'.format(word.decode('utf8'), cnt))


if __name__ == '__main__':
    word_count()