-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathPyDictProxy.java
More file actions
159 lines (128 loc) · 3.83 KB
/
Copy pathPyDictProxy.java
File metadata and controls
159 lines (128 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* Copyright (c) 2008 Jython Developers */
package org.python.core;
import org.python.expose.ExposedMethod;
import org.python.expose.ExposedNew;
import org.python.expose.ExposedType;
import org.python.expose.MethodType;
/**
* Readonly proxy for dictionaries (actually any mapping).
*
*/
@ExposedType(name = "mappingproxy", isBaseType = false)
public class PyDictProxy extends PyObject implements Traverseproc {
/** The dict proxied to. */
PyObject dict;
public PyDictProxy(PyObject dict) {
super();
this.dict = dict;
}
@ExposedNew
static PyObject mappingproxy_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args,
String[] keywords) {
ArgParser ap = new ArgParser("mappingproxy", args, keywords, new String[] {"object"}, 0);
PyObject d = ap.getPyObject(0);
return new PyDictProxy(d);
}
@Override
public PyObject __iter__() {
return dict.__iter__();
}
@Override
public PyObject __finditem__(PyObject key) {
return dict.__finditem__(key);
}
@Override
public int __len__() {
return dict.__len__();
}
@ExposedMethod
public PyObject mappingproxy___getitem__(PyObject key) {
return dict.__getitem__(key);
}
@ExposedMethod
public boolean mappingproxy___contains__(PyObject value) {
return dict.__contains__(value);
}
@ExposedMethod
public boolean mappingproxy_has_key(PyObject key) {
return dict.__contains__(key);
}
@ExposedMethod(defaults = "Py.None")
public PyObject mappingproxy_get(PyObject key, PyObject default_object) {
return dict.invoke("get", key, default_object);
}
@ExposedMethod
public PyObject mappingproxy_keys() {
return dict.invoke("keys");
}
@ExposedMethod
public PyObject mappingproxy_values() {
return dict.invoke("values");
}
@ExposedMethod
public PyObject mappingproxy_items() {
return dict.invoke("items");
}
@ExposedMethod
public PyObject mappingproxy_iterkeys() {
return dict.invoke("iterkeys");
}
@ExposedMethod
public PyObject mappingproxy_itervalues() {
return dict.invoke("itervalues");
}
@ExposedMethod
public PyObject mappingproxy_iteritems() {
return dict.invoke("iteritems");
}
@ExposedMethod
public PyObject mappingproxy_copy() {
return dict.invoke("copy");
}
@ExposedMethod(type = MethodType.BINARY)
public PyObject mappingproxy___lt__(PyObject other) {
return dict.__lt__(other);
}
@ExposedMethod(type = MethodType.BINARY)
public PyObject mappingproxy___le__(PyObject other) {
return dict.__le__(other);
}
@ExposedMethod(type = MethodType.BINARY)
public PyObject mappingproxy___eq__(PyObject other) {
return dict.__eq__(other);
}
@ExposedMethod(type = MethodType.BINARY)
public PyObject mappingproxy___ne__(PyObject other) {
return dict.__ne__(other);
}
@ExposedMethod(type = MethodType.BINARY)
public PyObject mappingproxy___gt__(PyObject other) {
return dict.__gt__(other);
}
@ExposedMethod(type = MethodType.BINARY)
public PyObject mappingproxy___ge__(PyObject other) {
return dict.__ge__(other);
}
@Override
@ExposedMethod
public PyUnicode __str__() {
return dict.__str__();
}
@Override
public boolean isMappingType() {
return true;
}
@Override
public boolean isSequenceType() {
return false;
}
/* Traverseproc implementation */
@Override
public int traverse(Visitproc visit, Object arg) {
return dict == null ? 0 : visit.visit(dict, arg);
}
@Override
public boolean refersDirectlyTo(PyObject ob) {
return ob != null && ob == dict;
}
}