Exemple #1
0
 def less_than_or_equal(self, w_object):
     assert isinstance(w_object, W_Array)
     if self.len() < w_object.len():
         return space.bool(True)
     elif self.len() == w_object.len():
         return self._less_than_or_equal(w_object)
     return space.bool(False)
Exemple #2
0
 def less_than(self, w_object):
     if self is w_object:
         return space.bool(False)
     assert isinstance(w_object, W_String)
     self.make_integral()
     w_object.make_integral()
     return space.bool(self.str_w() < w_object.str_w())
Exemple #3
0
def is_numeric(context, params):
    php_type = params[0].deref().get_type()
    if php_type == PHPTypes.w_int or php_type == PHPTypes.w_float:
        return space.bool(True)
    if php_type == PHPTypes.w_string:
        return params[0].deref().is_convertible_to_number_strict()
    return space.bool(False)
Exemple #4
0
 def more_than_or_equal(self, w_object):
     if self is w_object:
         return space.bool(True)
     assert isinstance(w_object, W_String)
     self.make_integral()
     w_object.make_integral()
     return space.bool(self.str_w() >= w_object.str_w())
Exemple #5
0
 def more_than(self, w_object):
     assert isinstance(w_object, W_Array)
     if self.len() > w_object.len():
         return space.bool(True)
     elif self.len() == w_object.len() and self.len() > 0:
         return self._more_than(w_object)
     return space.bool(False)
Exemple #6
0
    def ISSET(self, arguments_number):
        """
        For most variables we keep their names on stack
        Unfortunately, we cannot do for array elements, which are
          called like this: isset($a[4])
        To handle this situation, GET_INDEX/GET_INDEXES put on stack
          not a name, but a wrapped element: W_Cell(index, element)
          and we check it
        """
        #TODO: add __isset() support
        #TODO: add PHP 5.4 support
        stack = self.frame.stack
        for i in range(arguments_number):
            w_argument = stack.pop()
            # W_Cell is not inherited from W_Type
            if isinstance(w_argument, W_Type):
                var_name = w_argument.str_w()
                if (not var_name in self.frame.variables or
                        self.frame.variables[var_name].deref().is_null()):
                    stack.append(space.bool(False))
                    return
            else:
                arg_type = w_argument.deref().get_type()
                if (arg_type == PHPTypes.w_undefined or
                        arg_type == PHPTypes.w_null):
                    stack.append(space.bool(False))
                    return

        stack.append(space.bool(True))
Exemple #7
0
 def test_as_bool(self):
     false = space.bool(False)
     self.assertTrue(false.equal(self.array.as_bool()).is_true())
     true = space.bool(True)
     self.array.set(space.int(3), space.int(3))
     self.assertTrue(true.equal(self.array.as_bool()).is_true())
     self.array.set(space.int(0), space.int(3))
     self.assertTrue(true.equal(self.array.as_bool()).is_true())
     self.assertFalse(false.equal(self.array.as_bool()).is_true())
Exemple #8
0
 def _compare_elements(self, operation, w_object):
     for key, w_value in self.storage.iteritems():
         if key not in w_object.storage:
             return space.bool(False)
         w_result = getattr(space, operation)(w_value,
                                              w_object.storage[key])
         if not w_result.is_true():
             return space.bool(False)
     return space.bool(True)
Exemple #9
0
 def func(self, w_object):
     iterator = self.storage.iter()
     for i in range(self.len()):
         key, w_value = iterator.nextitem()
         if key not in w_object.storage:
             return space.bool(False)
         w_result = getattr(space, name)(w_value,
                                         w_object.storage[key])
         if not w_result.is_true():
             return space.bool(False)
     return space.bool(True)
Exemple #10
0
 def equal(self, w_object):
     if self is w_object:
         return space.bool(True)
     if self.strlen() != w_object.strlen():
         return space.bool(False)
     assert isinstance(w_object, W_String)
     if self.strategy is w_object.strategy:
         return space.bool(self.strategy.equal(self, w_object))
     self.make_integral()
     w_object.make_integral()
     return space.bool(self.str_w() == w_object.str_w())
Exemple #11
0
 def test_array_creation_int_branch(self):
     raw = [space.int(3), space.int(1),
            space.float(-1.2), space.int(2),
            space.bool(False), space.int(2),
            space.bool(True), space.int(3)]
     actual = space.array(raw)
     expected = {space.string('3'): space.int(1),
                 space.string('-1'): space.int(2),
                 space.string('0'): space.int(2), space.string('1'): space.int(3)}
     for key, value in expected.iteritems():
         self.assertTrue(actual.get(key).deref().equal(value).is_true())
Exemple #12
0
 def not_equal(self, w_object):
     assert isinstance(w_object, W_Array)
     if self.len() != w_object.len():
         return space.bool(True)
     else:
         iterator = self.storage.iter()
         for i in range(self.len()):
             key, w_value = iterator.nextitem()
             if key not in w_object.storage:
                 return space.bool(True)
             if space.not_equal(w_value, w_object.storage[key]).is_true():
                 return space.bool(True)
         return space.bool(False)
Exemple #13
0
 def test_get_type_conversion_other(self):
     array = space.array([space.int(0), space.int(1),
                          space.int(1), space.int(2),
                          space.int(-1), space.int(3)])
     value = array.get(space.float(1.5)).deref()
     self.assertTrue(value.equal(space.int(2)).is_true())
     value = array.get(space.bool(True)).deref()
     self.assertTrue(value.equal(space.int(2)).is_true())
     value = array.get(space.bool(False)).deref()
     self.assertTrue(value.equal(space.int(1)).is_true())
     with self.assertRaises(KeyError):
         value = array.get(space.null())
     with self.assertRaises(IllegalOffsetType):
         value = array.get(space.array())
Exemple #14
0
 def test_array_creation_one_key(self):
     raw = [space.int(1), space.int(1),
            space.string("1"), space.int(2),
            space.float(1.5), space.int(3),
            space.bool(True), space.int(4)]
     actual = space.array(raw)
     expected = {space.string('1'): space.int(4)}
     for key, value in expected.iteritems():
         self.assertTrue(actual.get(key).deref().equal(value).is_true())
Exemple #15
0
    def func(self, value):
        w_right = self.frame.stack.pop()
        w_left = self.frame.stack.pop()
        try:
            w_result = getattr(space, space_name)(w_left, w_right)
        except DivisionByZeroError:
            DivisionByZero(self.context).handle()
            w_result = space.bool(False)

        self.frame.stack.append(w_result)
Exemple #16
0
 def EMPTY_VAR(self, value):
     #TODO: array support
     #TODO: object support
     name = self.frame.pop_name()
     if name not in self.frame.variables:
         w_result = space.bool(True)
     else:
         w_value = self.frame.get_variable(name, self.context)
         w_result = space.is_empty(w_value)
     self.frame.stack.append(w_result)
Exemple #17
0
def print_r(context, params):
    #TODO: object
    #TODO: resource
    w_variable = params[0].deref()
    if len(params) > 1:
        to_variable = params[1].deref().is_true()
    else:
        to_variable = False

    w_result = _print_variable(w_variable)
    if not to_variable:
        context.print_output(w_result.str_w())
        return space.bool(True)

    return w_result
Exemple #18
0
    def interpret(self, context, frame):
        if not self.bytecode:
            try:
                self.bytecode = compiling.compile_source(self)
            except PieError as e:
                e.context = context
                e.handle()
                return space.bool(False)
        Interpreter(self.bytecode, context, frame).interpret()

        # TODO: as debug_trace function appear, a test for
        # this path should appear too
        if frame.stack:
            return frame.stack.pop()
        else:
            return space.null()
Exemple #19
0
 def as_bool(self):
     self.make_integral()
     if not self.is_true():
         return space.bool(False)
     return space.bool(True)
Exemple #20
0
 def not_equal(self, w_object):
     w_result = self.equal(w_object)
     return space.bool(not w_result.is_true())
Exemple #21
0
 def get_compiled_value(self):
     return space.bool(self.value)
Exemple #22
0
 def as_bool(self):
     return space.bool(self.is_true())
Exemple #23
0
 def as_bool(self):
     return space.bool(False)
Exemple #24
0
 def is_convertible_to_number_strict(self):
     try:
         self.as_number_strict()
         return space.bool(True)
     except NotConvertibleToNumber:
         return space.bool(False)
Exemple #25
0
 def less_than(self, object):
     return space.bool(False)
Exemple #26
0
 def more_than_or_equal(self, object):
     return space.bool(True)
Exemple #27
0
 def not_equal(self, object):
     return space.bool(False)
Exemple #28
0
 def more_than(self, object):
     return space.bool(False)
Exemple #29
0
 def equal(self, object):
     return space.bool(True)
Exemple #30
0
 def equal(self, w_object):
     assert isinstance(w_object, W_Array)
     if self.len() != w_object.len():
         return space.bool(False)
     return self._equal(w_object)