Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove six compatibility layer dependency #2535

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c3a8106
Remove usage of `six.integer_types`
peace-maker Jan 17, 2025
9c2a75d
Remove usage of `six.string_types`
peace-maker Jan 17, 2025
9d27ce6
Remove usage of `six.text_type`
peace-maker Jan 17, 2025
ec88ecb
Remove usage of `six.binary_type`
peace-maker Jan 17, 2025
b5b0f66
Remove usage of `from six.moves import range`
peace-maker Jan 17, 2025
d25d251
Remove usage of `from six.moves import configparser`
peace-maker Jan 17, 2025
75f19e5
Remove usage of `six.class_types`
peace-maker Jan 17, 2025
4f03b9c
Remove usage of `from six.moves import urllib`
peace-maker Jan 17, 2025
0a259c2
Remove usage of `six.int2byte`
peace-maker Jan 17, 2025
7408fe0
Remove usage of `six.indexbytes`
peace-maker Jan 17, 2025
cc50e7d
Remove usage of `from six.moves import builtins`
peace-maker Jan 17, 2025
c4ab1fa
Remove usage of `from six import BytesIO`
peace-maker Jan 17, 2025
988fb7e
Remove usage of `six.unichr`
peace-maker Jan 17, 2025
bfed673
Remove usage of `six.print_`
peace-maker Jan 17, 2025
ec12ebf
Remove usage of `from six.moves.queue import Queue`
peace-maker Jan 17, 2025
333efe6
Remove usage of `six.get_function_defaults` and `six.get_function_code`
peace-maker Jan 17, 2025
6f97600
Remove usage of `six.b`
peace-maker Jan 17, 2025
7b6560f
Remove usage of itertools/builtins from `six.moves`
peace-maker Jan 17, 2025
b633165
Remove usage of `pickle` and `StringIO` from `six.moves`
peace-maker Jan 17, 2025
e0e20c6
Remove code guarded by `six.PY2`
peace-maker Jan 17, 2025
1a68b1f
Remove `python_2_bytes_compatible` decorator
peace-maker Jan 17, 2025
b7a4373
Remove `six` dependency from pyproject.toml 🎉
peace-maker Jan 17, 2025
879c186
Update CHANGELOG
peace-maker Jan 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ The table below shows which release corresponds to each branch, and what date th
- [#2526][2526] Properly make use of extra arguments in `packing` utilities. `sign` parameter requires keyword syntax to specify it.
- [#2517][2517] Allow to passthru kwargs on `ssh.__getattr__` convenience function to fix SSH motd problems
- [#2527][2527] Allow setting debugger path via `context.gdb_binary`
- [#2535][2535] Remove `six` Python 2 compatibility layer dependency

[2519]: https://github.com/Gallopsled/pwntools/pull/2519
[2507]: https://github.com/Gallopsled/pwntools/pull/2507
Expand All @@ -89,6 +90,7 @@ The table below shows which release corresponds to each branch, and what date th
[2526]: https://github.com/Gallopsled/pwntools/pull/2526
[2517]: https://github.com/Gallopsled/pwntools/pull/2517
[2527]: https://github.com/Gallopsled/pwntools/pull/2527
[2535]: https://github.com/Gallopsled/pwntools/pull/2535

## 4.15.0 (`beta`)

Expand Down
4 changes: 1 addition & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import os
import doctest
import signal
import six
import subprocess
import sys

Expand Down Expand Up @@ -71,7 +70,6 @@ def filter(self, record):
import sys, os
os.environ['PWNLIB_NOTERM'] = '1'
os.environ['PWNLIB_RANDOMIZE'] = '0'
import six
import pwnlib.update
import pwnlib.util.fiddling
import logging
Expand Down Expand Up @@ -362,7 +360,7 @@ def linkcode_resolve(domain, info):
if isinstance(val, property):
val = val.fget

if isinstance(val, (types.ModuleType, types.MethodType, types.FunctionType, types.TracebackType, types.FrameType, types.CodeType) + six.class_types):
if isinstance(val, (types.ModuleType, types.MethodType, types.FunctionType, types.TracebackType, types.FrameType, types.CodeType, type)):
try:
lines, first = inspect.getsourcelines(val)
filename += '#L%d-L%d' % (first, first + len(lines) - 1)
Expand Down
1 change: 0 additions & 1 deletion docs/source/filesystem.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.. testsetup:: *

import time
import six
from pwnlib.context import context
from pwnlib.tubes.ssh import ssh
from pwnlib.filesystem import *
Expand Down
4 changes: 2 additions & 2 deletions pwn/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@

# Promote these modules, so that "from pwn import *" will let you access them

from six.moves import cPickle as pickle, cStringIO as StringIO
from six import BytesIO
import pickle
from io import BytesIO, StringIO

log = getLogger("pwnlib.exploit")
error = log.error
Expand Down
7 changes: 3 additions & 4 deletions pwnlib/adb/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import os
import re
import shutil
import six
import stat
import tempfile
import time
Expand Down Expand Up @@ -85,7 +84,7 @@ def adb(argv, *a, **kw):
>>> adb.adb(['shell', 'uname']) # it is better to use adb.process
b'Linux\n'
"""
if isinstance(argv, (bytes, six.text_type)):
if isinstance(argv, (bytes, str)):
argv = [argv]

log.debug("$ " + ' '.join(context.adb + argv))
Expand Down Expand Up @@ -838,7 +837,7 @@ def process(argv, *a, **kw):
>>> print(adb.process(['cat','/proc/version']).recvall().decode('utf-8')) # doctest: +ELLIPSIS
Linux version ...
"""
if isinstance(argv, (bytes, six.text_type)):
if isinstance(argv, (bytes, str)):
argv = [argv]

message = "Starting %s process %r" % ('Android', argv[0])
Expand Down Expand Up @@ -1263,7 +1262,7 @@ def __eq__(self, other):
>>> adb.properties.ro.build.version.sdk == "24"
True
"""
if isinstance(other, six.string_types):
if isinstance(other, str):
return str(self) == other
return super(Property, self).__eq__(other)

Expand Down
3 changes: 1 addition & 2 deletions pwnlib/adb/bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ctypes
import io
import os
import six
import sys

from pwnlib.log import getLogger
Expand Down Expand Up @@ -65,7 +64,7 @@ def extract(self, index_or_name):
Returns:
Contents of the image.
"""
if isinstance(index_or_name, six.integer_types):
if isinstance(index_or_name, int):
index = index_or_name
else:
for i in range(len(self.img_info)):
Expand Down
7 changes: 2 additions & 5 deletions pwnlib/commandline/cyclic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import division

import argparse
import six
import string
import sys

Expand All @@ -11,6 +10,7 @@

from pwn import *
from pwnlib.commandline import common
from pwnlib.util.packing import _encode

parser = common.parser_commands.add_parser(
'cyclic',
Expand Down Expand Up @@ -64,10 +64,7 @@ def main(args):
subsize = args.length

if args.lookup:
pat = args.lookup

if six.PY3:
pat = bytes(pat, encoding='utf-8')
pat = _encode(args.lookup)

try:
pat = int(pat, 0)
Expand Down
5 changes: 2 additions & 3 deletions pwnlib/commandline/shellcraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import argparse
import os
import six
import sys
import types

Expand Down Expand Up @@ -280,8 +279,8 @@ def main(args):

code_array = []
for (name, func, func_args) in funcs:
defargs = len(six.get_function_defaults(func) or ())
reqargs = six.get_function_code(func).co_argcount - defargs
defargs = len(func.__defaults__ or ())
reqargs = func.__code__.co_argcount - defargs

if len(func_args) < reqargs:
if defargs > 0:
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from __future__ import absolute_import
from __future__ import division

from six.moves import configparser
import configparser
import os

registered_configs = {}
Expand Down
9 changes: 4 additions & 5 deletions pwnlib/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import os.path
import platform
import shutil
import six
import socket
import string
import sys
Expand Down Expand Up @@ -1040,7 +1039,7 @@ def log_file(self, value):
>>> open(bar_txt).readlines()[-1] #doctest: +ELLIPSIS
'...:DEBUG:...:Hello from bar!\n'
"""
if isinstance(value, (bytes, six.text_type)):
if isinstance(value, (bytes, str)):
# check if mode was specified as "[value],[mode]"
from pwnlib.util.packing import _need_text
value = _need_text(value)
Expand Down Expand Up @@ -1258,7 +1257,7 @@ def terminal(self, value):
Can be a string or an iterable of strings. In the latter case the first
entry is the terminal and the rest are default arguments.
"""
if isinstance(value, (bytes, six.text_type)):
if isinstance(value, (bytes, str)):
return [value]
return value

Expand Down Expand Up @@ -1339,7 +1338,7 @@ def adb_port(self, value):
def device(self, device):
"""Sets the device being operated on.
"""
if isinstance(device, (bytes, six.text_type)):
if isinstance(device, (bytes, str)):
device = Device(device)
if isinstance(device, Device):
self.arch = device.arch or self.arch
Expand Down Expand Up @@ -1755,7 +1754,7 @@ def update_context_defaults(section):

default = ContextType.defaults[key]

if isinstance(default, six.string_types + six.integer_types + (tuple, list, dict)):
if isinstance(default, (str, int, tuple, list, dict)):
value = safeeval.expr(value)
else:
log.warn("Unsupported configuration option %r in section %r" % (key, 'context'))
Expand Down
5 changes: 2 additions & 3 deletions pwnlib/data/syscalls/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import pwnlib.abi
import pwnlib.constants
import pwnlib.shellcraft
import six
%>
'''

Expand Down Expand Up @@ -76,8 +75,8 @@

# The argument is not a register. It is a string value, and we
# are expecting a string value
elif name in can_pushstr and isinstance(arg, (six.binary_type, six.text_type)):
if isinstance(arg, six.text_type):
elif name in can_pushstr and isinstance(arg, (bytes, str)):
if isinstance(arg, str):
arg = arg.encode('utf-8')
string_arguments[name] = arg

Expand Down
6 changes: 2 additions & 4 deletions pwnlib/elf/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@
import mmap
import os
import re
import six
import subprocess
import tempfile

from six import BytesIO

from collections import namedtuple, defaultdict
from io import BytesIO

from elftools.elf.constants import P_FLAGS
from elftools.elf.constants import SHN_INDICES
Expand Down Expand Up @@ -266,7 +264,7 @@ def __init__(self, path, checksec=True):
#:
#: See: :attr:`.ContextType.arch`
self.arch = self.get_machine_arch()
if isinstance(self.arch, (bytes, six.text_type)):
if isinstance(self.arch, (bytes, str)):
self.arch = self.arch.lower()

self._sections = None
Expand Down
7 changes: 1 addition & 6 deletions pwnlib/encoders/i386/ascii_shellcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

from itertools import product

import six

from pwnlib.context import LocalContext
from pwnlib.context import context
from pwnlib.encoders.encoder import Encoder
Expand Down Expand Up @@ -43,10 +41,7 @@ def __init__(self, slop=20, max_subs=4):
there are, the bigger the packed shellcode will be.
Defaults to 4.
"""
if six.PY2:
super(AsciiShellcodeEncoder, self).__init__()
elif six.PY3:
super().__init__()
super().__init__()
self.slop = slop
self.max_subs = max_subs

Expand Down
3 changes: 1 addition & 2 deletions pwnlib/encoders/i386/delta.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import absolute_import
from __future__ import division

import six
import collections
from random import choice
from random import randint
Expand Down Expand Up @@ -59,7 +58,7 @@ def __call__(self, raw_bytes, avoid, pcreg=''):
table = collections.defaultdict(lambda: [])
endchar = bytearray()

not_bad = lambda x: six.int2byte(x) not in avoid
not_bad = lambda x: bytes((x,)) not in avoid
not_bad_or_term = lambda x: not_bad(x) and x != self.terminator

for i in filter(not_bad_or_term, range(0, 256)):
Expand Down
5 changes: 2 additions & 3 deletions pwnlib/encoders/mips/xor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from __future__ import absolute_import
from __future__ import division

import six
from pwnlib import asm
from pwnlib import shellcraft
from pwnlib.context import context
Expand Down Expand Up @@ -128,8 +127,8 @@ def __call__(self, raw_bytes, avoid, pcreg=''):
sizehi = size >> 8

decoder = decoders[context.endian]
decoder = decoder.replace(b'SIZ1', six.int2byte(sizehi))
decoder = decoder.replace(b'SIZ2', six.int2byte(sizelo))
decoder = decoder.replace(b'SIZ1', bytes((sizehi,)))
decoder = decoder.replace(b'SIZ2', bytes((sizelo,)))

key, data = xor_key(raw_bytes, avoid=avoid)

Expand Down
2 changes: 0 additions & 2 deletions pwnlib/filepointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

from pwnlib.context import context
from pwnlib.log import getLogger
from pwnlib.util.misc import python_2_bytes_compatible
from pwnlib.util.packing import pack

log = getLogger(__name__)
Expand Down Expand Up @@ -98,7 +97,6 @@ def update_var(l):
return var


@python_2_bytes_compatible
class FileStructure(object):
r"""
Crafts a FILE structure, with default values for some fields, like _lock which should point to null ideally, set.
Expand Down
6 changes: 1 addition & 5 deletions pwnlib/filesystem/path.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import six
import tempfile

if six.PY3:
from pathlib import *
else:
from pathlib2 import *
from pathlib import *

@classmethod
def mktemp(cls):
Expand Down
17 changes: 4 additions & 13 deletions pwnlib/filesystem/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Emulates pathlib as much as possible, but does so through duck typing.
"""
import os
import six
import sys
import tempfile
import time
Expand All @@ -14,10 +13,7 @@
from pwnlib.util.misc import read, write
from pwnlib.util.packing import _encode, _decode

if six.PY3:
from pathlib import *
else:
from pathlib2 import *
from pathlib import *

class SSHPath(PosixPath):
r"""Represents a file that exists on a remote filesystem.
Expand Down Expand Up @@ -82,11 +78,11 @@ def _s(self, other):
return other

# We don't want unicode
if isinstance(other, six.text_type):
if isinstance(other, str):
return str(other)

# We also don't want binary
if isinstance(other, six.binary_type):
if isinstance(other, bytes):
return str(_decode(other))

def _new(self, path, *a, **kw):
Expand Down Expand Up @@ -399,14 +395,9 @@ def resolve(self, strict=False):
path = self.absolute().path
path = os.path.normpath(path)

if six.PY2:
error_type = IOError
else:
error_type = FileNotFoundError

try:
return self._new(self.ssh.sftp.normalize(path))
except error_type as e:
except FileNotFoundError as e:
raise ValueError("Could not normalize path: %r" % path)

def stat(self):
Expand Down
1 change: 0 additions & 1 deletion pwnlib/fmtstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def send_payload(payload):
import logging
import re
from operator import itemgetter
from six.moves import range
from sortedcontainers import SortedList

from pwnlib.log import getLogger
Expand Down
Loading
Loading