Package omero :: Module rtypes
[hide private]
[frames] | no frames]

Source Code for Module omero.rtypes

   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  
 
26 -def rtype(val):
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 # Static factory methods (primitives) 67 # ========================================================================= 68
69 -def rbool(val):
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
82 -def rdouble(val):
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
91 -def rfloat(val):
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
100 -def rint(val):
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
112 -def rlong(val):
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
124 -def rtime(val):
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 # Static factory methods (objects) 134 # ========================================================================= 135
136 -def rinternal(val):
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
151 -def robject(val):
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
166 -def rclass(val):
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
183 -def rstring(val):
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 # Static factory methods (collections) 201 # ========================================================================= 202
203 -def rarray(val = None, *args):
204 return RArrayI(val, *args)
205
206 -def rlist(val = None, *args):
207 return RListI(val, *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 # Implementations (primitives) 216 # ========================================================================= 217
218 -class RBoolI(omero.RBool):
219
220 - def __init__(self, value):
221 omero.RBool.__init__(self, value)
222
223 - def getValue(self, current = None):
224 return self._val
225
226 - def compare(self, rhs, current = None):
227 raise NotImplementedError("compare")
228
229 - def __eq__(self, obj):
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
238 - def __ne__(self, obj):
239 return not self.__eq__(obj)
240
241 - def __hash__(self):
242 if self._val: 243 return hash(True) 244 else: 245 return hash(False)
246
247 - def __getattr__(self, attr):
248 if attr == "val": 249 return self.getValue() 250 else: 251 raise AttributeError(attr)
252
253 - def __setattr__(self, attr, value):
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
262 - def ice_postUnmarshal(self):
263 """ 264 Provides additional initialization once all data loaded 265 Required due to __getattr__ implementation. 266 """ 267 pass # Currently unused
268 269
270 - def ice_preMarshal(self):
271 """ 272 Provides additional validation before data is sent 273 Required due to __getattr__ implementation. 274 """ 275 pass # Currently unused
276
277 -class RDoubleI(omero.RDouble):
278
279 - def __init__(self, value):
280 omero.RDouble.__init__(self, value)
281
282 - def getValue(self, current = None):
283 return self._val
284
285 - def compare(self, rhs, current = None):
286 raise NotImplementedError("compare")
287
288 - def __eq__(self, obj):
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
297 - def __ne__(self, obj):
298 return not self.__eq__(obj)
299
300 - def __hash__(self):
301 return hash(self._val)
302
303 - def __getattr__(self, attr):
304 if attr == "val": 305 return self.getValue() 306 else: 307 raise AttributeError(attr)
308
309 - def __setattr__(self, attr, value):
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
318 - def ice_postUnmarshal(self):
319 """ 320 Provides additional initialization once all data loaded 321 Required due to __getattr__ implementation. 322 """ 323 pass # Currently unused
324
325 - def ice_preMarshal(self):
326 """ 327 Provides additional validation before data is sent 328 Required due to __getattr__ implementation. 329 """ 330 pass # Currently unused
331
332 -class RFloatI(omero.RFloat):
333
334 - def __init__(self, value):
335 omero.RFloat.__init__(self, value)
336
337 - def getValue(self, current = None):
338 return self._val
339
340 - def compare(self, rhs, current = None):
341 raise NotImplementedError("compare")
342
343 - def __eq__(self, obj):
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
352 - def __ne__(self, obj):
353 return not self.__eq__(obj)
354
355 - def __hash__(self):
356 return hash(self._val)
357
358 - def __getattr__(self, attr):
359 if attr == "val": 360 return self.getValue() 361 else: 362 raise AttributeError(attr)
363
364 - def __setattr__(self, attr, value):
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
373 - def ice_postUnmarshal(self):
374 """ 375 Provides additional initialization once all data loaded 376 Required due to __getattr__ implementation. 377 """ 378 pass # Currently unused
379
380 - def ice_preMarshal(self):
381 """ 382 Provides additional validation before data is sent 383 Required due to __getattr__ implementation. 384 """ 385 pass # Currently unused
386
387 -class RIntI(omero.RInt):
388
389 - def __init__(self, value):
390 omero.RInt.__init__(self, value)
391
392 - def getValue(self, current = None):
393 return self._val
394
395 - def compare(self, rhs, current = None):
396 raise NotImplementedError("compare")
397
398 - def __eq__(self, obj):
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
407 - def __ne__(self, obj):
408 return not self.__eq__(obj)
409
410 - def __hash__(self):
411 return hash(self._val)
412
413 - def __getattr__(self, attr):
414 if attr == "val": 415 return self.getValue() 416 else: 417 raise AttributeError(attr)
418
419 - def __setattr__(self, attr, value):
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
428 - def ice_postUnmarshal(self):
429 """ 430 Provides additional initialization once all data loaded 431 Required due to __getattr__ implementation. 432 """ 433 pass # Currently unused
434
435 - def ice_preMarshal(self):
436 """ 437 Provides additional validation before data is sent 438 Required due to __getattr__ implementation. 439 """ 440 pass # Currently unused
441
442 -class RLongI(omero.RLong):
443
444 - def __init__(self, value):
445 omero.RLong.__init__(self, value)
446
447 - def getValue(self, current = None):
448 return self._val
449
450 - def compare(self, rhs, current = None):
451 raise NotImplementedError("compare")
452
453 - def __eq__(self, obj):
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
462 - def __ne__(self, obj):
463 return not self.__eq__(obj)
464
465 - def __hash__(self):
466 return hash(self._val)
467
468 - def __getattr__(self, attr):
469 if attr == "val": 470 return self.getValue() 471 else: 472 raise AttributeError(attr)
473
474 - def __setattr__(self, attr, value):
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
483 - def ice_postUnmarshal(self):
484 """ 485 Provides additional initialization once all data loaded 486 Required due to __getattr__ implementation. 487 """ 488 pass # Currently unused
489
490 - def ice_preMarshal(self):
491 """ 492 Provides additional validation before data is sent 493 Required due to __getattr__ implementation. 494 """ 495 pass # Currently unused
496
497 -class RTimeI(omero.RTime):
498
499 - def __init__(self, value):
500 omero.RTime.__init__(self, value)
501
502 - def getValue(self, current = None):
503 return self._val
504
505 - def compare(self, rhs, current = None):
506 raise NotImplementedError("compare")
507
508 - def __eq__(self, obj):
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
517 - def __ne__(self, obj):
518 return not self.__eq__(obj)
519
520 - def __hash__(self):
521 return hash(self._val)
522
523 - def __getattr__(self, attr):
524 if attr == "val": 525 return self.getValue() 526 else: 527 raise AttributeError(attr)
528
529 - def __setattr__(self, attr, value):
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
538 - def ice_postUnmarshal(self):
539 """ 540 Provides additional initialization once all data loaded 541 Required due to __getattr__ implementation. 542 """ 543 pass # Currently unused
544
545 - def ice_preMarshal(self):
546 """ 547 Provides additional validation before data is sent 548 Required due to __getattr__ implementation. 549 """ 550 pass # Currently unused
551 552 # Implementations (objects) 553 # ========================================================================= 554
555 -class RInternalI(omero.RInternal):
556
557 - def __init__(self, value):
558 omero.RInternal.__init__(self, value)
559
560 - def getValue(self, current = None):
561 return self._val
562
563 - def compare(self, rhs, current = None):
564 raise NotImplementedError("compare")
565
566 - def __eq__(self, obj):
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
575 - def __ne__(self, obj):
576 return not self.__eq__(obj)
577
578 - def __hash__(self):
579 return hash(self._val)
580
581 - def __getattr__(self, attr):
582 if attr == "val": 583 return self.getValue() 584 else: 585 raise AttributeError(attr)
586
587 - def __setattr__(self, attr, value):
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
596 - def ice_postUnmarshal(self):
597 """ 598 Provides additional initialization once all data loaded 599 Required due to __getattr__ implementation. 600 """ 601 pass # Currently unused
602
603 - def ice_preMarshal(self):
604 """ 605 Provides additional validation before data is sent 606 Required due to __getattr__ implementation. 607 """ 608 pass # Currently unused
609
610 -class RObjectI(omero.RObject):
611
612 - def __init__(self, value):
613 omero.RObject.__init__(self, value)
614
615 - def getValue(self, current = None):
616 return self._val
617
618 - def compare(self, rhs, current = None):
619 raise NotImplementedError("compare")
620
621 - def __eq__(self, obj):
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
630 - def __ne__(self, obj):
631 return not self.__eq__(obj)
632
633 - def __hash__(self):
634 return hash(self._val)
635
636 - def __getattr__(self, attr):
637 if attr == "val": 638 return self.getValue() 639 else: 640 raise AttributeError(attr)
641
642 - def __setattr__(self, attr, value):
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
651 - def ice_postUnmarshal(self):
652 """ 653 Provides additional initialization once all data loaded 654 Required due to __getattr__ implementation. 655 """ 656 pass # Currently unused
657
658 - def ice_preMarshal(self):
659 """ 660 Provides additional validation before data is sent 661 Required due to __getattr__ implementation. 662 """ 663 pass # Currently unused
664
665 -class RStringI(omero.RString):
666
667 - def __init__(self, value):
668 omero.RString.__init__(self, value)
669
670 - def getValue(self, current = None):
671 return self._val
672
673 - def compare(self, rhs, current = None):
674 raise NotImplementedError("compare")
675
676 - def __eq__(self, obj):
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
685 - def __ne__(self, obj):
686 return not self.__eq__(obj)
687
688 - def __hash__(self):
689 return hash(self._val)
690
691 - def __getattr__(self, attr):
692 if attr == "val": 693 return self.getValue() 694 else: 695 raise AttributeError(attr)
696
697 - def __setattr__(self, attr, value):
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
706 - def ice_postUnmarshal(self):
707 """ 708 Provides additional initialization once all data loaded 709 Required due to __getattr__ implementation. 710 """ 711 pass # Currently unused
712
713 - def ice_preMarshal(self):
714 """ 715 Provides additional validation before data is sent 716 Required due to __getattr__ implementation. 717 """ 718 pass # Currently unused
719
720 -class RClassI(omero.RClass):
721
722 - def __init__(self, value):
723 omero.RClass.__init__(self, value)
724
725 - def getValue(self, current = None):
726 return self._val
727
728 - def compare(self, rhs, current = None):
729 raise NotImplementedError("compare")
730
731 - def __eq__(self, obj):
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
740 - def __ne__(self, obj):
741 return not self.__eq__(obj)
742
743 - def __hash__(self):
744 return hash(self._val)
745
746 - def __getattr__(self, attr):
747 if attr == "val": 748 return self.getValue() 749 else: 750 raise AttributeError(attr)
751
752 - def __setattr__(self, attr, value):
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
761 - def ice_postUnmarshal(self):
762 """ 763 Provides additional initialization once all data loaded 764 Required due to __getattr__ implementation. 765 """ 766 pass # Currently unused
767
768 - def ice_preMarshal(self):
769 """ 770 Provides additional validation before data is sent 771 Required due to __getattr__ implementation. 772 """ 773 pass # Currently unused
774 775 # Implementations (collections) 776 # ========================================================================= 777
778 -class RArrayI(omero.RArray):
779 """ 780 Guaranteed to never contain an empty list. 781 """ 782
783 - def __init__(self, arg = None, *args):
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
798 - def getValue(self, current = None):
799 return self._val
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):
808 self._val.append(value)
809
810 - def addAll(self, values, current = None):
811 self.val.append(values)
812
813 - def __eq__(self, obj):
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
822 - def __ne__(self, obj):
823 return not self.__eq__(obj)
824
825 - def __hash__(self, obj):
826 """ 827 Not allowed. Hashing a list is not supported. 828 """ 829 return hash(self._val) # Throws an exception
830
831 - def __getattr__(self, attr):
832 if attr == "val": 833 return self.getValue() 834 else: 835 raise AttributeError(attr)
836
837 - def __setattr__(self, attr, value):
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
846 - def ice_postUnmarshal(self):
847 """ 848 Provides additional initialization once all data loaded 849 Required due to __getattr__ implementation. 850 """ 851 pass # Currently unused
852
853 - def ice_preMarshal(self):
854 """ 855 Provides additional validation before data is sent 856 Required due to __getattr__ implementation. 857 """ 858 pass # Currently unused
859
860 -class RListI(omero.RList):
861 """ 862 Guaranteed to never contain an empty list. 863 """ 864
865 - def __init__(self, arg = None, *args):
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
881 - def getValue(self, current = None):
882 return self._val
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):
891 self._val.append(value)
892
893 - def addAll(self, values, current = None):
894 self.val.append(values)
895
896 - def __eq__(self, obj):
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
905 - def __ne__(self, obj):
906 return not self.__eq__(obj)
907
908 - def __hash__(self, obj):
909 """ 910 Not allowed. Hashing a list is not supported. 911 """ 912 return hash(self._val) # Throws an exception
913
914 - def __getattr__(self, attr):
915 if attr == "val": 916 return self.getValue() 917 else: 918 raise AttributeError(attr)
919
920 - def __setattr__(self, attr, value):
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
929 - def ice_postUnmarshal(self):
930 """ 931 Provides additional initialization once all data loaded 932 Required due to __getattr__ implementation. 933 """ 934 pass # Currently unused
935
936 - def ice_preMarshal(self):
937 """ 938 Provides additional validation before data is sent 939 Required due to __getattr__ implementation. 940 """ 941 pass # Currently unused
942
943 -class RSetI(omero.RSet):
944 """ 945 Guaranteed to never contain an empty list. 946 """ 947
948 - def __init__(self, arg = None, *args):
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
964 - def getValue(self, current = None):
965 return self._val
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):
974 self._val.append(value)
975
976 - def addAll(self, values, current = None):
977 self.val.append(values)
978
979 - def __eq__(self, obj):
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
988 - def __ne__(self, obj):
989 return not self.__eq__(obj)
990
991 - def __hash__(self, obj):
992 """ 993 Not allowed. Hashing a list is not supported. 994 """ 995 return hash(self._val) # Throws an exception
996
997 - def __getattr__(self, attr):
998 if attr == "val": 999 return self.getValue() 1000 else: 1001 raise AttributeError(attr)
1002
1003 - def __setattr__(self, attr, value):
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
1012 - def ice_postUnmarshal(self):
1013 """ 1014 Provides additional initialization once all data loaded 1015 Required due to __getattr__ implementation. 1016 """ 1017 pass # Currently unused
1018
1019 - def ice_preMarshal(self):
1020 """ 1021 Provides additional validation before data is sent 1022 Required due to __getattr__ implementation. 1023 """ 1024 pass # Currently unused
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) # May throw an exception 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
1043 - def getValue(self, current = None):
1044 return self._val
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
1055 - def __eq__(self, obj):
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
1064 - def __ne__(self, obj):
1065 return not self.__eq__(obj)
1066
1067 - def __hash__(self, obj):
1068 """ 1069 Not allowed. Hashing a list is not supported. 1070 """ 1071 return hash(self._val) # Throws an exception
1072
1073 - def __getattr__(self, attr):
1074 if attr == "val": 1075 return self.getValue() 1076 else: 1077 raise AttributeError(attr)
1078
1079 - def __setattr__(self, attr, value):
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
1088 - def ice_postUnmarshal(self):
1089 """ 1090 Provides additional initialization once all data loaded 1091 Required due to __getattr__ implementation. 1092 """ 1093 pass # Currently unused
1094
1095 - def ice_preMarshal(self):
1096 """ 1097 Provides additional validation before data is sent 1098 Required due to __getattr__ implementation. 1099 """ 1100 pass # Currently unused
1101 1102 # Helpers 1103 # ======================================================================== 1104 1105 # Conversion classes are for omero.model <--> ome.model only (no python) 1106
1107 -class ObjectFactory(Ice.ObjectFactory):
1108
1109 - def __init__(self, cls, f):
1110 self.id = cls.ice_staticId() 1111 self.f = f
1112
1113 - def create(self, string):
1114 return self.f()
1115
1116 - def destroy(self):
1117 pass
1118
1119 - def register(self, ic):
1120 ic.addObjectFactory(self, self.id)
1121 1122 1123 # Shared state (flyweight) 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 # Object factories 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