예제 #1
0
def test_integration_with_stdout():
    "STDOUT filter integration"

    sys.stdout = sys.__stdout__
    couleur.proxy(sys.stdout).enable()
    assert sys.stdout is not sys.__stdout__
    couleur.proxy(sys.stdout).disable()
    assert sys.stdout is sys.__stdout__
예제 #2
0
def test_integration_with_stderr():
    "STDERR filter integration"

    sys.stderr = sys.__stderr__
    couleur.proxy(sys.stderr).enable()
    assert sys.stderr is not sys.__stderr__
    couleur.proxy(sys.stderr).disable()
    assert sys.stderr is sys.__stderr__
예제 #3
0
def test_integration_with_stdout():
    "STDOUT filter integration"

    sys.stdout = sys.__stdout__
    couleur.proxy(sys.stdout).enable()
    assert sys.stdout is not sys.__stdout__
    couleur.proxy(sys.stdout).disable()
    assert sys.stdout is sys.__stdout__
예제 #4
0
def test_supress_up_when_ignoring_colors():
    "file-like filter output: supress #{up} when ignoring colors"

    io = StringIO()
    couleur.proxy(io).enable()
    couleur.proxy(io).ignore()
    io.write("This is visible#{up}but this is invisible\n")
    assert_equals('This is visible', io.getvalue())
예제 #5
0
def test_supress_up_when_ignoring_colors():
    "file-like filter output: supress #{up} when ignoring colors"

    io = StringIO()
    couleur.proxy(io).enable()
    couleur.proxy(io).ignore()
    io.write("This is visible#{up}but this is invisible\n")
    assert_equals('This is visible', io.getvalue())
예제 #6
0
def test_integration_with_stderr():
    "STDERR filter integration"

    sys.stderr = sys.__stderr__
    couleur.proxy(sys.stderr).enable()
    assert sys.stderr is not sys.__stderr__
    couleur.proxy(sys.stderr).disable()
    assert sys.stderr is sys.__stderr__
예제 #7
0
def test_output_green_and_red_on_white_foreground():
    "STDERR filter output: green foreground and white on red background"

    couleur.proxy(sys.stderr).enable()
    sys.stderr.write("#{green}Hello #{white}#{on:red}Italy!\n")
    assert_stderr('\033[32mHello \033[37;41mItaly!\n')
    couleur.proxy(sys.stderr).disable()
    sys.stderr.write("#{black}should not be translated\n")
    assert_stderr('#{black}should not be translated\n')
예제 #8
0
def test_output_green_foreground():
    "STDERR filter output: green foreground"

    couleur.proxy(sys.stderr).enable()
    sys.stderr.write("#{green}Hello Green!\n")
    assert_stderr('\033[32mHello Green!\n')
    couleur.proxy(sys.stderr).disable()
    sys.stderr.write("#{black}should not be translated\n")
    assert_stderr('#{black}should not be translated\n')
예제 #9
0
def test_output_black_on_white_foreground():
    "STDERR filter output: black foreground on white background"

    couleur.proxy(sys.stderr).enable()
    sys.stderr.write("#{black}#{on:white}Hello Black!\n")
    assert_stderr('\033[30;47mHello Black!\n')
    couleur.proxy(sys.stderr).disable()
    sys.stderr.write("#{black}should not be translated\n")
    assert_stderr('#{black}should not be translated\n')
예제 #10
0
def test_output_green_foreground():
    "STDOUT filter output: green foreground"

    couleur.proxy(sys.stdout).enable()
    print "#{green}Hello Green!#{reset}"
    assert_stdout('\033[32mHello Green!\033[0m\n')
    couleur.proxy(sys.stdout).disable()
    print "#{black}should not be translated"
    assert_stdout('#{black}should not be translated\n')
예제 #11
0
def test_output_black_on_white_foreground():
    "STDOUT filter output: black foreground on white background"

    couleur.proxy(sys.stdout).enable()
    print("#{black}#{on:white}Hello Black!#{reset}")
    assert_stdout('\033[30;47mHello Black!\033[0m\n')
    couleur.proxy(sys.stdout).disable()
    print("#{black}should not be translated")
    assert_stdout('#{black}should not be translated\n')
예제 #12
0
def test_output_green_foreground():
    "STDOUT filter output: green foreground"

    couleur.proxy(sys.stdout).enable()
    print("#{green}Hello Green!#{reset}")
    assert_stdout('\033[32mHello Green!\033[0m\n')
    couleur.proxy(sys.stdout).disable()
    print("#{black}should not be translated")
    assert_stdout('#{black}should not be translated\n')
예제 #13
0
def test_output_green_and_red_on_white_foreground():
    "STDOUT filter output: green foreground and white on red background"

    couleur.proxy(sys.stdout).enable()
    print("#{green}Hello #{white}#{on:red}Italy!#{reset}")
    assert_stdout('\033[32mHello \033[37;41mItaly!\033[0m\n')
    couleur.proxy(sys.stdout).disable()
    print("#{black}should not be translated")
    assert_stdout('#{black}should not be translated\n')
예제 #14
0
def test_output_green_and_red_on_white_foreground():
    "STDERR filter output: green foreground and white on red background"

    couleur.proxy(sys.stderr).enable()
    sys.stderr.write("#{green}Hello #{white}#{on:red}Italy!\n")
    assert_stderr('\033[32mHello \033[37;41mItaly!\n')
    couleur.proxy(sys.stderr).disable()
    sys.stderr.write("#{black}should not be translated\n")
    assert_stderr('#{black}should not be translated\n')
예제 #15
0
def test_output_green_foreground():
    "STDERR filter output: green foreground"

    couleur.proxy(sys.stderr).enable()
    sys.stderr.write("#{green}Hello Green!\n")
    assert_stderr('\033[32mHello Green!\n')
    couleur.proxy(sys.stderr).disable()
    sys.stderr.write("#{black}should not be translated\n")
    assert_stderr('#{black}should not be translated\n')
예제 #16
0
def test_output_black_on_white_foreground():
    "STDOUT filter output: black foreground on white background"

    couleur.proxy(sys.stdout).enable()
    print "#{black}#{on:white}Hello Black!#{reset}"
    assert_stdout('\033[30;47mHello Black!\033[0m\n')
    couleur.proxy(sys.stdout).disable()
    print "#{black}should not be translated"
    assert_stdout('#{black}should not be translated\n')
예제 #17
0
def test_output_black_on_white_foreground():
    "STDERR filter output: black foreground on white background"

    couleur.proxy(sys.stderr).enable()
    sys.stderr.write("#{black}#{on:white}Hello Black!\n")
    assert_stderr('\033[30;47mHello Black!\n')
    couleur.proxy(sys.stderr).disable()
    sys.stderr.write("#{black}should not be translated\n")
    assert_stderr('#{black}should not be translated\n')
예제 #18
0
def test_output_green_and_red_on_white_foreground():
    "STDOUT filter output: green foreground and white on red background"

    couleur.proxy(sys.stdout).enable()
    print "#{green}Hello #{white}#{on:red}Italy!#{reset}"
    assert_stdout('\033[32mHello \033[37;41mItaly!\033[0m\n')
    couleur.proxy(sys.stdout).disable()
    print "#{black}should not be translated"
    assert_stdout('#{black}should not be translated\n')
예제 #19
0
def test_output_black_foreground():
    "STDOUT filter output: black foreground"

    couleur.proxy(sys.stdout).enable()
    print "#{black}Hello Black!#{reset}"
    assert_stdout('\033[30mHello Black!\033[0m\n')
    couleur.proxy(sys.stdout).disable()
    print "#{black}should not be translated"
    assert_stdout('#{black}should not be translated\n')
예제 #20
0
def test_output_different_delimiters():
    "using square brackets as delimiters should work"

    couleur.proxy(sys.stdout, delimiter=couleur.delimiters.SQUARE_BRACKETS).enable()
    print "[black]Hello Black![reset]"
    assert_stdout('\033[30mHello Black!\033[0m\n')
    couleur.proxy(sys.stdout).disable()
    print "[black]should not be translated"
    assert_stdout('[black]should not be translated\n')
예제 #21
0
def test_output_different_delimiters():
    "using square brackets as delimiters should work"

    couleur.proxy(sys.stdout,
                  delimiter=couleur.delimiters.SQUARE_BRACKETS).enable()
    print "[black]Hello Black![reset]"
    assert_stdout('\033[30mHello Black!\033[0m\n')
    couleur.proxy(sys.stdout).disable()
    print "[black]should not be translated"
    assert_stdout('[black]should not be translated\n')
예제 #22
0
def test_supress_up_when_ignoring_colors_as_many_times_needed():
    "file-like filter output: supress #{up} as many times as needed"

    io = StringIO()
    couleur.proxy(io).enable()
    couleur.proxy(io).ignore()
    io.write("This is visible#{up}#{up}#{up}#{up}\n" \
        " Line one supressed\n" \
        " Line two supressed\n" \
        " Line three supressed\n")
    assert_equals('This is visible', io.getvalue())
예제 #23
0
def test_supress_up_when_ignoring_colors_as_many_times_needed():
    "file-like filter output: supress #{up} as many times as needed"

    io = StringIO()
    couleur.proxy(io).enable()
    couleur.proxy(io).ignore()
    io.write("This is visible#{up}#{up}#{up}#{up}\n" \
        " Line one supressed\n" \
        " Line two supressed\n" \
        " Line three supressed\n")
    assert_equals('This is visible', io.getvalue())
예제 #24
0
def test_output_green_and_red_on_white_foreground():
    "file-like filter output: green foreground and white on red background"

    io = StringIO()
    couleur.proxy(io).enable()
    io.write("#{green}Hello #{white}#{on:red}Italy!\n")
    assert_equals('\033[32mHello \033[37;41mItaly!\n', io.getvalue())
    couleur.proxy(io).disable()
    io.seek(0)
    io.truncate()
    io.write("#{black}should not be translated\n")
    assert_equals('#{black}should not be translated\n', io.getvalue())
예제 #25
0
def test_output_green_foreground():
    "file-like filter output: green foreground"

    io = StringIO()
    couleur.proxy(io).enable()
    io.write("#{green}Hello Green!\n")
    assert_equals('\033[32mHello Green!\n', io.getvalue())
    couleur.proxy(io).disable()
    io.seek(0)
    io.truncate()
    io.write("#{black}should not be translated\n")
    assert_equals('#{black}should not be translated\n', io.getvalue())
예제 #26
0
def test_output_green_foreground():
    "file-like filter output: green foreground"

    io = StringIO()
    couleur.proxy(io).enable()
    io.write("#{green}Hello Green!\n")
    assert_equals('\033[32mHello Green!\n', io.getvalue())
    couleur.proxy(io).disable()
    io.seek(0)
    io.truncate()
    io.write("#{black}should not be translated\n")
    assert_equals('#{black}should not be translated\n', io.getvalue())
예제 #27
0
def test_output_bold_green_on_bold_white():
    "file-like filter output: bold green on white"

    io = StringIO()
    couleur.proxy(io).enable()
    io.write("#{bold}#{green}#{on:white}Hello\n")
    assert_equals('\033[1;32;47mHello\n', io.getvalue())
    couleur.proxy(io).disable()
    io.seek(0)
    io.truncate()
    io.write("#{black}should not be translated\n")
    assert_equals('#{black}should not be translated\n', io.getvalue())
예제 #28
0
def test_output_black_on_white_foreground():
    "file-like filter output: black foreground on white background"

    io = StringIO()
    couleur.proxy(io).enable()
    io.write("#{black}#{on:white}Hello Black!\n")
    assert_equals('\033[30;47mHello Black!\n', io.getvalue())
    couleur.proxy(io).disable()
    io.seek(0)
    io.truncate()
    io.write("#{black}should not be translated\n")
    assert_equals('#{black}should not be translated\n', io.getvalue())
예제 #29
0
def test_output_bold_green_on_bold_white():
    "file-like filter output: bold green on white"

    io = StringIO()
    couleur.proxy(io).enable()
    io.write("#{bold}#{green}#{on:white}Hello\n")
    assert_equals('\033[1;32;47mHello\n', io.getvalue())
    couleur.proxy(io).disable()
    io.seek(0)
    io.truncate()
    io.write("#{black}should not be translated\n")
    assert_equals('#{black}should not be translated\n', io.getvalue())
예제 #30
0
def test_output_green_and_red_on_white_foreground():
    "file-like filter output: green foreground and white on red background"

    io = StringIO()
    couleur.proxy(io).enable()
    io.write("#{green}Hello #{white}#{on:red}Italy!\n")
    assert_equals('\033[32mHello \033[37;41mItaly!\n', io.getvalue())
    couleur.proxy(io).disable()
    io.seek(0)
    io.truncate()
    io.write("#{black}should not be translated\n")
    assert_equals('#{black}should not be translated\n', io.getvalue())
예제 #31
0
def test_output_black_on_white_foreground():
    "file-like filter output: black foreground on white background"

    io = StringIO()
    couleur.proxy(io).enable()
    io.write("#{black}#{on:white}Hello Black!\n")
    assert_equals('\033[30;47mHello Black!\n', io.getvalue())
    couleur.proxy(io).disable()
    io.seek(0)
    io.truncate()
    io.write("#{black}should not be translated\n")
    assert_equals('#{black}should not be translated\n', io.getvalue())
예제 #32
0
def test_output_stdout_ignoring_output_square_brackets():
    "STDOUT filter output: ignoring output"

    couleur.proxy(sys.stdout, delimiter=couleur.delimiters.SQUARE_BRACKETS).enable()
    couleur.proxy(sys.stdout, delimiter=couleur.delimiters.SQUARE_BRACKETS).ignore()
    sys.stdout.write("[green]Hello [white][on:blue]World![reset]\n")
    assert_stdout('Hello World!\n')
    couleur.proxy(sys.stdout, delimiter=couleur.delimiters.SQUARE_BRACKETS).enable()
    sys.stdout.write("[green]Hi There!\n")
    assert_stdout('\033[32mHi There!\n')
    couleur.proxy(sys.stdout, delimiter=couleur.delimiters.SQUARE_BRACKETS).disable()
    sys.stdout.write("[black]should not be translated\n")
    assert_stdout('[black]should not be translated\n')
예제 #33
0
def test_output_stderr_ignoring_output():
    "STDERR filter output: ignoring output"

    couleur.proxy(sys.stderr).enable()
    couleur.proxy(sys.stderr).ignore()
    sys.stderr.write("#{green}Hello #{white}#{on:blue}World!#{reset}\n")
    assert_stderr('Hello World!\n')
    couleur.proxy(sys.stderr).enable()
    sys.stderr.write("#{green}Hi There!\n")
    assert_stderr('\033[32mHi There!\n')
    couleur.proxy(sys.stderr).disable()
    sys.stderr.write("#{black}should not be translated\n")
    assert_stderr('#{black}should not be translated\n')
예제 #34
0
def test_output_stdout_ignoring_output():
    "STDOUT filter output: green foreground and white on red background"

    couleur.proxy(sys.stdout).enable()
    couleur.proxy(sys.stdout).ignore()
    print("#{green}Hello #{white}#{on:blue}World!#{reset}")
    assert_stdout('Hello World!\n')
    couleur.proxy(sys.stdout).enable()
    print("#{green}Hi There!")
    assert_stdout('\033[32mHi There!\n')
    couleur.proxy(sys.stdout).disable()
    print("#{black}should not be translated")
    assert_stdout('#{black}should not be translated\n')
예제 #35
0
def test_output_stdout_ignoring_output():
    "STDOUT filter output: green foreground and white on red background"

    couleur.proxy(sys.stdout).enable()
    couleur.proxy(sys.stdout).ignore()
    print "#{green}Hello #{white}#{on:blue}World!#{reset}"
    assert_stdout('Hello World!\n')
    couleur.proxy(sys.stdout).enable()
    print "#{green}Hi There!"
    assert_stdout('\033[32mHi There!\n')
    couleur.proxy(sys.stdout).disable()
    print "#{black}should not be translated"
    assert_stdout('#{black}should not be translated\n')
예제 #36
0
def test_errput_stderr_ignoring_errput():
    "STDERR filter errput: ignoring output"

    couleur.proxy(sys.stderr).enable()
    couleur.proxy(sys.stderr).ignore()
    sys.stderr.write("#{green}Hello #{white}#{on:blue}World!#{reset}\n")
    assert_stderr('Hello World!\n')
    couleur.proxy(sys.stderr).enable()
    sys.stderr.write("#{green}Hi There!\n")
    assert_stderr('\033[32mHi There!\n')
    couleur.proxy(sys.stderr).disable()
    sys.stderr.write("#{black}should not be translated\n")
    assert_stderr('#{black}should not be translated\n')
예제 #37
0
def test_output_stdout_ignoring_output_square_brackets():
    "STDOUT filter output: ignoring output"

    couleur.proxy(sys.stdout,
                  delimiter=couleur.delimiters.SQUARE_BRACKETS).enable()
    couleur.proxy(sys.stdout,
                  delimiter=couleur.delimiters.SQUARE_BRACKETS).ignore()
    sys.stdout.write("[green]Hello [white][on:blue]World![reset]\n")
    assert_stdout('Hello World!\n')
    couleur.proxy(sys.stdout,
                  delimiter=couleur.delimiters.SQUARE_BRACKETS).enable()
    sys.stdout.write("[green]Hi There!\n")
    assert_stdout('\033[32mHi There!\n')
    couleur.proxy(sys.stdout,
                  delimiter=couleur.delimiters.SQUARE_BRACKETS).disable()
    sys.stdout.write("[black]should not be translated\n")
    assert_stdout('[black]should not be translated\n')
예제 #38
0
def test_ignoring_colors():
    "file-like filter output: ignoring output"

    io = StringIO()
    couleur.proxy(io).enable()
    couleur.proxy(io).ignore()
    io.write("#{bold}#{green}#{on:white}Hello\n")
    assert_equals('Hello\n', io.getvalue())
    couleur.proxy(io).disable()
    io.seek(0)
    io.truncate()
    io.write("#{black}should not be translated\n")
    assert_equals('#{black}should not be translated\n', io.getvalue())
예제 #39
0
def test_ignoring_colors():
    "file-like filter output: ignoring output"

    io = StringIO()
    couleur.proxy(io).enable()
    couleur.proxy(io).ignore()
    io.write("#{bold}#{green}#{on:white}Hello\n")
    assert_equals('Hello\n', io.getvalue())
    couleur.proxy(io).disable()
    io.seek(0)
    io.truncate()
    io.write("#{black}should not be translated\n")
    assert_equals('#{black}should not be translated\n', io.getvalue())
예제 #40
0
    res[1].extend(rest[1])
    return res


def hexdump_diff(p1, p2):
    res = hexdump_diff_helper(p1, p2)
    #for x in range(0, len(res[0]), 16):
    #    out += res0[x:x+16] + "   |   " + res1[x:x+16] + "\n"
    #return out
    return '<div class="packet left">' + ' '.join(res[0]) + '</div>' + \
           '<div class="packet right">' + ' '.join(res[1]) + '</div><div class="clearfix"></div><br/>'


def pcap_packets(fylname):
    f = open(fylname)
    pcap = dpkt.pcap.Reader(f)
    for ts, buf in pcap:
        eth = dpkt.ethernet.Ethernet(buf)
        ip = eth.data
        yield ip


if __name__ == '__main__':
    print '<html><head><link rel="stylesheet" href="style.css" type="text/css" /></head><body>'
    packets1 = pcap_packets(sys.argv[1])
    packets2 = pcap_packets(sys.argv[2])
    couleur.proxy(sys.stdout).enable()
    for packet1, packet2 in itertools.izip(packets1, packets2):
        print hexdump_diff(packet1, packet2)
    print '</body></html>'
# -*- coding: utf-8 -*-# <Couleur - fancy shell output for python># Copyright (C) <2010>  Gabriel Falco <*****@*****.**>## This program is free software: you can redistribute it and/or modify# it under the terms of the GNU Lesser General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU General Public License for more details.## You should have received a copy of the GNU Lesser General Public License# along with this program.  If not, see <http://www.gnu.org/licenses/>.import sysfrom StringIO import StringIOfrom nose.tools import with_setup, assert_equals
import couleur

def prepare_stderr(): if isinstance(sys.stderr, StringIO): del sys.stderr
    std = StringIO()    sys.stderr = std

def assert_stderr(expected):    string = sys.stderr.getvalue()    sys.stderr.seek(0)    sys.stderr.truncate()    assert_equals(string, expected)

@with_setup(prepare_stderr)def test_output_black_foreground(): "STDERR filter output: black foreground"
    couleur.proxy(sys.stderr).enable()    sys.stderr.write("#{black}Hello Black!\n")    assert_stderr('\033[30mHello Black!\n')    couleur.proxy(sys.stderr).disable()    sys.stderr.write("#{black}should not be translated\n")    assert_stderr('#{black}should not be translated\n')

@with_setup(prepare_stderr)def test_output_black_on_white_foreground(): "STDERR filter output: black foreground on white background"
    couleur.proxy(sys.stderr).enable()    sys.stderr.write("#{black}#{on:white}Hello Black!\n")    assert_stderr('\033[30;47mHello Black!\n')    couleur.proxy(sys.stderr).disable()    sys.stderr.write("#{black}should not be translated\n")    assert_stderr('#{black}should not be translated\n')

@with_setup(prepare_stderr)def test_output_green_foreground(): "STDERR filter output: green foreground"
    couleur.proxy(sys.stderr).enable()    sys.stderr.write("#{green}Hello Green!\n")    assert_stderr('\033[32mHello Green!\n')    couleur.proxy(sys.stderr).disable()    sys.stderr.write("#{black}should not be translated\n")    assert_stderr('#{black}should not be translated\n')

@with_setup(prepare_stderr)def test_output_green_and_red_on_white_foreground(): "STDERR filter output: green foreground and white on red background"
    couleur.proxy(sys.stderr).enable()    sys.stderr.write("#{green}Hello #{white}#{on:red}Italy!\n")    assert_stderr('\033[32mHello \033[37;41mItaly!\n')    couleur.proxy(sys.stderr).disable()    sys.stderr.write("#{black}should not be translated\n")    assert_stderr('#{black}should not be translated\n')

@with_setup(prepare_stderr)def test_output_stderr_ignoring_output(): "STDERR filter output: ignoring output"
    couleur.proxy(sys.stderr).enable()    couleur.proxy(sys.stderr).ignore()    sys.stderr.write("#{green}Hello #{white}#{on:blue}World!#{reset}\n")    assert_stderr('Hello World!\n')    couleur.proxy(sys.stderr).enable()    sys.stderr.write("#{green}Hi There!\n")    assert_stderr('\033[32mHi There!\n')    couleur.proxy(sys.stderr).disable()    sys.stderr.write("#{black}should not be translated\n")    assert_stderr('#{black}should not be translated\n')

def test_integration_with_stderr(): "STDERR filter integration"
    sys.stderr = sys.__stderr__    couleur.proxy(sys.stderr).enable() assert sys.stderr is not sys.__stderr__    couleur.proxy(sys.stderr).disable() assert sys.stderr is sys.__stderr__

@with_setup(prepare_stderr)def test_output_stderr_ignoring_output_square_brackets(): "STDERR filter output: ignoring output"
    couleur.proxy(sys.stderr, delimiter=couleur.delimiters.SQUARE_BRACKETS).enable()    couleur.proxy(sys.stderr, delimiter=couleur.delimiters.SQUARE_BRACKETS).ignore()    sys.stderr.write("[green]Hello [white][on:blue]World![reset]\n")    assert_stderr('Hello World!\n')    couleur.proxy(sys.stderr, delimiter=couleur.delimiters.SQUARE_BRACKETS).enable()    sys.stderr.write("[green]Hi There!\n")    assert_stderr('\033[32mHi There!\n')    couleur.proxy(sys.stderr, delimiter=couleur.delimiters.SQUARE_BRACKETS).disable()    sys.stderr.write("[black]should not be translated\n")    assert_stderr('[black]should not be translated\n')
# -*- coding: utf-8 -*-# <Couleur - fancy shell output for python># Copyright (C) <2010>  Gabriel Falco <*****@*****.**>## This program is free software: you can redistribute it and/or modify# it under the terms of the GNU Lesser General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU General Public License for more details.## You should have received a copy of the GNU Lesser General Public License# along with this program.  If not, see <http://www.gnu.org/licenses/>.from StringIO import StringIOfrom nose.tools import assert_equals
import couleur
def test_output_black_foreground(): "file-like filter output: black foreground"
    io = StringIO()    couleur.proxy(io).enable()    io.write("#{black}Hello Black!\n")    assert_equals('\033[30mHello Black!\n', io.getvalue())    couleur.proxy(io).disable()    io.seek(0)    io.truncate()    io.write("#{black}should not be translated\n")    assert_equals('#{black}should not be translated\n', io.getvalue())
def test_output_black_on_white_foreground(): "file-like filter output: black foreground on white background"
    io = StringIO()    couleur.proxy(io).enable()    io.write("#{black}#{on:white}Hello Black!\n")    assert_equals('\033[30;47mHello Black!\n', io.getvalue())    couleur.proxy(io).disable()    io.seek(0)    io.truncate()    io.write("#{black}should not be translated\n")    assert_equals('#{black}should not be translated\n', io.getvalue())
def test_output_green_foreground(): "file-like filter output: green foreground"
    io = StringIO()    couleur.proxy(io).enable()    io.write("#{green}Hello Green!\n")    assert_equals('\033[32mHello Green!\n', io.getvalue())    couleur.proxy(io).disable()    io.seek(0)    io.truncate()    io.write("#{black}should not be translated\n")    assert_equals('#{black}should not be translated\n', io.getvalue())
def test_output_green_and_red_on_white_foreground(): "file-like filter output: green foreground and white on red background"
    io = StringIO()    couleur.proxy(io).enable()    io.write("#{green}Hello #{white}#{on:red}Italy!\n")    assert_equals('\033[32mHello \033[37;41mItaly!\n', io.getvalue())    couleur.proxy(io).disable()    io.seek(0)    io.truncate()    io.write("#{black}should not be translated\n")    assert_equals('#{black}should not be translated\n', io.getvalue())
def test_output_bold_green_on_bold_white(): "file-like filter output: bold green on white"
    io = StringIO()    couleur.proxy(io).enable()    io.write("#{bold}#{green}#{on:white}Hello\n")    assert_equals('\033[1;32;47mHello\n', io.getvalue())    couleur.proxy(io).disable()    io.seek(0)    io.truncate()    io.write("#{black}should not be translated\n")    assert_equals('#{black}should not be translated\n', io.getvalue())
def test_minify():    assert_equals("\033[1;32;41mHello\n", couleur.minify("\033[1m\033[32m\033[41mHello\n"))    assert_equals("\033[1;32;41mHello\n", couleur.minify("\033[1;32;41mHello\n"))
def test_ignoring_colors(): "file-like filter output: ignoring output"
    io = StringIO()    couleur.proxy(io).enable()    couleur.proxy(io).ignore()    io.write("#{bold}#{green}#{on:white}Hello\n")    assert_equals('Hello\n', io.getvalue())    couleur.proxy(io).disable()    io.seek(0)    io.truncate()    io.write("#{black}should not be translated\n")    assert_equals('#{black}should not be translated\n', io.getvalue())

def test_supress_up_when_ignoring_colors(): "file-like filter output: supress #{up} when ignoring colors"
    io = StringIO()    couleur.proxy(io).enable()    couleur.proxy(io).ignore()    io.write("This is visible#{up}but this is invisible\n")    assert_equals('This is visible', io.getvalue())
def test_supress_up_when_ignoring_colors_as_many_times_needed(): "file-like filter output: supress #{up} as many times as needed"
    io = StringIO()    couleur.proxy(io).enable()    couleur.proxy(io).ignore()    io.write("This is visible#{up}#{up}#{up}#{up}\n" \ " Line one supressed\n" \ " Line two supressed\n" \ " Line three supressed\n")    assert_equals('This is visible', io.getvalue())
예제 #43
0
파일: hexdump_diff.py 프로젝트: ewust/telex
        offset += size
    rest = hexdump_diff_helper(p1.data, p2.data)
    res[0].extend(rest[0])
    res[1].extend(rest[1])
    return res

def hexdump_diff(p1, p2):
    res = hexdump_diff_helper(p1, p2)
    #for x in range(0, len(res[0]), 16):
    #    out += res0[x:x+16] + "   |   " + res1[x:x+16] + "\n"
    #return out
    return '<div class="packet left">' + ' '.join(res[0]) + '</div>' + \
           '<div class="packet right">' + ' '.join(res[1]) + '</div><div class="clearfix"></div><br/>'

def pcap_packets(fylname):
    f = open(fylname)
    pcap = dpkt.pcap.Reader(f)
    for ts,buf in pcap:
        eth = dpkt.ethernet.Ethernet(buf)
        ip = eth.data
        yield ip

if __name__ == '__main__':
  print '<html><head><link rel="stylesheet" href="style.css" type="text/css" /></head><body>'
  packets1 = pcap_packets(sys.argv[1])
  packets2 = pcap_packets(sys.argv[2])
  couleur.proxy(sys.stdout).enable()
  for packet1, packet2 in itertools.izip(packets1, packets2):
    print hexdump_diff(packet1, packet2)
  print '</body></html>'