From 45f4768a5cc4e820d1b5d7d221e2974f6ddf390d Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 19 Aug 2011 21:38:05 +1200 Subject: [PATCH] Add attribution and license for tnetstring.py --- libmproxy/flow.py | 8 ++--- libmproxy/{netstring.py => tnetstring.py} | 37 +++++++++++++---------- test/.pry | 1 + 3 files changed, 26 insertions(+), 20 deletions(-) rename libmproxy/{netstring.py => tnetstring.py} (91%) diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 8ec1a6a30..c0130ec3d 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -2,9 +2,9 @@ This module provides more sophisticated flow tracking. These match requests with their responses, and provide filtering and interception facilities. """ -import json, hashlib, Cookie, cookielib, base64, copy, re +import hashlib, Cookie, cookielib, copy, re import time -import netstring, filt, script, utils, encoding, proxy +import tnetstring, filt, script, utils, encoding, proxy from email.utils import parsedate_tz, formatdate, mktime_tz import controller, version @@ -1319,7 +1319,7 @@ class FlowWriter: def add(self, flow): d = flow._get_state() - netstring.dump(d, self.fo) + tnetstring.dump(d, self.fo) class FlowReadError(Exception): @@ -1339,7 +1339,7 @@ class FlowReader: off = 0 try: while 1: - data = netstring.load(self.fo) + data = tnetstring.load(self.fo) off = self.fo.tell() yield Flow._from_state(data) except ValueError, v: diff --git a/libmproxy/netstring.py b/libmproxy/tnetstring.py similarity index 91% rename from libmproxy/netstring.py rename to libmproxy/tnetstring.py index 03e38c6a9..76b15a028 100644 --- a/libmproxy/netstring.py +++ b/libmproxy/tnetstring.py @@ -1,5 +1,25 @@ +# imported from the tnetstring project: https://github.com/rfk/tnetstring +# +# Copyright (c) 2011 Ryan Kelly +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. """ - tnetstring: data serialization using typed netstrings ====================================================== @@ -376,18 +396,3 @@ def pop(string,encoding=None): d[key] = val return (d,remain) raise ValueError("unknown type tag") - - - -# Use the c-extension version if available -try: - import _tnetstring -except ImportError: - pass -else: - dumps = _tnetstring.dumps - load = _tnetstring.load - loads = _tnetstring.loads - pop = _tnetstring.pop - - diff --git a/test/.pry b/test/.pry index 63b746339..f6f18e7ba 100644 --- a/test/.pry +++ b/test/.pry @@ -2,4 +2,5 @@ base = .. coverage = ../libmproxy exclude = . ../libmproxy/contrib + ../libmproxy/tnetstring.py