mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-11 05:17:59 +03:00
Drop python3 compat imports
We are going completely python3
This commit is contained in:
parent
e90d728380
commit
3086c7fda9
@ -146,10 +146,7 @@ class Command(object):
|
||||
oldstdin = sys.stdin
|
||||
oldargv = sys.argv
|
||||
try:
|
||||
if sys.version_info[0] == 3:
|
||||
out = io.StringIO()
|
||||
else:
|
||||
out = io.BytesIO()
|
||||
out = io.StringIO()
|
||||
|
||||
sys.stdout = out
|
||||
sys.stderr = out
|
||||
|
@ -20,7 +20,6 @@ from __future__ import print_function
|
||||
import glob
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from virtconv import VirtConverter
|
||||
@ -33,11 +32,7 @@ out_dir = base_dir + "libvirt_output"
|
||||
|
||||
class TestVirtConv(unittest.TestCase):
|
||||
def _convert_helper(self, infile, outfile, in_type, disk_format):
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
outbuf = io.StringIO()
|
||||
else:
|
||||
outbuf = io.BytesIO()
|
||||
outbuf = io.StringIO()
|
||||
|
||||
def print_cb(msg):
|
||||
print(msg, file=outbuf)
|
||||
|
@ -20,13 +20,11 @@
|
||||
|
||||
import ipaddress
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import Pango
|
||||
|
||||
|
||||
from virtinst import Network
|
||||
|
||||
from . import uiutil
|
||||
@ -45,15 +43,12 @@ _red = Gdk.Color.parse("#ffc0c0")[1]
|
||||
_black = Gdk.Color.parse("#000000")[1]
|
||||
_white = Gdk.Color.parse("#f0f0f0")[1]
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
unicode = str # pylint: disable=redefined-builtin
|
||||
|
||||
|
||||
def _make_ipaddr(addrstr):
|
||||
if addrstr is None:
|
||||
return None
|
||||
try:
|
||||
return ipaddress.ip_network(unicode(addrstr), strict=False)
|
||||
return ipaddress.ip_network(str(addrstr), strict=False)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
@ -19,33 +19,29 @@
|
||||
#
|
||||
|
||||
import ipaddress
|
||||
import sys
|
||||
|
||||
from virtinst import Network
|
||||
|
||||
from .libvirtobject import vmmLibvirtObject
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
unicode = str # pylint: disable=redefined-builtin
|
||||
|
||||
|
||||
def _make_addr_str(addrStr, prefix, netmaskStr):
|
||||
if prefix:
|
||||
return str(
|
||||
ipaddress.ip_network(
|
||||
unicode("{}/{}").format(addrStr, prefix), strict=False
|
||||
str("{}/{}").format(addrStr, prefix), strict=False
|
||||
)
|
||||
)
|
||||
elif netmaskStr:
|
||||
netmask = ipaddress.ip_address(unicode((netmaskStr)))
|
||||
network = ipaddress.ip_address(unicode((addrStr)))
|
||||
netmask = ipaddress.ip_address(str((netmaskStr)))
|
||||
network = ipaddress.ip_address(str((addrStr)))
|
||||
return str(
|
||||
ipaddress.ip_network(
|
||||
unicode("{}/{}").format(network, netmask), strict=False
|
||||
str("{}/{}").format(network, netmask), strict=False
|
||||
)
|
||||
)
|
||||
else:
|
||||
return str(ipaddress.ip_network(unicode(addrStr), strict=False))
|
||||
return str(ipaddress.ip_network(str(addrStr), strict=False))
|
||||
|
||||
|
||||
class vmmNetwork(vmmLibvirtObject):
|
||||
@ -148,7 +144,7 @@ class vmmNetwork(vmmLibvirtObject):
|
||||
return [None, None]
|
||||
|
||||
routeAddr = _make_addr_str(route.address, route.prefix, route.netmask)
|
||||
routeVia = str(ipaddress.ip_address(unicode(route.gateway)))
|
||||
routeVia = str(ipaddress.ip_address(str(route.gateway)))
|
||||
|
||||
if not routeAddr or not routeVia:
|
||||
return [None, None]
|
||||
@ -182,8 +178,8 @@ class vmmNetwork(vmmLibvirtObject):
|
||||
|
||||
dhcp = [None, None]
|
||||
if dhcpstart and dhcpend:
|
||||
dhcp = [str(ipaddress.ip_address(unicode(dhcpstart))),
|
||||
str(ipaddress.ip_address(unicode(dhcpend)))]
|
||||
dhcp = [str(ipaddress.ip_address(str(dhcpstart))),
|
||||
str(ipaddress.ip_address(str(dhcpend)))]
|
||||
return [ret, dhcp]
|
||||
|
||||
def get_ipv4_network(self):
|
||||
|
@ -23,15 +23,11 @@ import os
|
||||
import queue
|
||||
import socket
|
||||
import signal
|
||||
import sys
|
||||
import threading
|
||||
import ipaddress
|
||||
|
||||
from .baseclass import vmmGObject
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
unicode = str # pylint: disable=redefined-builtin
|
||||
|
||||
|
||||
class ConnectionInfo(object):
|
||||
"""
|
||||
@ -55,13 +51,13 @@ class ConnectionInfo(object):
|
||||
|
||||
def _is_listen_localhost(self, host=None):
|
||||
try:
|
||||
return ipaddress.ip_network(unicode(host or self.gaddr)).is_loopback
|
||||
return ipaddress.ip_network(str(host or self.gaddr)).is_loopback
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def _is_listen_any(self):
|
||||
try:
|
||||
return ipaddress.ip_network(unicode(self.gaddr)).is_unspecified
|
||||
return ipaddress.ip_network(str(self.gaddr)).is_unspecified
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
@ -399,19 +399,11 @@ class Guest(XMLBuilder):
|
||||
try:
|
||||
domain.create()
|
||||
except Exception:
|
||||
# pylint: disable=exec-used, unused-variable
|
||||
import sys
|
||||
exc_info = sys.exc_info()
|
||||
try:
|
||||
domain.undefine()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
raise
|
||||
else:
|
||||
# Use exec() to avoid syntax error from Python 3
|
||||
exec("raise exc_info[0], exc_info[1], exc_info[2]")
|
||||
raise
|
||||
|
||||
|
||||
if install_xml and install_xml != final_xml:
|
||||
|
@ -22,16 +22,12 @@ Classes for building and installing libvirt interface xml
|
||||
|
||||
import ipaddress
|
||||
import logging
|
||||
import sys
|
||||
|
||||
import libvirt
|
||||
|
||||
from . import util
|
||||
from .xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
unicode = str # pylint: disable=redefined-builtin
|
||||
|
||||
|
||||
class _IPAddress(XMLBuilder):
|
||||
_XML_PROP_ORDER = ["address", "prefix"]
|
||||
@ -42,7 +38,7 @@ class _IPAddress(XMLBuilder):
|
||||
######################
|
||||
|
||||
def _validate_ipaddr(self, addr):
|
||||
ipaddress.ip_address(unicode(addr))
|
||||
ipaddress.ip_address(str(addr))
|
||||
return addr
|
||||
|
||||
address = XMLProperty("./@address", validate_cb=_validate_ipaddr)
|
||||
|
@ -19,16 +19,7 @@
|
||||
|
||||
import logging
|
||||
import re
|
||||
import sys
|
||||
|
||||
# pylint: disable=no-name-in-module,import-error
|
||||
if sys.version_info[0] == 3:
|
||||
# Python 3
|
||||
from urllib.parse import unquote
|
||||
else:
|
||||
# Python 2
|
||||
from urlparse import unquote
|
||||
|
||||
import urllib.parse
|
||||
|
||||
from .cli import parse_optstr_tuples
|
||||
|
||||
@ -56,7 +47,7 @@ class URI(object):
|
||||
"""
|
||||
def __init__(self, uri):
|
||||
self.uri = uri
|
||||
unquoted_uri = unquote(uri)
|
||||
unquoted_uri = urllib.parse.unquote(uri)
|
||||
|
||||
(self.scheme, self.username, self.hostname,
|
||||
self.path, self.query, self.fragment) = self._split(unquoted_uri)
|
||||
|
@ -26,23 +26,14 @@ import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
import requests
|
||||
|
||||
from .osdict import OSDB
|
||||
|
||||
# pylint: disable=no-name-in-module, import-error
|
||||
if sys.version_info[0] == 3:
|
||||
# Python 3
|
||||
from urllib.parse import urlparse
|
||||
from urllib.request import Request, urlopen
|
||||
else:
|
||||
# Python 2
|
||||
from urlparse import urlparse
|
||||
from urllib2 import Request, urlopen
|
||||
|
||||
|
||||
#########################################################################
|
||||
# Backends for the various URL types we support (http, ftp, nfs, local) #
|
||||
@ -228,7 +219,7 @@ class _FTPURLFetcher(_URLFetcher):
|
||||
return
|
||||
|
||||
try:
|
||||
parsed = urlparse(self.location)
|
||||
parsed = urllib.parse.urlparse(self.location)
|
||||
self._ftp = ftplib.FTP()
|
||||
self._ftp.connect(parsed.hostname, parsed.port)
|
||||
self._ftp.login()
|
||||
@ -242,9 +233,9 @@ class _FTPURLFetcher(_URLFetcher):
|
||||
"""
|
||||
Use urllib and ftplib to grab the file
|
||||
"""
|
||||
request = Request(url)
|
||||
urlobj = urlopen(request)
|
||||
size = self._ftp.size(urlparse(url)[2])
|
||||
request = urllib.request.Request(url)
|
||||
urlobj = urllib.request.urlopen(request)
|
||||
size = self._ftp.size(urllib.parse.urlparse(url)[2])
|
||||
return urlobj, size
|
||||
|
||||
|
||||
@ -260,7 +251,7 @@ class _FTPURLFetcher(_URLFetcher):
|
||||
self._ftp = None
|
||||
|
||||
def _hasFile(self, url):
|
||||
path = urlparse.urlparse(url)[2]
|
||||
path = urllib.parse.urlparse(url)[2]
|
||||
|
||||
try:
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user