diff --git a/batavia/core/types/NotImplementedType.js b/batavia/core/types/NotImplementedType.js index fdc5ba970..29d6f0e4a 100644 --- a/batavia/core/types/NotImplementedType.js +++ b/batavia/core/types/NotImplementedType.js @@ -4,7 +4,7 @@ var PyObject = require('./Object') var basic_types = require('./Type') var exceptions = require('../exceptions') -var constants = require('../constants') +var version = require('../version') function NotImplementedType() { PyObject.call(this) @@ -43,36 +43,28 @@ NotImplementedType.prototype.__str__ = function() { **************************************************/ NotImplementedType.prototype.__lt__ = function(other) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: NotImplementedType() < ' + basic_types.type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'NotImplementedType' and '" + - basic_types.type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: NotImplementedType() < ' + basic_types.type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'NotImplementedType' and '" + + basic_types.type_name(other) + "'" + ) } } NotImplementedType.prototype.__le__ = function(other) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: NotImplementedType() <= ' + basic_types.type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'NotImplementedType' and '" + - basic_types.type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: NotImplementedType() <= ' + basic_types.type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'NotImplementedType' and '" + + basic_types.type_name(other) + "'" + ) } } @@ -85,36 +77,28 @@ NotImplementedType.prototype.__ne__ = function(other) { } NotImplementedType.prototype.__gt__ = function(other) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: NotImplementedType() > ' + basic_types.type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'NotImplementedType' and '" + - basic_types.type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: NotImplementedType() > ' + basic_types.type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'NotImplementedType' and '" + + basic_types.type_name(other) + "'" + ) } } NotImplementedType.prototype.__ge__ = function(other) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: NotImplementedType() >= ' + basic_types.type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'NotImplementedType' and '" + - basic_types.type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: NotImplementedType() >= ' + basic_types.type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'NotImplementedType' and '" + + basic_types.type_name(other) + "'" + ) } } diff --git a/batavia/modules/json/decoder.js b/batavia/modules/json/decoder.js index b5a18eed7..f1522f4d1 100644 --- a/batavia/modules/json/decoder.js +++ b/batavia/modules/json/decoder.js @@ -3,7 +3,7 @@ var core = require('../../core') var PyObject = core.Object var exceptions = core.exceptions var callables = core.callables -var constants = core.constants +var version = core.version var validateParams = require('./utils').validateParams function JSONDecoder() { @@ -64,7 +64,7 @@ JSONDecoder.prototype.decode = function(s) { try { ret = JSON.parse(s, reviver) } catch (e) { - if (constants.BATAVIA_MAGIC === constants.BATAVIA_MAGIC_34) { + if (version.earlier('3.5')) { throw new exceptions.ValueError.$pyclass(e.message) } else { throw new exceptions.JSONDecodeError.$pyclass(e.message) diff --git a/batavia/modules/json/encoder.js b/batavia/modules/json/encoder.js index 184a3b78c..46cad9975 100644 --- a/batavia/modules/json/encoder.js +++ b/batavia/modules/json/encoder.js @@ -2,7 +2,7 @@ var PyObject = require('../../core').Object var create_pyclass = require('../../core').create_pyclass var callables = require('../../core').callables var exceptions = require('../../core').exceptions -var constants = require('../../core').constants +var version = require('../../core').version var type_name = require('../../core').type_name var types = require('../../types') var builtins = require('../../builtins') @@ -178,18 +178,14 @@ var make_encode = function( } else if (default_) { ret = encode(callables.call_function(default_, [obj]), indent_level) } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - obj.toString() + ' is not JSON serializable' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "Object of type '" + type_name(obj) + "' is not JSON serializable" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + obj.toString() + ' is not JSON serializable' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "Object of type '" + type_name(obj) + "' is not JSON serializable" + ) } } diff --git a/batavia/types/Bytes.js b/batavia/types/Bytes.js index 95efcc6b5..cc8b6c0f1 100644 --- a/batavia/types/Bytes.js +++ b/batavia/types/Bytes.js @@ -1,6 +1,7 @@ var Buffer = require('buffer').Buffer var constants = require('../core').constants +var version = require('../core').version var PyObject = require('../core').Object var create_pyclass = require('../core').create_pyclass var exceptions = require('../core').exceptions @@ -89,19 +90,15 @@ Bytes.prototype.__lt__ = function(other) { if (types.isinstance(other, Bytes)) { return this.val < other.val } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: bytes() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'bytes' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: bytes() < ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'bytes' and '" + + type_name(other) + "'" + ) } } } @@ -112,19 +109,15 @@ Bytes.prototype.__le__ = function(other) { if (types.isinstance(other, Bytes)) { return this.val <= other.val } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: bytes() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'bytes' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: bytes() <= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'bytes' and '" + + type_name(other) + "'" + ) } } } @@ -153,19 +146,15 @@ Bytes.prototype.__gt__ = function(other) { if (types.isinstance(other, Bytes)) { return this.val > other.val } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: bytes() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'bytes' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: bytes() > ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'bytes' and '" + + type_name(other) + "'" + ) } } } @@ -176,19 +165,15 @@ Bytes.prototype.__ge__ = function(other) { if (types.isinstance(other, Bytes)) { return this.val >= other.val } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: bytes() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'bytes' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: bytes() >= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'bytes' and '" + + type_name(other) + "'" + ) } } } @@ -332,18 +317,14 @@ Bytes.prototype.__add__ = function(other) { types.Str, types.Tuple ])) { // does not concat with all these - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - "can't concat bytes to " + type_name(other) - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "can't concat " + type_name(other) + ' to bytes' - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + "can't concat bytes to " + type_name(other) + ) + } else { + throw new exceptions.TypeError.$pyclass( + "can't concat " + type_name(other) + ' to bytes' + ) } } else { throw new exceptions.NotImplementedError.$pyclass('Bytes.__add__ has not been implemented') diff --git a/batavia/types/Complex.js b/batavia/types/Complex.js index 9d69e9b5e..e4545c68d 100644 --- a/batavia/types/Complex.js +++ b/batavia/types/Complex.js @@ -1,6 +1,6 @@ var PyObject = require('../core').Object var exceptions = require('../core').exceptions -var constants = require('../core').constants +var version = require('../core').version var type_name = require('../core').type_name var create_pyclass = require('../core').create_pyclass @@ -61,36 +61,28 @@ function Complex(re, im) { this.imag = -this.imag } } else if (!types.isinstance(re, [types.Float, types.Int, types.Bool, types.Complex])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - throw new exceptions.TypeError.$pyclass( - "complex() argument must be a string, a bytes-like object or a number, not '" + - type_name(re) + "'" - ) - case constants.BATAVIA_MAGIC_353: - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "complex() first argument must be a string, a bytes-like object or a number, not '" + - type_name(re) + "'" - ) + if (version.later('3.5')) { + throw new exceptions.TypeError.$pyclass( + "complex() first argument must be a string, a bytes-like object or a number, not '" + + type_name(re) + "'" + ) + } else { + throw new exceptions.TypeError.$pyclass( + "complex() argument must be a string, a bytes-like object or a number, not '" + + type_name(re) + "'" + ) } } else if (!types.isinstance(im, [types.Float, types.Int, types.Bool, types.Complex])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - throw new exceptions.TypeError.$pyclass( - "complex() argument must be a string, a bytes-like object or a number, not '" + - type_name(im) + "'" - ) - case constants.BATAVIA_MAGIC_353: - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "complex() first argument must be a string, a bytes-like object or a number, not '" + - type_name(im) + "'" - ) + if (version.later('3.5')) { + throw new exceptions.TypeError.$pyclass( + "complex() first argument must be a string, a bytes-like object or a number, not '" + + type_name(im) + "'" + ) + } else { + throw new exceptions.TypeError.$pyclass( + "complex() argument must be a string, a bytes-like object or a number, not '" + + type_name(im) + "'" + ) } } else if (typeof re === 'number' && typeof im === 'number') { this.real = re @@ -150,34 +142,26 @@ Complex.prototype.__str__ = function() { **************************************************/ Complex.prototype.__lt__ = function(other) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: complex() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'complex' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: complex() < ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'complex' and '" + type_name(other) + "'" + ) } } Complex.prototype.__le__ = function(other) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: complex() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'complex' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: complex() <= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'complex' and '" + type_name(other) + "'" + ) } } @@ -208,34 +192,26 @@ Complex.prototype.__ne__ = function(other) { } Complex.prototype.__gt__ = function(other) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: complex() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'complex' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: complex() > ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'complex' and '" + type_name(other) + "'" + ) } } Complex.prototype.__ge__ = function(other) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: complex() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'complex' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: complex() >= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'complex' and '" + type_name(other) + "'" + ) } } diff --git a/batavia/types/Dict.js b/batavia/types/Dict.js index 82900d4d2..a547eaec5 100644 --- a/batavia/types/Dict.js +++ b/batavia/types/Dict.js @@ -1,6 +1,6 @@ var PyObject = require('../core').Object var exceptions = require('../core').exceptions -var constants = require('../core').constants +var version = require('../core').version var callables = require('../core').callables var type_name = require('../core').type_name var create_pyclass = require('../core').create_pyclass @@ -169,36 +169,28 @@ Dict.prototype.__lt__ = function(other) { var types = require('../types') if (other !== None) { if (types.isbataviainstance(other)) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'dict' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() < ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'dict' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() < other.valueOf() } } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() < NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'dict' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() < NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'dict' and 'NoneType'" + ) } } @@ -206,36 +198,28 @@ Dict.prototype.__le__ = function(other) { var types = require('../types') if (other !== None) { if (types.isbataviainstance(other)) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'dict' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() <= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'dict' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() <= other.valueOf() } } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() <= NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'dict' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() <= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'dict' and 'NoneType'" + ) } } @@ -275,36 +259,28 @@ Dict.prototype.__gt__ = function(other) { var types = require('../types') if (other !== None) { if (types.isbataviainstance(other)) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'dict' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() > ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'dict' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() > other.valueOf() } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() > NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'dict' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() > NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'dict' and 'NoneType'" + ) } } } @@ -313,36 +289,28 @@ Dict.prototype.__ge__ = function(other) { var types = require('../types') if (other !== None) { if (types.isbataviainstance(other)) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'dict' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() >= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'dict' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() >= other.valueOf() } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() >= NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'dict' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() >= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'dict' and 'NoneType'" + ) } } } diff --git a/batavia/types/Float.js b/batavia/types/Float.js index 22ca2c530..d481fcee3 100644 --- a/batavia/types/Float.js +++ b/batavia/types/Float.js @@ -1,6 +1,6 @@ var PyObject = require('../core').Object var exceptions = require('../core').exceptions -var constants = require('../core').constants +var version = require('../core').version var type_name = require('../core').type_name var create_pyclass = require('../core').create_pyclass var None = require('../core').None @@ -97,36 +97,28 @@ Float.prototype.__lt__ = function(other) { types.Range, types.Set, types.Slice, types.Bytes, types.Bytearray ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: float() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'float' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: float() < ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'float' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() < other.valueOf() } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: float() < NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'float' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: float() < NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'float' and 'NoneType'" + ) } } } @@ -140,36 +132,28 @@ Float.prototype.__le__ = function(other) { types.NoneType, types.Str, types.NotImplementedType, types.Range, types.Set, types.Slice ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: float() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'float' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: float() <= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'float' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() <= other.valueOf() } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: float() <= NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'float' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: float() <= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'float' and 'NoneType'" + ) } } } @@ -208,36 +192,28 @@ Float.prototype.__gt__ = function(other) { types.NoneType, types.Str, types.NotImplementedType, types.Range, types.Set, types.Slice ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: float() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'float' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: float() > ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'float' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() > other.valueOf() } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: float() > NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'float' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: float() > NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'float' and 'NoneType'" + ) } } } @@ -252,38 +228,29 @@ Float.prototype.__ge__ = function(other) { types.Range, types.Set, types.Slice, types.Bytes, types.Bytearray ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: float() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'float' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: float() >= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'float' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() >= other.valueOf() } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: float() >= NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'float' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: float() >= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'float' and 'NoneType'" + ) } - throw new exceptions.TypeError.$pyclass('unorderable types: float() >= NoneType()') } } diff --git a/batavia/types/FrozenSet.js b/batavia/types/FrozenSet.js index b23bae94c..138cc24de 100644 --- a/batavia/types/FrozenSet.js +++ b/batavia/types/FrozenSet.js @@ -1,7 +1,7 @@ var PyObject = require('../core').Object var create_pyclass = require('../core').create_pyclass var exceptions = require('../core').exceptions -var constants = require('../core').constants +var version = require('../core').version var callables = require('../core').callables var type_name = require('../core').type_name var SetIterator = require('./SetIterator') @@ -72,18 +72,14 @@ FrozenSet.prototype.__lt__ = function(other) { return new types.Bool(this.data.keys().length < other.data.keys().length) } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: frozenset() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'frozenset' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: frozenset() < ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'frozenset' and '" + type_name(other) + "'" + ) } } @@ -93,18 +89,14 @@ FrozenSet.prototype.__le__ = function(other) { if (types.isinstance(other, [types.Set, types.FrozenSet])) { return new types.Bool(this.data.keys().length <= other.data.keys().length) } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: frozenset() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'frozenset' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: frozenset() <= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'frozenset' and '" + type_name(other) + "'" + ) } } @@ -137,18 +129,14 @@ FrozenSet.prototype.__gt__ = function(other) { if (types.isinstance(other, [types.Set, types.FrozenSet])) { return new types.Bool(this.data.keys().length > other.data.keys().length) } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: frozenset() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'frozenset' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: frozenset() > ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'frozenset' and '" + type_name(other) + "'" + ) } } @@ -158,18 +146,14 @@ FrozenSet.prototype.__ge__ = function(other) { if (types.isinstance(other, [types.Set, types.FrozenSet])) { return new types.Bool(this.data.keys().length >= other.data.keys().length) } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: frozenset() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'frozenset' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: frozenset() >= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'frozenset' and '" + type_name(other) + "'" + ) } } diff --git a/batavia/types/Int.js b/batavia/types/Int.js index 039ba6e21..33ebcf7b0 100644 --- a/batavia/types/Int.js +++ b/batavia/types/Int.js @@ -2,7 +2,7 @@ var BigNumber = require('bignumber.js') var PyObject = require('../core').Object var exceptions = require('../core').exceptions -var constants = require('../core').constants +var version = require('../core').version var type_name = require('../core').type_name var create_pyclass = require('../core').create_pyclass var None = require('../core').None @@ -106,34 +106,26 @@ Int.prototype.__lt__ = function(other) { } else if (types.isinstance(other, types.Float)) { return this.val.lt(other.valueOf()) } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: int() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'int' and '" + - type_name(other) + "'" - ) - } - } - } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: + if (version.earlier('3.6')) { throw new exceptions.TypeError.$pyclass( - 'unorderable types: int() < NoneType()' + 'unorderable types: int() < ' + type_name(other) + '()' ) - case constants.BATAVIA_MAGIC_36: + } else { throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'int' and 'NoneType'" + "'<' not supported between instances of 'int' and '" + + type_name(other) + "'" ) + } + } + } else { + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: int() < NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'int' and 'NoneType'" + ) } } } @@ -153,34 +145,26 @@ Int.prototype.__le__ = function(other) { } else if (types.isinstance(other, types.Float)) { return this.val.lte(other.valueOf()) } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: int() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'int' and '" + - type_name(other) + "'" - ) - } - } - } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: + if (version.earlier('3.6')) { throw new exceptions.TypeError.$pyclass( - 'unorderable types: int() <= NoneType()' + 'unorderable types: int() <= ' + type_name(other) + '()' ) - case constants.BATAVIA_MAGIC_36: + } else { throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'int' and 'NoneType'" + "'<=' not supported between instances of 'int' and '" + + type_name(other) + "'" ) + } + } + } else { + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: int() <= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'int' and 'NoneType'" + ) } } } @@ -220,34 +204,26 @@ Int.prototype.__gt__ = function(other) { } else if (types.isinstance(other, types.Float)) { return this.val.gt(other.valueOf()) } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: int() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'int' and '" + - type_name(other) + "'" - ) - } - } - } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: + if (version.earlier('3.6')) { throw new exceptions.TypeError.$pyclass( - 'unorderable types: int() > NoneType()' + 'unorderable types: int() > ' + type_name(other) + '()' ) - case constants.BATAVIA_MAGIC_36: + } else { throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'int' and 'NoneType'" + "'>' not supported between instances of 'int' and '" + + type_name(other) + "'" ) + } + } + } else { + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: int() > NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'int' and 'NoneType'" + ) } } } @@ -267,34 +243,26 @@ Int.prototype.__ge__ = function(other) { } else if (types.isinstance(other, types.Float)) { return this.val.gte(other.valueOf()) } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: int() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'int' and '" + - type_name(other) + "'" - ) - } - } - } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: + if (version.earlier('3.6')) { throw new exceptions.TypeError.$pyclass( - 'unorderable types: int() >= NoneType()' + 'unorderable types: int() >= ' + type_name(other) + '()' ) - case constants.BATAVIA_MAGIC_36: + } else { throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'int' and 'NoneType'" + "'>=' not supported between instances of 'int' and '" + + type_name(other) + "'" ) + } + } + } else { + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: int() >= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'int' and 'NoneType'" + ) } } } diff --git a/batavia/types/JSDict.js b/batavia/types/JSDict.js index a3f6b1b6b..bc3ac7655 100644 --- a/batavia/types/JSDict.js +++ b/batavia/types/JSDict.js @@ -1,5 +1,5 @@ var exceptions = require('../core').exceptions -var constants = require('../core').constants +var version = require('../core').version var type_name = require('../core').type_name var None = require('../core').None @@ -66,35 +66,27 @@ JSDict.prototype.__lt__ = function(other) { types.Int, types.JSDict, types.List, types.NoneType, types.Str, types.Tuple ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'dict' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() < ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'dict' and '" + type_name(other) + "'" + ) } } else { return this.valueOf() < other.valueOf() } } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() < NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'dict' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() < NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'dict' and 'NoneType'" + ) } } @@ -107,35 +99,27 @@ JSDict.prototype.__le__ = function(other) { types.Int, types.JSDict, types.List, types.NoneType, types.Str, types.Tuple ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'dict' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() <= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'dict' and '" + type_name(other) + "'" + ) } } else { return this.valueOf() <= other.valueOf() } } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() <= NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'dict' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() <= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'dict' and 'NoneType'" + ) } } @@ -157,35 +141,27 @@ JSDict.prototype.__gt__ = function(other) { types.NoneType, types.Set, types.Str, types.Tuple ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'dict' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() > ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'dict' and '" + type_name(other) + "'" + ) } } else { return this.valueOf() > other.valueOf() } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() > NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'dict' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() > NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'dict' and 'NoneType'" + ) } } } @@ -199,35 +175,27 @@ JSDict.prototype.__ge__ = function(other) { types.Int, types.JSDict, types.List, types.NoneType, types.Str, types.Tuple ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'dict' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() >= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'dict' and '" + type_name(other) + "'" + ) } } else { return this.valueOf() >= other.valueOf() } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: dict() >= NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'dict' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: dict() >= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'dict' and 'NoneType'" + ) } } } diff --git a/batavia/types/List.js b/batavia/types/List.js index cb408c876..abc1cb990 100644 --- a/batavia/types/List.js +++ b/batavia/types/List.js @@ -1,4 +1,4 @@ -var constants = require('../core').constants +var version = require('../core').version var exceptions = require('../core').exceptions var callables = require('../core').callables var type_name = require('../core').type_name @@ -84,19 +84,15 @@ List.prototype.__lt__ = function(other) { var types = require('../types') if (types.isinstance(other, [types.Bytes, types.Bytearray])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'list' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: list() < ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'list' and '" + + type_name(other) + "'" + ) } } @@ -119,34 +115,26 @@ List.prototype.__lt__ = function(other) { // got through loop and all values were equal. Determine by comparing length return this.length < other.length } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'list' and '" + - type_name(other) + "'" - ) - } - } - } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: + if (version.earlier('3.6')) { throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() < NoneType()' + 'unorderable types: list() < ' + type_name(other) + '()' ) - case constants.BATAVIA_MAGIC_36: + } else { throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'list' and 'NoneType'" + "'<' not supported between instances of 'list' and '" + + type_name(other) + "'" ) + } + } + } else { + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: list() < NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'list' and 'NoneType'" + ) } } } @@ -155,19 +143,15 @@ List.prototype.__le__ = function(other) { var types = require('../types') if (types.isinstance(other, [types.Bytes, types.Bytearray])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'list' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: list() <= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'list' and '" + + type_name(other) + "'" + ) } } @@ -190,34 +174,26 @@ List.prototype.__le__ = function(other) { // got through loop and all values were equal. Determine by comparing length return this.length <= other.length } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'list' and '" + - type_name(other) + "'" - ) - } - } - } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: + if (version.earlier('3.6')) { throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() <= NoneType()' + 'unorderable types: list() <= ' + type_name(other) + '()' ) - case constants.BATAVIA_MAGIC_36: + } else { throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'list' and 'NoneType'" + "'<=' not supported between instances of 'list' and '" + + type_name(other) + "'" ) + } + } + } else { + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: list() <= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'list' and 'NoneType'" + ) } } } @@ -249,19 +225,15 @@ List.prototype.__gt__ = function(other) { var types = require('../types') if (types.isinstance(other, [types.Bytes, types.Bytearray])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'list' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: list() > ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'list' and '" + + type_name(other) + "'" + ) } } @@ -284,34 +256,26 @@ List.prototype.__gt__ = function(other) { // got through loop and all values were equal. Determine by comparing length return this.length > other.length } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'list' and '" + - type_name(other) + "'" - ) - } - } - } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: + if (version.earlier('3.6')) { throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() > NoneType()' + 'unorderable types: list() > ' + type_name(other) + '()' ) - case constants.BATAVIA_MAGIC_36: + } else { throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'list' and 'NoneType'" + "'>' not supported between instances of 'list' and '" + + type_name(other) + "'" ) + } + } + } else { + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: list() > NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'list' and 'NoneType'" + ) } } } @@ -320,19 +284,15 @@ List.prototype.__ge__ = function(other) { var types = require('../types') if (types.isinstance(other, [types.Bytes, types.Bytearray])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'list' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: list() >= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'list' and '" + + type_name(other) + "'" + ) } } @@ -355,34 +315,26 @@ List.prototype.__ge__ = function(other) { // got through loop and all values were equal. Determine by comparing length return this.length >= other.length } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'list' and '" + - type_name(other) + "'" - ) - } - } - } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: + if (version.earlier('3.6')) { throw new exceptions.TypeError.$pyclass( - 'unorderable types: list() >= NoneType()' + 'unorderable types: list() >= ' + type_name(other) + '()' ) - case constants.BATAVIA_MAGIC_36: + } else { throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'list' and 'NoneType'" + "'>=' not supported between instances of 'list' and '" + + type_name(other) + "'" ) + } + } + } else { + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: list() >= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'list' and 'NoneType'" + ) } } } @@ -603,7 +555,7 @@ List.prototype.__getitem__ = function(index) { } } else { var msg = 'list indices must be integers or slices, not ' - if (constants.BATAVIA_MAGIC === constants.BATAVIA_MAGIC_34) { + if (!version.later('3.4')) { msg = 'list indices must be integers, not ' } throw new exceptions.TypeError.$pyclass(msg + type_name(index)) diff --git a/batavia/types/Set.js b/batavia/types/Set.js index 91d7bc0cc..d4b543da4 100644 --- a/batavia/types/Set.js +++ b/batavia/types/Set.js @@ -1,7 +1,7 @@ /* eslint-disable no-extend-native */ var PyObject = require('../core').Object var exceptions = require('../core').exceptions -var constants = require('../core').constants +var version = require('../core').version var callables = require('../core').callables var type_name = require('../core').type_name var create_pyclass = require('../core').create_pyclass @@ -70,18 +70,14 @@ Set.prototype.__lt__ = function(other) { if (types.isinstance(other, [types.Set, types.FrozenSet])) { return new types.Bool(this.data.keys().length < other.data.keys().length) } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: set() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'set' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: set() < ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'set' and '" + type_name(other) + "'" + ) } } @@ -91,18 +87,14 @@ Set.prototype.__le__ = function(other) { if (types.isinstance(other, [types.Set, types.FrozenSet])) { return new types.Bool(this.data.keys().length <= other.data.keys().length) } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: set() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'set' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: set() <= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'set' and '" + type_name(other) + "'" + ) } } @@ -135,18 +127,14 @@ Set.prototype.__gt__ = function(other) { if (types.isinstance(other, [types.Set, types.FrozenSet])) { return new types.Bool(this.data.keys().length > other.data.keys().length) } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: set() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'set' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: set() > ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'set' and '" + type_name(other) + "'" + ) } } @@ -156,18 +144,14 @@ Set.prototype.__ge__ = function(other) { if (types.isinstance(other, [types.Set, types.FrozenSet])) { return new types.Bool(this.data.keys().length >= other.data.keys().length) } - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: set() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'set' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: set() >= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'set' and '" + type_name(other) + "'" + ) } } diff --git a/batavia/types/Str.js b/batavia/types/Str.js index e5d1e36db..27e7f1578 100644 --- a/batavia/types/Str.js +++ b/batavia/types/Str.js @@ -2,6 +2,7 @@ var Buffer = require('buffer').Buffer var PyObject = require('../core').Object var constants = require('../core').constants +var version = require('../core').version var exceptions = require('../core').exceptions var type_name = require('../core').type_name var create_pyclass = require('../core').create_pyclass @@ -90,36 +91,28 @@ Str.prototype.__lt__ = function(other) { types.Range, types.Set, types.Slice, types.FrozenSet ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: str() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'str' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: str() < ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'str' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() < other } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: str() < NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'str' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: str() < NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'str' and 'NoneType'" + ) } } } @@ -135,36 +128,28 @@ Str.prototype.__le__ = function(other) { types.Type, types.Complex, types.NotImplementedType, types.Range, types.Slice, types.FrozenSet ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: str() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'str' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: str() <= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'str' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() <= other } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: str() <= NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'str' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: str() <= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'str' and 'NoneType'" + ) } } } @@ -216,36 +201,28 @@ Str.prototype.__gt__ = function(other) { types.NotImplementedType, types.Range, types.Slice, types.FrozenSet ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: str() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'str' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: str() > ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'str' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() > other } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: str() > NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'str' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: str() > NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'str' and 'NoneType'" + ) } } } @@ -262,36 +239,28 @@ Str.prototype.__ge__ = function(other) { types.Range, types.Slice, types.FrozenSet ])) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: str() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'str' and '" + - type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: str() >= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'str' and '" + + type_name(other) + "'" + ) } } else { return this.valueOf() >= other } } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: str() >= NoneType()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'str' and 'NoneType'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: str() >= NoneType()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'str' and 'NoneType'" + ) } } } @@ -388,16 +357,12 @@ Str.prototype.__add__ = function(other) { if (types.isinstance(other, Str)) { return this.valueOf() + other.valueOf() } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - "Can't convert '" + type_name(other) + "' object to str implicitly" - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass('must be str, not ' + type_name(other)) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + "Can't convert '" + type_name(other) + "' object to str implicitly" + ) + } else { + throw new exceptions.TypeError.$pyclass('must be str, not ' + type_name(other)) } } } @@ -560,16 +525,12 @@ Str.prototype.__iadd__ = function(other) { if (types.isinstance(other, Str)) { return this.valueOf() + other.valueOf() } else { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - "Can't convert '" + type_name(other) + "' object to str implicitly" - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass('must be str, not ' + type_name(other)) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + "Can't convert '" + type_name(other) + "' object to str implicitly" + ) + } else { + throw new exceptions.TypeError.$pyclass('must be str, not ' + type_name(other)) } } } diff --git a/batavia/types/StrUtils.js b/batavia/types/StrUtils.js index 0a6bc6aed..d65a3c3c9 100644 --- a/batavia/types/StrUtils.js +++ b/batavia/types/StrUtils.js @@ -1,5 +1,5 @@ var exceptions = require('../core').exceptions -var constants = require('../core').constants +var version = require('../core').version var type_name = require('../core').type_name var BigNumber = require('bignumber.js').BigNumber @@ -1179,18 +1179,14 @@ function _new_subsitute(str, args, kwargs) { } // things that aren't allowed with strings: - // grouping - // sign - // alternate form + // grouping + // sign + // alternate form if (this.grouping === ',') { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.ValueError.$pyclass("Cannot specify ',' with 's'.") - case constants.BATAVIA_MAGIC_36: - throw new exceptions.ValueError.$pyclass("Cannot specify ',' or '_' with 's'.") + if (version.earlier('3.6')) { + throw new exceptions.ValueError.$pyclass("Cannot specify ',' with 's'.") + } else { + throw new exceptions.ValueError.$pyclass("Cannot specify ',' or '_' with 's'.") } } diff --git a/batavia/types/Tuple.js b/batavia/types/Tuple.js index 3a89b89d6..f55f9c7b8 100644 --- a/batavia/types/Tuple.js +++ b/batavia/types/Tuple.js @@ -1,4 +1,4 @@ -var constants = require('../core').constants +var version = require('../core').version var PyObject = require('../core').Object var exceptions = require('../core').exceptions var callables = require('../core').callables @@ -87,18 +87,14 @@ Tuple.prototype.__lt__ = function(other) { var types = require('../types') if (!types.isinstance(other, types.Tuple)) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: tuple() < ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<' not supported between instances of 'tuple' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: tuple() < ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<' not supported between instances of 'tuple' and '" + type_name(other) + "'" + ) } } if (this.length === 0 && other.length > 0) { @@ -123,18 +119,14 @@ Tuple.prototype.__le__ = function(other) { var types = require('../types') if (!types.isinstance(other, types.Tuple)) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: tuple() <= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'<=' not supported between instances of 'tuple' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: tuple() <= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'<=' not supported between instances of 'tuple' and '" + type_name(other) + "'" + ) } } for (var i = 0; i < this.length; i++) { @@ -177,18 +169,14 @@ Tuple.prototype.__gt__ = function(other) { var types = require('../types') if (!types.isinstance(other, types.Tuple)) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: tuple() > ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>' not supported between instances of 'tuple' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: tuple() > ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>' not supported between instances of 'tuple' and '" + type_name(other) + "'" + ) } } if (this.length === 0 && other.length > 0) { @@ -214,18 +202,14 @@ Tuple.prototype.__ge__ = function(other) { var types = require('../types') if (!types.isinstance(other, types.Tuple)) { - switch (constants.BATAVIA_MAGIC) { - case constants.BATAVIA_MAGIC_34: - case constants.BATAVIA_MAGIC_35a0: - case constants.BATAVIA_MAGIC_35: - case constants.BATAVIA_MAGIC_353: - throw new exceptions.TypeError.$pyclass( - 'unorderable types: tuple() >= ' + type_name(other) + '()' - ) - case constants.BATAVIA_MAGIC_36: - throw new exceptions.TypeError.$pyclass( - "'>=' not supported between instances of 'tuple' and '" + type_name(other) + "'" - ) + if (version.earlier('3.6')) { + throw new exceptions.TypeError.$pyclass( + 'unorderable types: tuple() >= ' + type_name(other) + '()' + ) + } else { + throw new exceptions.TypeError.$pyclass( + "'>=' not supported between instances of 'tuple' and '" + type_name(other) + "'" + ) } } for (var i = 0; i < this.length; i++) { @@ -453,7 +437,7 @@ Tuple.prototype.__getitem__ = function(index) { return new Tuple(steppedArray) } else { var msg = 'tuple indices must be integers or slices, not ' - if (constants.BATAVIA_MAGIC === constants.BATAVIA_MAGIC_34) { + if (!version.later('3.4')) { msg = 'tuple indices must be integers, not ' } throw new exceptions.TypeError.$pyclass(msg + type_name(index))