aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/script.py
blob: 897ebb725e5073dbd51ee48cf944a11d5f2a75e4 (plain)
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
"""
    The mitmproxy scripting interface is simple - a serialized representation
    of a flow is passed to the script on stdin, and a possibly modified flow is
    then read by mitmproxy from the scripts stdout. This module provides two
    convenience functions to make loading and returning data from scripts
    simple.
"""
import sys, base64
import flow


#begin nocover
def load_flow():
    """
        Load a flow from the stdin. Returns a Flow object.
    """
    data = sys.stdin.read()
    return flow.Flow.script_deserialize(data)


def return_flow(f):
    """
        Print a flow to stdout. 
    """
    print >> sys.stdout, f.script_serialize()