Example #1
0
 def pop_keyerror(n):
     o = OrderedDict()
     o[3] = 4
     try:
         return o.pop(n)
     except KeyError:
         return 500
Example #2
0
 def delitem(n):
     o = OrderedDict()
     o[2] = 3
     o[3] = 4
     del o[n]
     vals = o.values()
     return vals[0] * 10 + len(vals)
Example #3
0
 def delitem(n):
     o = OrderedDict()
     o[2] = 3
     o[3] = 4
     del o[n]
     vals = o.values()
     return vals[0] * 10 + len(vals)
Example #4
0
 def pop_keyerror(n):
     o = OrderedDict()
     o[3] = 4
     try:
         return o.pop(n)
     except KeyError:
         return 500
Example #5
0
class W_HashObject(W_Object):
    classdef = ClassDef("Hash", W_Object.classdef)

    def __init__(self, space):
        W_Object.__init__(self, space)
        self.contents = OrderedDict(space.eq_w, space.hash_w)

    @classdef.singleton_method("allocate")
    def method_allocate(self, space):
        return W_HashObject(space)

    @classdef.method("[]")
    def method_subscript(self, space, w_key):
        return self.contents.get(w_key, space.w_nil)

    @classdef.method("[]=")
    def method_subscript_assign(self, w_key, w_value):
        self.contents[w_key] = w_value
        return w_value

    @classdef.method("delete")
    def method_delete(self, space, w_key):
        return self.contents.pop(w_key, space.w_nil)

    @classdef.method("keys")
    def method_keys(self, space):
        return space.newarray(self.contents.keys())

    @classdef.method("values")
    def method_values(self, space):
        return space.newarray(self.contents.values())

    @classdef.method("to_hash")
    def method_to_hash(self, space):
        return self

    classdef.app_method("""
    def each
        iter = Topaz::HashIterator.new(self)
        while true
            begin
                key, value = iter.next()
            rescue StopIteration
                return
            end
            yield key, value
        end
    end
    alias each_pair each
    """)

    @classdef.method("key?")
    @classdef.method("has_key?")
    @classdef.method("member?")
    @classdef.method("include?")
    def method_includep(self, space, w_key):
        return space.newbool(w_key in self.contents)
Example #6
0
 def merge_dicts(n):
     if n:
         o = OrderedDict()
         o[5] = 10
     else:
         o = OrderedDict()
         o[2] = 20
     o[3] = 30
     return o[3]
Example #7
0
 def iteritems(n):
     o = OrderedDict()
     o[0] = 10
     o[2] = 15
     o[3] = 12
     r = []
     for k, v in o.iteritems():
         r.append((k, v))
     p = r[n]
     return p[0] * 100 + p[1]
Example #8
0
 def iteritems(n):
     o = OrderedDict()
     o[0] = 10
     o[2] = 15
     o[3] = 12
     r = []
     for k, v in o.iteritems():
         r.append((k, v))
     p = r[n]
     return p[0] * 100 + p[1]
Example #9
0
 def get_set_object(n):
     x = Simple(n)
     o = OrderedDict()
     o[x] = x
     return o[x].x
Example #10
0
 def create():
     OrderedDict()
     return 0
Example #11
0
 def simple_get_set():
     o = OrderedDict()
     o["a"] = 2
     return o["a"]
Example #12
0
 def pop_default(n, d):
     o = OrderedDict()
     o[1] = 12
     o[2] = 3
     return (o.pop(n, d) * 10) + len(o)
Example #13
0
 def get(n):
     o = OrderedDict()
     o[4] = 3
     return o.get(n, 123)
Example #14
0
 def custom_eq_hash(n):
     o = OrderedDict(Simple.eq, Simple.hash)
     o[Simple(n)] = 23
     return o[Simple(n)]
Example #15
0
 def pop(n):
     o = OrderedDict()
     o[1] = 12
     o[2] = 3
     return (o.pop(n) * 10) + len(o)
Example #16
0
 def values(n):
     o = OrderedDict()
     o[4] = 1
     o[5] = 2
     o[4] = 3
     return o.values()[n]
Example #17
0
 def iteritems_next_method(n):
     o = OrderedDict()
     o[n] = 5
     it = o.iteritems()
     return it.next()[1]
Example #18
0
 def keys_object(n):
     o = OrderedDict()
     o[Simple(1)] = None
     o[Simple(2)] = None
     o[Simple(3)] = None
     return o.keys()[n].x
Example #19
0
 def iteritems_next_method(n):
     o = OrderedDict()
     o[n] = 5
     it = o.iteritems()
     return it.next()[1]
Example #20
0
 def values(n):
     o = OrderedDict()
     o[4] = 1
     o[5] = 2
     o[4] = 3
     return o.values()[n]
Example #21
0
 def keys(n):
     o = OrderedDict()
     o[4] = 1
     o[5] = 2
     o[4] = 2
     return o.keys()[n]
Example #22
0
 def grow(n):
     o = OrderedDict()
     for i in xrange(n):
         o[i] = -20
     return o[3]
Example #23
0
 def keys_object(n):
     o = OrderedDict()
     o[Simple(1)] = None
     o[Simple(2)] = None
     o[Simple(3)] = None
     return o.keys()[n].x
Example #24
0
 def contains(n):
     o = OrderedDict()
     o[4] = 5
     return n in o
Example #25
0
 def len(n):
     o = OrderedDict()
     for i in xrange(n):
         o[i] = i
     return len(o)
Example #26
0
 def pop(n):
     o = OrderedDict()
     o[1] = 12
     o[2] = 3
     return (o.pop(n) * 10) + len(o)
Example #27
0
 def get(n):
     o = OrderedDict()
     o[4] = 3
     return o.get(n, 123)
Example #28
0
 def pop_default(n, d):
     o = OrderedDict()
     o[1] = 12
     o[2] = 3
     return (o.pop(n, d) * 10) + len(o)
Example #29
0
 def __init__(self, space):
     W_Object.__init__(self, space)
     self.contents = OrderedDict(space.eq_w, space.hash_w)
Example #30
0
 def keys(n):
     o = OrderedDict()
     o[4] = 1
     o[5] = 2
     o[4] = 2
     return o.keys()[n]