1 """
2 ::
3 /*
4 * $Id$
5 *
6 * Copyright 2008 Glencoe Software, Inc. All rights reserved.
7 * Use is subject to license terms supplied in LICENSE.txt
8 *
9 */
10 """
11
12 """
13 Module which is responsible for creating rtypes from static
14 factory methods. Where possible, factory methods return cached values
15 (the fly-weight pattern) such that <code>rbool(true) == rbool(true)</code>
16 might hold true.
17
18 This module is meant to be kept in sync with the abstract Java class
19 omero.rtypes as well as the omero/rtypes.{h,cpp} files.
20 """
21
22 import omero, Ice
23 import omero_RTypes_ice
24 import omero_Scripts_ice
25
27 """
28 If None or an RType, return the argument itself. Otherwise,
29 attempts to dispatch to the other omero.rtypes.* static methods
30 to create a proper {@link RType} subclass by checking the type
31 of the input. If no conversion is found, a {@link ClientError} is
32 thrown.
33
34 Note: unlike the statically typed languages, the rtype implementation
35 in Python is somewhat limited by the lack of types (float v. double)
36 All float-like values will produce an omero.RFloat subclass. Similar
37 problems may arise with rlong and rint
38 """
39 if val == None:
40 return None
41 elif isinstance(val, omero.RType):
42 return val
43 elif isinstance(val,bool):
44 return rbool(val)
45 elif isinstance(val, int):
46 return rint(val)
47 elif isinstance(val, long):
48 return rlong(val)
49 elif isinstance(val, float):
50 return rfloat(val)
51 elif isinstance(val, str):
52 return rstring(val)
53 elif isinstance(val, omero.model.IObject):
54 return robject(val)
55 elif isinstance(val, omero.Internal):
56 return rinternal(val)
57 elif isinstance(val, list):
58 return rlist(val)
59 elif isinstance(val, set):
60 return rset(val)
61 elif isinstance(val, dict):
62 return rmap(val)
63 else:
64 raise omero.ClientError("Cannot handle conversion from: %s" % type(val))
65
66
67
68
70 """
71 Returns the argument itself if None or an instance of RBool.
72 Otherwise, checks the value for"trueness" and returns either
73 rtrue or rfalse.
74 """
75 if val == None or isinstance(val, omero.RBool):
76 return val
77 elif val:
78 return rtrue
79 else:
80 return rfalse
81
83 """
84 Returns the argument itself if None or an instance of RDouble.
85 Otherwise, assigns a coerced float to the value of a new RDouble.
86 """
87 if val == None or isinstance(val, omero.RDouble):
88 return val
89 return RDoubleI(float(val))
90
92 """
93 Returns the argument itself if None or an instance of RFloat.
94 Otherwise, assigns a coerced float to the value of a new RFloat.
95 """
96 if val == None or isinstance(val, omero.RFloat):
97 return val
98 return RFloatI(float(val))
99
101 """
102 Returns the argument itself if None or an instance of RInt.
103 If the argument is 0, rint0 is returned.
104 Otherwise, assigns a coerced int to the value of a new RInt
105 """
106 if val == None or isinstance(val, omero.RInt):
107 return val
108 elif val == 0:
109 return rint0
110 return RIntI(int(val))
111
113 """
114 Returns the argument itself if None or an instance of RLong.
115 If the argument is 0, rlong 0 is returned.
116 Otherwise, assigns a coerced int to the value of a new RLong
117 """
118 if val == None or isinstance(val, omero.RLong):
119 return val
120 elif val == 0:
121 return rlong0
122 return RLongI(long(val))
123
125 """
126 Returns the argument itself if None or an instance of RTime.
127 Otherwise, assigns a coerced long to the value of a new RTime
128 """
129 if val == None or isinstance(val, omero.RTime):
130 return val
131 return RTimeI(long(val))
132
133
134
135
137 """
138 If argument is None, returns rnullinternal.
139 If an RInternal, returns the argument itself.
140 Otherwise creates a new RInternal.
141 """
142 if val == None:
143 return rnullinternal
144 elif isinstance(val, omero.RInternal):
145 return val
146 elif isinstance(val, omero.Internal):
147 return RInternalI(val)
148 else:
149 raise ValueError("Not Internal type: %s" % type(val))
150
152 """
153 If argument is None, returns rnullobject.
154 If an RObject, returns the argument itself.
155 Otherwise creates a new RObject
156 """
157 if val == None:
158 return rnullobject
159 elif isinstance(val, omero.RObject):
160 return val
161 elif isinstance(val, omero.model.IObject):
162 return RObjectI(val)
163 else:
164 raise ValueError("Not IObject type: %s" % type(val))
165
167 """
168 If argument is None or "", returns emptyclass.
169 If an RClass, returns the argument itself.
170 Otherwise creates a new RClass
171 """
172 if val == None:
173 return remptyclass
174 elif isinstance(val, omero.RClass):
175 return val
176 elif isinstance(val, str):
177 if len(val) == 0:
178 return remptyclass
179 else:
180 return RClassI(val)
181 raise ValueError("Not string type: %s" % type(val))
182
184 """
185 If argument is None or "", returns emptystring.
186 If an RString, returns the argument itself.
187 Otherwise creates a new RString
188 """
189 if val == None:
190 return remptystr
191 elif isinstance(val, omero.RString):
192 return val
193 elif isinstance(val, str):
194 if len(val) == 0:
195 return remptystr
196 else:
197 return RStringI(val)
198 raise ValueError("Not string type: %s" % type(val))
199
200
201
202
203 -def rarray(val = None, *args):
205
206 -def rlist(val = None, *args):
208
209 -def rset(val = None, *args):
210 return RSetI(val, *args)
211
212 -def rmap(val = None, **kwargs):
213 return RMapI(val, **kwargs)
214
215
216
217
219
222
225
226 - def compare(self, rhs, current = None):
227 raise NotImplementedError("compare")
228
230 if obj == None:
231 return False
232 elif obj is self:
233 return True
234 elif not isinstance(obj, omero.RBool):
235 return False
236 return obj._val == self._val
237
239 return not self.__eq__(obj)
240
242 if self._val:
243 return hash(True)
244 else:
245 return hash(False)
246
248 if attr == "val":
249 return self.getValue()
250 else:
251 raise AttributeError(attr)
252
254 if attr == "val":
255 if self.__dict__.has_key("_val"):
256 raise omero.ClientError("Cannot write to val")
257 else:
258 self.__dict__["_val"] = value
259 else:
260 object.__setattr__(self, attr, value)
261
263 """
264 Provides additional initialization once all data loaded
265 Required due to __getattr__ implementation.
266 """
267 pass
268
269
271 """
272 Provides additional validation before data is sent
273 Required due to __getattr__ implementation.
274 """
275 pass
276
278
281
284
285 - def compare(self, rhs, current = None):
286 raise NotImplementedError("compare")
287
289 if obj == None:
290 return False
291 elif obj is self:
292 return True
293 elif not isinstance(obj, omero.RDouble):
294 return False
295 return obj._val == self._val
296
298 return not self.__eq__(obj)
299
301 return hash(self._val)
302
304 if attr == "val":
305 return self.getValue()
306 else:
307 raise AttributeError(attr)
308
310 if attr == "val":
311 if self.__dict__.has_key("_val"):
312 raise omero.ClientError("Cannot write to val")
313 else:
314 self.__dict__["_val"] = value
315 else:
316 object.__setattr__(self, attr, value)
317
319 """
320 Provides additional initialization once all data loaded
321 Required due to __getattr__ implementation.
322 """
323 pass
324
326 """
327 Provides additional validation before data is sent
328 Required due to __getattr__ implementation.
329 """
330 pass
331
333
336
339
340 - def compare(self, rhs, current = None):
341 raise NotImplementedError("compare")
342
344 if obj == None:
345 return False
346 elif obj is self:
347 return True
348 elif not isinstance(obj, omero.RFloat):
349 return False
350 return obj._val == self._val
351
353 return not self.__eq__(obj)
354
356 return hash(self._val)
357
359 if attr == "val":
360 return self.getValue()
361 else:
362 raise AttributeError(attr)
363
365 if attr == "val":
366 if self.__dict__.has_key("_val"):
367 raise omero.ClientError("Cannot write to val")
368 else:
369 self.__dict__["_val"] = value
370 else:
371 object.__setattr__(self, attr, value)
372
374 """
375 Provides additional initialization once all data loaded
376 Required due to __getattr__ implementation.
377 """
378 pass
379
381 """
382 Provides additional validation before data is sent
383 Required due to __getattr__ implementation.
384 """
385 pass
386
388
391
394
395 - def compare(self, rhs, current = None):
396 raise NotImplementedError("compare")
397
399 if obj == None:
400 return False
401 elif obj is self:
402 return True
403 elif not isinstance(obj, omero.RInt):
404 return False
405 return obj._val == self._val
406
408 return not self.__eq__(obj)
409
411 return hash(self._val)
412
414 if attr == "val":
415 return self.getValue()
416 else:
417 raise AttributeError(attr)
418
420 if attr == "val":
421 if self.__dict__.has_key("_val"):
422 raise omero.ClientError("Cannot write to val")
423 else:
424 self.__dict__["_val"] = value
425 else:
426 object.__setattr__(self, attr, value)
427
429 """
430 Provides additional initialization once all data loaded
431 Required due to __getattr__ implementation.
432 """
433 pass
434
436 """
437 Provides additional validation before data is sent
438 Required due to __getattr__ implementation.
439 """
440 pass
441
443
446
449
450 - def compare(self, rhs, current = None):
451 raise NotImplementedError("compare")
452
454 if obj == None:
455 return False
456 elif obj is self:
457 return True
458 elif not isinstance(obj, omero.RLong):
459 return False
460 return obj._val == self._val
461
463 return not self.__eq__(obj)
464
466 return hash(self._val)
467
469 if attr == "val":
470 return self.getValue()
471 else:
472 raise AttributeError(attr)
473
475 if attr == "val":
476 if self.__dict__.has_key("_val"):
477 raise omero.ClientError("Cannot write to val")
478 else:
479 self.__dict__["_val"] = value
480 else:
481 object.__setattr__(self, attr, value)
482
484 """
485 Provides additional initialization once all data loaded
486 Required due to __getattr__ implementation.
487 """
488 pass
489
491 """
492 Provides additional validation before data is sent
493 Required due to __getattr__ implementation.
494 """
495 pass
496
498
501
504
505 - def compare(self, rhs, current = None):
506 raise NotImplementedError("compare")
507
509 if obj == None:
510 return False
511 elif obj is self:
512 return True
513 elif not isinstance(obj, omero.RTime):
514 return False
515 return obj._val == self._val
516
518 return not self.__eq__(obj)
519
521 return hash(self._val)
522
524 if attr == "val":
525 return self.getValue()
526 else:
527 raise AttributeError(attr)
528
530 if attr == "val":
531 if self.__dict__.has_key("_val"):
532 raise omero.ClientError("Cannot write to val")
533 else:
534 self.__dict__["_val"] = value
535 else:
536 object.__setattr__(self, attr, value)
537
539 """
540 Provides additional initialization once all data loaded
541 Required due to __getattr__ implementation.
542 """
543 pass
544
546 """
547 Provides additional validation before data is sent
548 Required due to __getattr__ implementation.
549 """
550 pass
551
552
553
554
556
559
562
563 - def compare(self, rhs, current = None):
564 raise NotImplementedError("compare")
565
567 if obj == None:
568 return False
569 elif obj is self:
570 return True
571 elif not isinstance(obj, omero.RInternal):
572 return False
573 return obj._val == self._val
574
576 return not self.__eq__(obj)
577
579 return hash(self._val)
580
582 if attr == "val":
583 return self.getValue()
584 else:
585 raise AttributeError(attr)
586
588 if attr == "val":
589 if self.__dict__.has_key("_val"):
590 raise omero.ClientError("Cannot write to val")
591 else:
592 self.__dict__["_val"] = value
593 else:
594 object.__setattr__(self, attr, value)
595
597 """
598 Provides additional initialization once all data loaded
599 Required due to __getattr__ implementation.
600 """
601 pass
602
604 """
605 Provides additional validation before data is sent
606 Required due to __getattr__ implementation.
607 """
608 pass
609
611
614
617
618 - def compare(self, rhs, current = None):
619 raise NotImplementedError("compare")
620
622 if obj == None:
623 return False
624 elif obj is self:
625 return True
626 elif not isinstance(obj, omero.RObject):
627 return False
628 return obj._val == self._val
629
631 return not self.__eq__(obj)
632
634 return hash(self._val)
635
637 if attr == "val":
638 return self.getValue()
639 else:
640 raise AttributeError(attr)
641
643 if attr == "val":
644 if self.__dict__.has_key("_val"):
645 raise omero.ClientError("Cannot write to val")
646 else:
647 self.__dict__["_val"] = value
648 else:
649 object.__setattr__(self, attr, value)
650
652 """
653 Provides additional initialization once all data loaded
654 Required due to __getattr__ implementation.
655 """
656 pass
657
659 """
660 Provides additional validation before data is sent
661 Required due to __getattr__ implementation.
662 """
663 pass
664
666
669
672
673 - def compare(self, rhs, current = None):
674 raise NotImplementedError("compare")
675
677 if obj == None:
678 return False
679 elif obj is self:
680 return True
681 elif not isinstance(obj, omero.RString):
682 return False
683 return obj._val == self._val
684
686 return not self.__eq__(obj)
687
689 return hash(self._val)
690
692 if attr == "val":
693 return self.getValue()
694 else:
695 raise AttributeError(attr)
696
698 if attr == "val":
699 if self.__dict__.has_key("_val"):
700 raise omero.ClientError("Cannot write to val")
701 else:
702 self.__dict__["_val"] = value
703 else:
704 object.__setattr__(self, attr, value)
705
707 """
708 Provides additional initialization once all data loaded
709 Required due to __getattr__ implementation.
710 """
711 pass
712
714 """
715 Provides additional validation before data is sent
716 Required due to __getattr__ implementation.
717 """
718 pass
719
721
724
727
728 - def compare(self, rhs, current = None):
729 raise NotImplementedError("compare")
730
732 if obj == None:
733 return False
734 elif obj is self:
735 return True
736 elif not isinstance(obj, omero.RClass):
737 return False
738 return obj._val == self._val
739
741 return not self.__eq__(obj)
742
744 return hash(self._val)
745
747 if attr == "val":
748 return self.getValue()
749 else:
750 raise AttributeError(attr)
751
753 if attr == "val":
754 if self.__dict__.has_key("_val"):
755 raise omero.ClientError("Cannot write to val")
756 else:
757 self.__dict__["_val"] = value
758 else:
759 object.__setattr__(self, attr, value)
760
762 """
763 Provides additional initialization once all data loaded
764 Required due to __getattr__ implementation.
765 """
766 pass
767
769 """
770 Provides additional validation before data is sent
771 Required due to __getattr__ implementation.
772 """
773 pass
774
775
776
777
779 """
780 Guaranteed to never contain an empty list.
781 """
782
784 if arg == None:
785 self._val = []
786 elif not hasattr(arg, "__iter__"):
787 self._val = [arg]
788 else:
789 self._val = list(arg)
790 self._val.extend(args)
791 for v in self._val:
792 if not isinstance(v, omero.RType):
793 raise ValueError("Item of wrong type: %s" % type(v))
794
795 - def compare(self, rhs, current = None):
796 raise NotImplementedError("compare")
797
800
801 - def get(self, index, current = None):
802 return self._val[index]
803
804 - def size(self, current = None):
805 return len(self._val)
806
807 - def add(self, value, current = None):
809
810 - def addAll(self, values, current = None):
812
814 if obj == None:
815 return False
816 elif self is obj:
817 return True
818 elif not isinstance(obj, omero.RArray):
819 return False
820 return self._val == obj._val
821
823 return not self.__eq__(obj)
824
826 """
827 Not allowed. Hashing a list is not supported.
828 """
829 return hash(self._val)
830
832 if attr == "val":
833 return self.getValue()
834 else:
835 raise AttributeError(attr)
836
838 if attr == "val":
839 if self.__dict__.has_key("_val"):
840 raise omero.ClientError("Cannot write to val")
841 else:
842 self.__dict__["_val"] = value
843 else:
844 object.__setattr__(self, attr, value)
845
847 """
848 Provides additional initialization once all data loaded
849 Required due to __getattr__ implementation.
850 """
851 pass
852
854 """
855 Provides additional validation before data is sent
856 Required due to __getattr__ implementation.
857 """
858 pass
859
861 """
862 Guaranteed to never contain an empty list.
863 """
864
866 if arg == None:
867 self._val = []
868 elif not hasattr(arg, "__iter__"):
869 self._val = [arg]
870 else:
871 self._val = list(arg)
872 self._val.extend(args)
873 for v in self._val:
874 if not isinstance(v, omero.RType):
875 raise ValueError("Item of wrong type: %s" % type(v))
876
877
878 - def compare(self, rhs, current = None):
879 raise NotImplementedError("compare")
880
883
884 - def get(self, index, current = None):
885 return self._val[index]
886
887 - def size(self, current = None):
888 return len(self._val)
889
890 - def add(self, value, current = None):
892
893 - def addAll(self, values, current = None):
895
897 if obj == None:
898 return False
899 elif self is obj:
900 return True
901 elif not isinstance(obj, omero.RList):
902 return False
903 return self._val == obj._val
904
906 return not self.__eq__(obj)
907
909 """
910 Not allowed. Hashing a list is not supported.
911 """
912 return hash(self._val)
913
915 if attr == "val":
916 return self.getValue()
917 else:
918 raise AttributeError(attr)
919
921 if attr == "val":
922 if self.__dict__.has_key("_val"):
923 raise omero.ClientError("Cannot write to val")
924 else:
925 self.__dict__["_val"] = value
926 else:
927 object.__setattr__(self, attr, value)
928
930 """
931 Provides additional initialization once all data loaded
932 Required due to __getattr__ implementation.
933 """
934 pass
935
937 """
938 Provides additional validation before data is sent
939 Required due to __getattr__ implementation.
940 """
941 pass
942
944 """
945 Guaranteed to never contain an empty list.
946 """
947
949 if arg == None:
950 self._val = []
951 elif not hasattr(arg, "__iter__"):
952 self._val = [arg]
953 else:
954 self._val = list(arg)
955 self._val.extend(args)
956 for v in self._val:
957 if not isinstance(v, omero.RType):
958 raise ValueError("Item of wrong type: %s" % type(v))
959
960
961 - def compare(self, rhs, current = None):
962 raise NotImplementedError("compare")
963
966
967 - def get(self, index, current = None):
968 return self._val[index]
969
970 - def size(self, current = None):
971 return len(self._val)
972
973 - def add(self, value, current = None):
975
976 - def addAll(self, values, current = None):
978
980 if obj == None:
981 return False
982 elif self is obj:
983 return True
984 elif not isinstance(obj, omero.RSet):
985 return False
986 return self._val == obj._val
987
989 return not self.__eq__(obj)
990
992 """
993 Not allowed. Hashing a list is not supported.
994 """
995 return hash(self._val)
996
998 if attr == "val":
999 return self.getValue()
1000 else:
1001 raise AttributeError(attr)
1002
1004 if attr == "val":
1005 if self.__dict__.has_key("_val"):
1006 raise omero.ClientError("Cannot write to val")
1007 else:
1008 self.__dict__["_val"] = value
1009 else:
1010 object.__setattr__(self, attr, value)
1011
1013 """
1014 Provides additional initialization once all data loaded
1015 Required due to __getattr__ implementation.
1016 """
1017 pass
1018
1020 """
1021 Provides additional validation before data is sent
1022 Required due to __getattr__ implementation.
1023 """
1024 pass
1025
1026 -class RMapI(omero.RMap):
1027
1028 - def __init__(self, arg = None, **kwargs):
1029 if arg == None:
1030 self._val = {}
1031 else:
1032 self._val = dict(arg)
1033 self._val.update(kwargs)
1034 for k, v in self._val.items():
1035 if not isinstance(k, str):
1036 raise ValueError("Key of wrong type: %s" % type(k))
1037 if not isinstance(v, omero.RType):
1038 raise ValueError("Value of wrong type: %s" % type(v))
1039
1040 - def compare(self, rhs, current = None):
1041 raise NotImplementedError("compare")
1042
1045
1046 - def get(self, key, current = None):
1047 return self._val[key]
1048
1049 - def put(self, key, value, current = None):
1050 self._val[key] = value
1051
1052 - def size(self, current = None):
1053 return len(self._val)
1054
1056 if obj == None:
1057 return False
1058 elif self is obj:
1059 return True
1060 elif not isinstance(obj, omero.RMap):
1061 return False
1062 return self._val == obj._val
1063
1065 return not self.__eq__(obj)
1066
1068 """
1069 Not allowed. Hashing a list is not supported.
1070 """
1071 return hash(self._val)
1072
1074 if attr == "val":
1075 return self.getValue()
1076 else:
1077 raise AttributeError(attr)
1078
1080 if attr == "val":
1081 if self.__dict__.has_key("_val"):
1082 raise omero.ClientError("Cannot write to val")
1083 else:
1084 self.__dict__["_val"] = value
1085 else:
1086 object.__setattr__(self, attr, value)
1087
1089 """
1090 Provides additional initialization once all data loaded
1091 Required due to __getattr__ implementation.
1092 """
1093 pass
1094
1096 """
1097 Provides additional validation before data is sent
1098 Required due to __getattr__ implementation.
1099 """
1100 pass
1101
1102
1103
1104
1105
1106
1108
1110 self.id = cls.ice_staticId()
1111 self.f = f
1112
1115
1118
1120 ic.addObjectFactory(self, self.id)
1121
1122
1123
1124
1125
1126 rtrue = RBoolI(True)
1127
1128 rfalse = RBoolI(False)
1129
1130 rlong0 = RLongI(0)
1131
1132 rint0 = RIntI(0)
1133
1134 remptystr = RStringI("")
1135
1136 remptyclass = RClassI("")
1137
1138 rnullinternal = RInternalI(None)
1139
1140 rnullobject = RObjectI(None)
1141
1142
1143
1144
1145 ObjectFactories = {
1146 RBoolI: ObjectFactory(RBoolI, lambda: RBoolI(False)),
1147 RDoubleI: ObjectFactory(RDoubleI, lambda: RDoubleI(0.0)),
1148 RFloatI: ObjectFactory(RFloatI, lambda: RFloatI(0.0)),
1149 RIntI: ObjectFactory(RIntI, lambda: RIntI(0)),
1150 RLongI: ObjectFactory(RLongI, lambda: RLongI(0)),
1151 RTimeI: ObjectFactory(RTimeI, lambda: RTimeI(0)),
1152 RClassI: ObjectFactory(RClassI, lambda: RClassI("")),
1153 RStringI: ObjectFactory(RStringI, lambda: RStringI("")),
1154 RInternalI: ObjectFactory(RInternalI, lambda: RInternalI(None)),
1155 RObjectI: ObjectFactory(RObjectI, lambda: RObjectI(None)),
1156 RArrayI: ObjectFactory(RArrayI, lambda: RArrayI()),
1157 RListI: ObjectFactory(RListI, lambda: RListI()),
1158 RSetI: ObjectFactory(RSetI, lambda: RSetI()),
1159 RMapI: ObjectFactory(RMapI, lambda: RMapI())
1160 }
1161