Преглед на файлове

Removed typing-module-related annotations as it's python 3.5+ only

Denis Waßmann преди 7 години
родител
ревизия
3f0066f096
променени са 2 файла, в които са добавени 7 реда и са изтрити 9 реда
  1. 4 5
      code/ID2TLib/IPv4.py
  2. 3 4
      code/ID2TLib/OldLibs/IPGenerator.py

+ 4 - 5
code/ID2TLib/IPv4.py

@@ -1,5 +1,4 @@
 import re
-from typing import Union, Any, Optional
 
 
 class IPAddress:
@@ -120,13 +119,13 @@ class IPAddress:
 	def __hash__(self) -> int:
 		return self.ipnum
 	
-	def __eq__(self, other: Any) -> bool:
+	def __eq__(self, other) -> bool:
 		if other is None:
 			return False
 		
 		return isinstance(other, IPAddress) and self.ipnum == other.ipnum
 	
-	def __lt__(self, other: Any) -> bool:
+	def __lt__(self, other) -> bool:
 		if other is None:
 			raise TypeError("Cannot compare to None")
 		if not isinstance(other, IPAddress):
@@ -147,7 +146,7 @@ class IPAddressBlock:
 	# this regex describes CIDR-notation (an ip-address plus "/XX", whereas XX is a number between 1 and 32)
 	CIDR_REGEXP = IPAddress.IP_REGEXP + r"(\/(3[0-2]|[12]?\d)|)?"
 	
-	def __init__(self, ip: Union(str, list, IPAddress), netmask = 32) -> "IPAddressBlock":
+	def __init__(self, ip: "Union(str, list, IPAddress)", netmask = 32) -> "IPAddressBlock":
 		"""
 		Construct a ip-block given a ip-address and a netmask. Given an ip and a netmask,
 		the constructed ip-block will describe the range ip/netmask (e.g. 127.0.0.1/8)
@@ -244,7 +243,7 @@ class ReservedIPBlocks:
 		return any(ip in block for block in ReservedIPBlocks.PRIVATE_IP_SEGMENTS)
 	
 	@staticmethod
-	def get_private_segment(ip: IPAddress) -> Optional[IPAddressBlock]:
+	def get_private_segment(ip: IPAddress) -> "Optional[IPAddressBlock]":
 		if not ReservedIPBlocks.is_private(ip):
 			raise ValueError("%s is not part of a private IP segment" % ip)
 

+ 3 - 4
code/ID2TLib/OldLibs/IPGenerator.py

@@ -1,6 +1,5 @@
 import random
 from code.ID2TLib import IPv4 as ip
-from typing import Union, Any
 
 
 class IPChooser:
@@ -65,7 +64,7 @@ class IPGenerator:
 	def from_range(range: ip.IPAddressBlock, *args, **kwargs) -> "IPGenerator":
 		return IPGenerator(IPChooserByRange(range), *args, **kwargs)
 	
-	def add_to_blacklist(self, ip_segment: Union[ip.IPAddressBlock, str]):
+	def add_to_blacklist(self, ip_segment: "Union[ip.IPAddressBlock, str]"):
 		if isinstance(ip_segment, ip.IPAddressBlock):
 			self.blacklist.append(ip_segment)
 		else:
@@ -100,11 +99,11 @@ class MappingIPGenerator(IPGenerator):
 		if clear_generated_ips:
 			self.mapping  = {}
 	
-	def get_mapped_ip(self, key: Any) -> ip.IPAddress:
+	def get_mapped_ip(self, key) -> ip.IPAddress:
 		if key not in self.mapping:
 			self.mapping[key] = self.random_ip()
 		
 		return self.mapping[key]
 	
-	def __getitem__(self, item: Any) -> ip.IPAddress:
+	def __getitem__(self, item) -> ip.IPAddress:
 		return self.get_mapped_ip(item)