mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-07 10:40:09 +00:00
Make 'none' synonymous to 'identity'
This commit is contained in:
parent
85e1539d0a
commit
5728a1c900
@ -34,7 +34,7 @@ def decode(encoded, encoding, errors='strict'):
|
|||||||
Raises:
|
Raises:
|
||||||
ValueError, if decoding fails.
|
ValueError, if decoding fails.
|
||||||
"""
|
"""
|
||||||
if len(encoded) == 0 or encoding == "none":
|
if len(encoded) == 0:
|
||||||
return encoded
|
return encoded
|
||||||
|
|
||||||
global _cache
|
global _cache
|
||||||
@ -76,7 +76,7 @@ def encode(decoded, encoding, errors='strict'):
|
|||||||
Raises:
|
Raises:
|
||||||
ValueError, if encoding fails.
|
ValueError, if encoding fails.
|
||||||
"""
|
"""
|
||||||
if len(decoded) == 0 or encoding == "none":
|
if len(decoded) == 0:
|
||||||
return decoded
|
return decoded
|
||||||
|
|
||||||
global _cache
|
global _cache
|
||||||
@ -162,12 +162,14 @@ def encode_deflate(content):
|
|||||||
|
|
||||||
|
|
||||||
custom_decode = {
|
custom_decode = {
|
||||||
|
"none": identity,
|
||||||
"identity": identity,
|
"identity": identity,
|
||||||
"gzip": decode_gzip,
|
"gzip": decode_gzip,
|
||||||
"deflate": decode_deflate,
|
"deflate": decode_deflate,
|
||||||
"br": decode_brotli,
|
"br": decode_brotli,
|
||||||
}
|
}
|
||||||
custom_encode = {
|
custom_encode = {
|
||||||
|
"none": identity,
|
||||||
"identity": identity,
|
"identity": identity,
|
||||||
"gzip": encode_gzip,
|
"gzip": encode_gzip,
|
||||||
"deflate": encode_deflate,
|
"deflate": encode_deflate,
|
||||||
|
@ -4,18 +4,17 @@ import pytest
|
|||||||
from netlib import encoding, tutils
|
from netlib import encoding, tutils
|
||||||
|
|
||||||
|
|
||||||
def test_identity():
|
@pytest.mark.parametrize("encoder", [
|
||||||
assert b"string" == encoding.decode(b"string", "identity")
|
'identity',
|
||||||
assert b"string" == encoding.encode(b"string", "identity")
|
'none',
|
||||||
|
])
|
||||||
|
def test_identity(encoder):
|
||||||
|
assert b"string" == encoding.decode(b"string", encoder)
|
||||||
|
assert b"string" == encoding.encode(b"string", encoder)
|
||||||
with tutils.raises(ValueError):
|
with tutils.raises(ValueError):
|
||||||
encoding.encode(b"string", "nonexistent encoding")
|
encoding.encode(b"string", "nonexistent encoding")
|
||||||
|
|
||||||
|
|
||||||
def test_none():
|
|
||||||
assert b"string" == encoding.decode(b"string", "none")
|
|
||||||
assert b"string" == encoding.encode(b"string", "none")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("encoder", [
|
@pytest.mark.parametrize("encoder", [
|
||||||
'gzip',
|
'gzip',
|
||||||
'br',
|
'br',
|
||||||
|
Loading…
Reference in New Issue
Block a user