WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.2% of users enabled 2FA.

Commit e0d567af authored by Stefan Marr's avatar Stefan Marr
Browse files

Use `in` instead of has_key()


Signed-off-by: default avatarStefan Marr <git@stefan-marr.de>
parent a3d1e509
from som.primitives.primitives import Primitives
from som.vmobjects.primitive import Primitive
from som.vmobjects.integer import integer_value_fits
import math
def _asString(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_string(str(rcvr.get_embedded_biginteger())))
def _sqrt(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_double(
math.sqrt(rcvr.get_embedded_biginteger())))
def _plus(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() + right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(interpreter.get_universe().new_integer(result))
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _minus(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() - right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(interpreter.get_universe().new_integer(result))
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _mult(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() * right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(interpreter.get_universe().new_integer(result))
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _div(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() / right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(interpreter.get_universe().new_integer(result))
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _mod(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
frame.push(interpreter.get_universe().new_biginteger(left.get_embedded_biginteger() % right_obj.get_embedded_value()))
def _and(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
frame.push(interpreter.get_universe().new_biginteger(left.get_embedded_biginteger() & right_obj.get_embedded_value()))
def _equals(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
if left.get_embedded_biginteger() == right_obj.get_embedded_value():
frame.push(interpreter.get_universe().trueObject)
else:
frame.push(interpreter.get_universe().falseObject)
def _lessThan(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
if left.get_embedded_biginteger() < right_obj.get_embedded_value():
frame.push(interpreter.get_universe().trueObject)
else:
frame.push(interpreter.get_universe().falseObject)
class BigIntegerPrimitives(Primitives):
def install_primitives(self):
self._install_instance_primitive(Primitive("asString", self._universe, _asString))
self._install_instance_primitive(Primitive("sqrt", self._universe, _sqrt))
self._install_instance_primitive(Primitive("+", self._universe, _plus))
self._install_instance_primitive(Primitive("-", self._universe, _minus))
self._install_instance_primitive(Primitive("*", self._universe, _mult))
self._install_instance_primitive(Primitive("/", self._universe, _div))
self._install_instance_primitive(Primitive("%", self._universe, _mod))
self._install_instance_primitive(Primitive("&", self._universe, _and))
self._install_instance_primitive(Primitive("=", self._universe, _equals))
self._install_instance_primitive(Primitive("<", self._universe, _lessThan))
......@@ -38,6 +38,6 @@ class SomTest(unittest.TestCase):
self.assertEquals(0, u.last_exit_code())
import sys
if sys.modules.has_key('pytest'):
if 'pytest' in sys.modules:
# hack to make pytest not to collect the unexpanded test method
delattr(SomTest, "test_som_test")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment