mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-22 03:04:09 -04:00
avoid unneeded py3 shims.
This commit is contained in:
parent
d6e462ed33
commit
ead4b9212a
4 changed files with 30 additions and 36 deletions
|
@ -1,6 +1,6 @@
|
|||
# Contributing to PySol FC
|
||||
|
||||
You want to contribute? That's great! First of all see [these links](https://github.com/shlomif/Freenode-programming-channel-FAQ/blob/master/FAQ.mdwn#i-want-to-contribute-to-an-open-source-project-but-how-which-one-can-i-contribute-to)
|
||||
You want to contribute? That's great! Welcome aboard. First of all see [these links](https://github.com/shlomif/Freenode-programming-channel-FAQ/blob/master/FAQ.mdwn#i-want-to-contribute-to-an-open-source-project-but-how-which-one-can-i-contribute-to)
|
||||
for general guidelines for contributing to open source.
|
||||
|
||||
# Contribution constraints
|
||||
|
|
|
@ -138,7 +138,6 @@ if INTP_VER < (2, 2):
|
|||
raise RuntimeError("Python v.2.2 or later needed")
|
||||
|
||||
if sys.version_info > (3,):
|
||||
long = int
|
||||
unicode = str
|
||||
|
||||
StringTypes = (str, unicode)
|
||||
|
@ -265,7 +264,7 @@ def dottedQuadToNum(ip):
|
|||
except socket.error:
|
||||
# bug in inet_aton, corrected in Python 2.3
|
||||
if ip.strip() == '255.255.255.255':
|
||||
return long('0xFFFFFFFF', 0)
|
||||
return int('0xFFFFFFFF', 0)
|
||||
else:
|
||||
raise ValueError('Not a good dotted-quad IP: %s' % ip)
|
||||
return
|
||||
|
@ -300,7 +299,7 @@ def numToDottedQuad(num):
|
|||
# no need to intercept here, 4294967295L is fine
|
||||
try:
|
||||
return socket.inet_ntoa(
|
||||
struct.pack('!L', long(num)))
|
||||
struct.pack('!L', int(num)))
|
||||
except (socket.error, struct.error, OverflowError):
|
||||
raise ValueError('Not a good numeric IP: %s' % num)
|
||||
|
||||
|
@ -461,7 +460,7 @@ class Validator(object):
|
|||
... # check that value is of the correct type.
|
||||
... # possible valid inputs are integers or strings
|
||||
... # that represent integers
|
||||
... if not isinstance(value, (int, long, StringTypes)):
|
||||
... if not isinstance(value, (int, StringTypes)):
|
||||
... raise VdtTypeError(value)
|
||||
... elif isinstance(value, StringTypes):
|
||||
... # if we are given a string
|
||||
|
@ -671,7 +670,7 @@ def _is_num_param(names, values, to_float=False):
|
|||
for (name, val) in zip(names, values):
|
||||
if val is None:
|
||||
out_params.append(val)
|
||||
elif isinstance(val, (int, long, float, StringTypes)):
|
||||
elif isinstance(val, (int, float, StringTypes)):
|
||||
try:
|
||||
out_params.append(fun(val))
|
||||
except ValueError:
|
||||
|
@ -729,7 +728,7 @@ def is_integer(value, min=None, max=None):
|
|||
"""
|
||||
# print value, type(value)
|
||||
(min_val, max_val) = _is_num_param(('min', 'max'), (min, max))
|
||||
if not isinstance(value, (int, long, StringTypes)):
|
||||
if not isinstance(value, (int, StringTypes)):
|
||||
raise VdtTypeError(value)
|
||||
if isinstance(value, StringTypes):
|
||||
# if it's a string - does it represent an integer ?
|
||||
|
@ -781,7 +780,7 @@ def is_float(value, min=None, max=None):
|
|||
"""
|
||||
(min_val, max_val) = _is_num_param(
|
||||
('min', 'max'), (min, max), to_float=True)
|
||||
if not isinstance(value, (int, long, float, StringTypes)):
|
||||
if not isinstance(value, (int, float, StringTypes)):
|
||||
raise VdtTypeError(value)
|
||||
if not isinstance(value, float):
|
||||
# if it's a string - does it represent a float ?
|
||||
|
|
|
@ -68,7 +68,6 @@ if True: # This prevents from travis 'error' E402.
|
|||
|
||||
if sys.version_info > (3,):
|
||||
basestring = str
|
||||
long = int
|
||||
|
||||
PLAY_TIME_TIMEOUT = 200
|
||||
|
||||
|
@ -787,7 +786,7 @@ class Game(object):
|
|||
self.app.gamerandom.setstate(state)
|
||||
# we want at least 17 digits
|
||||
seed = self.app.gamerandom.randrange(
|
||||
long('10000000000000000'),
|
||||
int('10000000000000000'),
|
||||
PysolRandom.MAX_SEED
|
||||
)
|
||||
self.random = PysolRandom(seed)
|
||||
|
@ -3217,7 +3216,7 @@ in the current implementation.''') % version)
|
|||
game.version = version
|
||||
game.version_tuple = version_tuple
|
||||
#
|
||||
initial_seed = random__long2str(pload(long))
|
||||
initial_seed = random__long2str(pload(int))
|
||||
game.random = constructRandom(initial_seed)
|
||||
state = pload()
|
||||
game.random.setstate(state)
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
|
||||
# imports
|
||||
import sys
|
||||
import re
|
||||
import time
|
||||
from pysollib.mfxutil import SubclassResponsibility
|
||||
|
@ -35,20 +34,17 @@ except ImportError:
|
|||
"https://pypi.python.org/pypi/random2 using pip or similar.")
|
||||
|
||||
|
||||
if sys.version_info > (3,):
|
||||
long = int
|
||||
|
||||
# ************************************************************************
|
||||
# * Abstract class for PySol Random number generator.
|
||||
# *
|
||||
# * We use a seed of type long in the range [0, MAX_SEED].
|
||||
# * We use a seed of type int in the range [0, MAX_SEED].
|
||||
# ************************************************************************
|
||||
|
||||
|
||||
class BasicRandom:
|
||||
# MAX_SEED = 0L
|
||||
# MAX_SEED = 0xffffffffffffffffL # 64 bits
|
||||
MAX_SEED = long('100000000000000000000') # 20 digits
|
||||
MAX_SEED = int('100000000000000000000') # 20 digits
|
||||
|
||||
ORIGIN_UNKNOWN = 0
|
||||
ORIGIN_RANDOM = 1
|
||||
|
@ -72,18 +68,18 @@ class BasicRandom:
|
|||
raise SubclassResponsibility
|
||||
|
||||
def copy(self):
|
||||
random = self.__class__(long(0))
|
||||
random = self.__class__(0)
|
||||
random.__dict__.update(self.__dict__)
|
||||
return random
|
||||
|
||||
def increaseSeed(self, seed):
|
||||
if seed < self.MAX_SEED:
|
||||
return seed + long(1)
|
||||
return long(0)
|
||||
return seed + 1
|
||||
return 0
|
||||
|
||||
def _getRandomSeed(self):
|
||||
t = long(time.time() * 256.0)
|
||||
t = (t ^ (t >> 24)) % (self.MAX_SEED + long(1))
|
||||
t = int(time.time() * 256.0)
|
||||
t = (t ^ (t >> 24)) % (self.MAX_SEED + 1)
|
||||
return t
|
||||
|
||||
def setSeedAsStr(self, new_s):
|
||||
|
@ -156,7 +152,7 @@ class MFXRandom(BasicRandom):
|
|||
return self.seed
|
||||
|
||||
def setSeed(self, seed):
|
||||
seed = long(seed)
|
||||
seed = int(seed)
|
||||
if not (0 <= seed <= self.MAX_SEED):
|
||||
raise ValueError("seed out of range")
|
||||
self.seed = seed
|
||||
|
@ -177,7 +173,7 @@ class MFXRandom(BasicRandom):
|
|||
|
||||
# Get a random integer in the range [a, b] including both end points.
|
||||
def randint(self, a, b):
|
||||
return a + long(self.random() * (b+1-a))
|
||||
return a + int(self.random() * (b+1-a))
|
||||
|
||||
def randrange(self, a, b):
|
||||
return self.randint(a, b-1)
|
||||
|
@ -201,12 +197,12 @@ class MFXRandom(BasicRandom):
|
|||
class LCRandom64(MFXRandom):
|
||||
|
||||
def random(self):
|
||||
self.seed = (self.seed*long('6364136223846793005') + 1) & self.MAX_SEED
|
||||
self.seed = (self.seed*int('6364136223846793005') + 1) & self.MAX_SEED
|
||||
return ((self.seed >> 21) & 0x7fffffff) / 2147483648.0
|
||||
|
||||
|
||||
MS_LONG_BIT = (long(1) << 1000)
|
||||
CUSTOM_BIT = (long(1) << 999)
|
||||
MS_LONG_BIT = (1 << 1000)
|
||||
CUSTOM_BIT = (1 << 999)
|
||||
|
||||
|
||||
class CustomRandom(BasicRandom):
|
||||
|
@ -235,7 +231,7 @@ class CustomRandom(BasicRandom):
|
|||
|
||||
|
||||
class LCRandom31(MFXRandom):
|
||||
MAX_SEED = long('0x1ffffffff', 0) # 33 bits
|
||||
MAX_SEED = int('0x1ffffffff', 0) # 33 bits
|
||||
|
||||
def getSeedStr(self):
|
||||
return "ms" + str(self.initial_seed)
|
||||
|
@ -244,12 +240,12 @@ class LCRandom31(MFXRandom):
|
|||
return "%05d" % int(seed)
|
||||
|
||||
def setSeed(self, seed):
|
||||
seed = long(seed)
|
||||
seed = int(seed)
|
||||
self.seed = seed
|
||||
if not (0 <= seed <= self.MAX_SEED):
|
||||
raise ValueError("seed out of range")
|
||||
self.seedx = (seed if (seed < long('0x100000000', 0)) else
|
||||
(seed - long('0x100000000', 0)))
|
||||
self.seedx = (seed if (seed < int('0x100000000', 0)) else
|
||||
(seed - int('0x100000000', 0)))
|
||||
return seed
|
||||
|
||||
def _rando(self):
|
||||
|
@ -301,19 +297,19 @@ def constructRandom(s):
|
|||
return CustomRandom()
|
||||
m = _match_ms(s)
|
||||
if m:
|
||||
seed = long(m.group(1))
|
||||
seed = int(m.group(1))
|
||||
if 0 <= seed <= LCRandom31.MAX_SEED:
|
||||
ret = LCRandom31(seed)
|
||||
ret.setSeedAsStr(s)
|
||||
return ret
|
||||
else:
|
||||
raise ValueError("ms seed out of range")
|
||||
# cut off "L" from possible conversion to long
|
||||
# cut off "L" from possible conversion to int
|
||||
s = re.sub(r"L$", "", str(s))
|
||||
s = re.sub(r"[\s\#\-\_\.\,]", "", s.lower())
|
||||
if not s:
|
||||
return None
|
||||
seed = long(s)
|
||||
seed = int(s)
|
||||
if 0 <= seed < 32000:
|
||||
return LCRandom31(seed)
|
||||
return PysolRandom(seed)
|
||||
|
@ -324,9 +320,9 @@ def random__str2long(s):
|
|||
return CUSTOM_BIT | MS_LONG_BIT
|
||||
m = _match_ms(s)
|
||||
if m:
|
||||
return (long(m.group(1)) | MS_LONG_BIT)
|
||||
return (int(m.group(1)) | MS_LONG_BIT)
|
||||
else:
|
||||
return long(s)
|
||||
return int(s)
|
||||
|
||||
|
||||
def random__long2str(l):
|
||||
|
|
Loading…
Add table
Reference in a new issue