mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 23:05:39 +00:00
lib/py: drop python 2 compatibility
This patch removes code introduced for compatibility with Python 2 in commits:bf80fee
(lib: correctly handle stdin/stdout (Python 3))b82f222
(lib: fix crit-recode fix for Python 2) Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
This commit is contained in:
committed by
Andrei Vagin
parent
d388b91de2
commit
002f2372a9
@@ -11,8 +11,6 @@ def inf(opts):
|
|||||||
if opts['in']:
|
if opts['in']:
|
||||||
return open(opts['in'], 'rb')
|
return open(opts['in'], 'rb')
|
||||||
else:
|
else:
|
||||||
if (sys.version_info < (3, 0)):
|
|
||||||
return sys.stdin
|
|
||||||
if sys.stdin.isatty():
|
if sys.stdin.isatty():
|
||||||
# If we are reading from a terminal (not a pipe) we want text input and not binary
|
# If we are reading from a terminal (not a pipe) we want text input and not binary
|
||||||
return sys.stdin
|
return sys.stdin
|
||||||
@@ -28,8 +26,6 @@ def outf(opts, decode):
|
|||||||
mode = 'w+'
|
mode = 'w+'
|
||||||
return open(opts['out'], mode)
|
return open(opts['out'], mode)
|
||||||
else:
|
else:
|
||||||
if (sys.version_info < (3, 0)):
|
|
||||||
return sys.stdout
|
|
||||||
if decode:
|
if decode:
|
||||||
return sys.stdout
|
return sys.stdout
|
||||||
return sys.stdout.buffer
|
return sys.stdout.buffer
|
||||||
|
@@ -42,7 +42,6 @@ import base64
|
|||||||
import struct
|
import struct
|
||||||
import os
|
import os
|
||||||
import array
|
import array
|
||||||
import sys
|
|
||||||
|
|
||||||
from . import magic
|
from . import magic
|
||||||
from . import pb
|
from . import pb
|
||||||
@@ -71,18 +70,12 @@ class MagicException(Exception):
|
|||||||
|
|
||||||
def decode_base64_data(data):
|
def decode_base64_data(data):
|
||||||
"""A helper function to decode base64 data."""
|
"""A helper function to decode base64 data."""
|
||||||
if (sys.version_info > (3, 0)):
|
return base64.decodebytes(str.encode(data))
|
||||||
return base64.decodebytes(str.encode(data))
|
|
||||||
else:
|
|
||||||
return base64.decodebytes(data)
|
|
||||||
|
|
||||||
|
|
||||||
def write_base64_data(f, data):
|
def write_base64_data(f, data):
|
||||||
"""A helper function to write base64 encoded data to a file."""
|
"""A helper function to write base64 encoded data to a file."""
|
||||||
if (sys.version_info > (3, 0)):
|
f.write(base64.decodebytes(str.encode(data)))
|
||||||
f.write(base64.decodebytes(str.encode(data)))
|
|
||||||
else:
|
|
||||||
f.write(base64.decodebytes(data))
|
|
||||||
|
|
||||||
|
|
||||||
# Generic class to handle loading/dumping criu images entries from/to bin
|
# Generic class to handle loading/dumping criu images entries from/to bin
|
||||||
|
@@ -3,7 +3,6 @@ import collections
|
|||||||
import os
|
import os
|
||||||
import quopri
|
import quopri
|
||||||
import socket
|
import socket
|
||||||
import sys
|
|
||||||
from ipaddress import IPv4Address, IPv6Address, ip_address
|
from ipaddress import IPv4Address, IPv6Address, ip_address
|
||||||
|
|
||||||
from google.protobuf.descriptor import FieldDescriptor as FD
|
from google.protobuf.descriptor import FieldDescriptor as FD
|
||||||
@@ -247,17 +246,11 @@ def encode_dev(field, value):
|
|||||||
|
|
||||||
|
|
||||||
def encode_base64(value):
|
def encode_base64(value):
|
||||||
if (sys.version_info > (3, 0)):
|
return base64.encodebytes(value).decode()
|
||||||
return base64.encodebytes(value).decode()
|
|
||||||
else:
|
|
||||||
return base64.encodebytes(value)
|
|
||||||
|
|
||||||
|
|
||||||
def decode_base64(value):
|
def decode_base64(value):
|
||||||
if (sys.version_info > (3, 0)):
|
return base64.decodebytes(str.encode(value))
|
||||||
return base64.decodebytes(str.encode(value))
|
|
||||||
else:
|
|
||||||
return base64.decodebytes(value)
|
|
||||||
|
|
||||||
|
|
||||||
def encode_unix(value):
|
def encode_unix(value):
|
||||||
|
Reference in New Issue
Block a user