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 -def wrap(val, cache=None):
67 """ 68 """ 69 if cache is None: 70 cache = {} 71 elif id(val) in cache: 72 return cache[id(val)] 73 74 if val is None: 75 return None 76 elif isinstance(val, (list, tuple)): 77 rv = rlist() 78 cache[id(val)] = rv 79 for x in val: 80 rv.val.append(wrap(x, cache)) 81 elif isinstance(val, set): 82 rv = rset() 83 cache[id(val)] = rv 84 for x in val: 85 rv.val.add(wrap(x, cache)) 86 elif isinstance(val, dict): 87 rv = rmap() 88 cache[id(val)] = rv 89 for k, v in val.items(): 90 rv.val[k] = wrap(v, cache) 91 rv._validate() 92 elif isinstance(val, omero.RType): 93 rv = val 94 else: 95 rv = rtype(val) 96 97 return rv
98
99 -def unwrap(val, cache=None):
100 """ 101 """ 102 if cache is None: 103 cache = {} 104 elif id(val) in cache: 105 return cache[id(val)] 106 107 if val is None: 108 return None 109 elif isinstance(val, (list, tuple)): 110 rv = [] 111 cache[id(val)] = rv 112 for x in val: 113 rv.append(unwrap(x, cache)) 114 elif isinstance(val, set): 115 rv = set() 116 cache[id(val)] = rv 117 for x in val: 118 rv.add(unwrap(x, cache)) 119 elif isinstance(val, dict): 120 rv = {} 121 cache[id(val)] = rv 122 for k, v in val.items(): 123 rv[unwrap(k, cache)] = unwrap(v, cache) 124 elif isinstance(val, omero.RCollection): 125 if val.val is None: 126 rv = None 127 cache[id(val)] = None 128 else: 129 rv = [] 130 cache[id(val)] = rv 131 for x in val.val: 132 rv.append(unwrap(x, cache)) 133 elif isinstance(val, omero.RMap): 134 if val.val is None: 135 rv = None 136 cache[id(val)] = None 137 else: 138 rv = {} 139 cache[id(val)] = rv 140 for k, v in val.val.items(): 141 rv[unwrap(k, cache)] = unwrap(v, cache) 142 elif isinstance(val, omero.RType): # Non-recursive 143 rv = val.val 144 cache[id(val)] = rv 145 else: 146 rv = val 147 148 return rv
149 150 151 # Static factory methods (primitives) 152 # ========================================================================= 153
154 -def rbool(val):
155 """ 156 Returns the argument itself if None or an instance of RBool. 157 Otherwise, checks the value for"trueness" and returns either 158 rtrue or rfalse. 159 """ 160 if val == None or isinstance(val, omero.RBool): 161 return val 162 elif val: 163 return rtrue 164 else: 165 return rfalse
166
167 -def rdouble(val):
168 """ 169 Returns the argument itself if None or an instance of RDouble. 170 Otherwise, assigns a coerced float to the value of a new RDouble. 171 """ 172 if val == None or isinstance(val, omero.RDouble): 173 return val 174 return RDoubleI(val)
175
176 -def rfloat(val):
177 """ 178 Returns the argument itself if None or an instance of RFloat. 179 Otherwise, assigns a coerced float to the value of a new RFloat. 180 """ 181 if val == None or isinstance(val, omero.RFloat): 182 return val 183 return RFloatI(val)
184
185 -def rint(val):
186 """ 187 Returns the argument itself if None or an instance of RInt. 188 If the argument is 0, rint0 is returned. 189 Otherwise, assigns a coerced int to the value of a new RInt 190 """ 191 if val == None or isinstance(val, omero.RInt): 192 return val 193 elif val == 0: 194 return rint0 195 return RIntI(val)
196
197 -def rlong(val):
198 """ 199 Returns the argument itself if None or an instance of RLong. 200 If the argument is 0, rlong 0 is returned. 201 Otherwise, assigns a coerced int to the value of a new RLong 202 """ 203 if val == None or isinstance(val, omero.RLong): 204 return val 205 elif val == 0: 206 return rlong0 207 return RLongI(val)
208
209 -def rtime(val):
210 """ 211 Returns the argument itself if None or an instance of RTime. 212 Otherwise, assigns a coerced long to the value of a new RTime 213 """ 214 if val == None or isinstance(val, omero.RTime): 215 return val 216 return RTimeI(val)
217 218 # Static factory methods (objects) 219 # ========================================================================= 220
221 -def rinternal(val):
222 """ 223 If argument is None, returns rnullinternal. 224 If an RInternal, returns the argument itself. 225 Otherwise creates a new RInternal. 226 """ 227 if val == None: 228 return rnullinternal 229 elif isinstance(val, omero.RInternal): 230 return val 231 elif isinstance(val, omero.Internal): 232 return RInternalI(val) 233 else: 234 raise ValueError("Not Internal type: %s" % type(val))
235
236 -def robject(val):
237 """ 238 If argument is None, returns rnullobject. 239 If an RObject, returns the argument itself. 240 Otherwise creates a new RObject 241 """ 242 if val == None: 243 return rnullobject 244 elif isinstance(val, omero.RObject): 245 return val 246 elif isinstance(val, omero.model.IObject): 247 return RObjectI(val) 248 else: 249 raise ValueError("Not IObject type: %s" % type(val))
250
251 -def rclass(val):
252 """ 253 If argument is None or "", returns emptyclass. 254 If an RClass, returns the argument itself. 255 Otherwise creates a new RClass 256 """ 257 if val == None: 258 return remptyclass 259 elif isinstance(val, omero.RClass): 260 return val 261 elif isinstance(val, str): 262 if len(val) == 0: 263 return remptyclass 264 else: 265 return RClassI(val) 266 raise ValueError("Not string type: %s" % type(val))
267
268 -def rstring(val):
269 """ 270 If argument is None or "", returns emptystring. 271 If an RString, returns the argument itself. 272 Otherwise creates a new RString 273 """ 274 if val == None: 275 return remptystr 276 elif isinstance(val, omero.RString): 277 return val 278 elif isinstance(val, str): 279 if len(val) == 0: 280 return remptystr 281 else: 282 return RStringI(val) 283 raise ValueError("Not string type: %s" % type(val))
284 285 # Static factory methods (collections) 286 # ========================================================================= 287
288 -def rarray(val = None, *args):
289 return RArrayI(val, *args)
290
291 -def rlist(val = None, *args):
292 return RListI(val, *args)
293
294 -def rset(val = None, *args):
295 return RSetI(val, *args)
296
297 -def rmap(val = None, **kwargs):
298 return RMapI(val, **kwargs)
299 300 # Implementations (primitives) 301 # ========================================================================= 302
303 -class RBoolI(omero.RBool):
304
305 - def __init__(self, value):
306 omero.RBool.__init__(self, value)
307
308 - def getValue(self, current = None):
309 return self._val
310
311 - def compare(self, rhs, current = None):
312 raise NotImplementedError("compare")
313
314 - def __eq__(self, obj):
315 if obj == None: 316 return False 317 elif obj is self: 318 return True 319 elif not isinstance(obj, omero.RBool): 320 return False 321 return obj._val == self._val
322
323 - def __ne__(self, obj):
324 return not self.__eq__(obj)
325
326 - def __hash__(self):
327 if self._val: 328 return hash(True) 329 else: 330 return hash(False)
331
332 - def __getattr__(self, attr):
333 if attr == "val": 334 return self.getValue() 335 else: 336 raise AttributeError(attr)
337
338 - def __setattr__(self, attr, value):
339 if attr == "val": 340 if self.__dict__.has_key("_val"): 341 raise omero.ClientError("Cannot write to val") 342 else: 343 self.__dict__["_val"] = value 344 else: 345 object.__setattr__(self, attr, value)
346
347 - def ice_postUnmarshal(self):
348 """ 349 Provides additional initialization once all data loaded 350 Required due to __getattr__ implementation. 351 """ 352 pass # Currently unused
353 354
355 - def ice_preMarshal(self):
356 """ 357 Provides additional validation before data is sent 358 Required due to __getattr__ implementation. 359 """ 360 pass # Currently unused
361
362 -class RDoubleI(omero.RDouble):
363
364 - def __init__(self, value):
365 omero.RDouble.__init__(self, float(value))
366
367 - def getValue(self, current = None):
368 return self._val
369
370 - def compare(self, rhs, current = None):
371 raise NotImplementedError("compare")
372
373 - def __eq__(self, obj):
374 if obj == None: 375 return False 376 elif obj is self: 377 return True 378 elif not isinstance(obj, omero.RDouble): 379 return False 380 return obj._val == self._val
381
382 - def __ne__(self, obj):
383 return not self.__eq__(obj)
384
385 - def __hash__(self):
386 return hash(self._val)
387
388 - def __getattr__(self, attr):
389 if attr == "val": 390 return self.getValue() 391 else: 392 raise AttributeError(attr)
393
394 - def __setattr__(self, attr, value):
395 if attr == "val": 396 if self.__dict__.has_key("_val"): 397 raise omero.ClientError("Cannot write to val") 398 else: 399 self.__dict__["_val"] = value 400 else: 401 object.__setattr__(self, attr, value)
402
403 - def ice_postUnmarshal(self):
404 """ 405 Provides additional initialization once all data loaded 406 Required due to __getattr__ implementation. 407 """ 408 pass # Currently unused
409
410 - def ice_preMarshal(self):
411 """ 412 Provides additional validation before data is sent 413 Required due to __getattr__ implementation. 414 """ 415 pass # Currently unused
416
417 -class RFloatI(omero.RFloat):
418
419 - def __init__(self, value):
420 omero.RFloat.__init__(self, float(value))
421
422 - def getValue(self, current = None):
423 return self._val
424
425 - def compare(self, rhs, current = None):
426 raise NotImplementedError("compare")
427
428 - def __eq__(self, obj):
429 if obj == None: 430 return False 431 elif obj is self: 432 return True 433 elif not isinstance(obj, omero.RFloat): 434 return False 435 return obj._val == self._val
436
437 - def __ne__(self, obj):
438 return not self.__eq__(obj)
439
440 - def __hash__(self):
441 return hash(self._val)
442
443 - def __getattr__(self, attr):
444 if attr == "val": 445 return self.getValue() 446 else: 447 raise AttributeError(attr)
448
449 - def __setattr__(self, attr, value):
450 if attr == "val": 451 if self.__dict__.has_key("_val"): 452 raise omero.ClientError("Cannot write to val") 453 else: 454 self.__dict__["_val"] = value 455 else: 456 object.__setattr__(self, attr, value)
457
458 - def ice_postUnmarshal(self):
459 """ 460 Provides additional initialization once all data loaded 461 Required due to __getattr__ implementation. 462 """ 463 pass # Currently unused
464
465 - def ice_preMarshal(self):
466 """ 467 Provides additional validation before data is sent 468 Required due to __getattr__ implementation. 469 """ 470 pass # Currently unused
471
472 -class RIntI(omero.RInt):
473
474 - def __init__(self, value):
475 omero.RInt.__init__(self, int(value))
476
477 - def getValue(self, current = None):
478 return self._val
479
480 - def compare(self, rhs, current = None):
481 raise NotImplementedError("compare")
482
483 - def __eq__(self, obj):
484 if obj == None: 485 return False 486 elif obj is self: 487 return True 488 elif not isinstance(obj, omero.RInt): 489 return False 490 return obj._val == self._val
491
492 - def __ne__(self, obj):
493 return not self.__eq__(obj)
494
495 - def __hash__(self):
496 return hash(self._val)
497
498 - def __getattr__(self, attr):
499 if attr == "val": 500 return self.getValue() 501 else: 502 raise AttributeError(attr)
503
504 - def __setattr__(self, attr, value):
505 if attr == "val": 506 if self.__dict__.has_key("_val"): 507 raise omero.ClientError("Cannot write to val") 508 else: 509 self.__dict__["_val"] = value 510 else: 511 object.__setattr__(self, attr, value)
512
513 - def ice_postUnmarshal(self):
514 """ 515 Provides additional initialization once all data loaded 516 Required due to __getattr__ implementation. 517 """ 518 pass # Currently unused
519
520 - def ice_preMarshal(self):
521 """ 522 Provides additional validation before data is sent 523 Required due to __getattr__ implementation. 524 """ 525 pass # Currently unused
526
527 -class RLongI(omero.RLong):
528
529 - def __init__(self, value):
530 omero.RLong.__init__(self, long(value))
531
532 - def getValue(self, current = None):
533 return self._val
534
535 - def compare(self, rhs, current = None):
536 raise NotImplementedError("compare")
537
538 - def __eq__(self, obj):
539 if obj == None: 540 return False 541 elif obj is self: 542 return True 543 elif not isinstance(obj, omero.RLong): 544 return False 545 return obj._val == self._val
546
547 - def __ne__(self, obj):
548 return not self.__eq__(obj)
549
550 - def __hash__(self):
551 return hash(self._val)
552
553 - def __getattr__(self, attr):
554 if attr == "val": 555 return self.getValue() 556 else: 557 raise AttributeError(attr)
558
559 - def __setattr__(self, attr, value):
560 if attr == "val": 561 if self.__dict__.has_key("_val"): 562 raise omero.ClientError("Cannot write to val") 563 else: 564 self.__dict__["_val"] = value 565 else: 566 object.__setattr__(self, attr, value)
567
568 - def ice_postUnmarshal(self):
569 """ 570 Provides additional initialization once all data loaded 571 Required due to __getattr__ implementation. 572 """ 573 pass # Currently unused
574
575 - def ice_preMarshal(self):
576 """ 577 Provides additional validation before data is sent 578 Required due to __getattr__ implementation. 579 """ 580 pass # Currently unused
581
582 -class RTimeI(omero.RTime):
583
584 - def __init__(self, value):
585 omero.RTime.__init__(self, long(value))
586
587 - def getValue(self, current = None):
588 return self._val
589
590 - def compare(self, rhs, current = None):
591 raise NotImplementedError("compare")
592
593 - def __eq__(self, obj):
594 if obj == None: 595 return False 596 elif obj is self: 597 return True 598 elif not isinstance(obj, omero.RTime): 599 return False 600 return obj._val == self._val
601
602 - def __ne__(self, obj):
603 return not self.__eq__(obj)
604
605 - def __hash__(self):
606 return hash(self._val)
607
608 - def __getattr__(self, attr):
609 if attr == "val": 610 return self.getValue() 611 else: 612 raise AttributeError(attr)
613
614 - def __setattr__(self, attr, value):
615 if attr == "val": 616 if self.__dict__.has_key("_val"): 617 raise omero.ClientError("Cannot write to val") 618 else: 619 self.__dict__["_val"] = value 620 else: 621 object.__setattr__(self, attr, value)
622
623 - def ice_postUnmarshal(self):
624 """ 625 Provides additional initialization once all data loaded 626 Required due to __getattr__ implementation. 627 """ 628 pass # Currently unused
629
630 - def ice_preMarshal(self):
631 """ 632 Provides additional validation before data is sent 633 Required due to __getattr__ implementation. 634 """ 635 pass # Currently unused
636 637 # Implementations (objects) 638 # ========================================================================= 639
640 -class RInternalI(omero.RInternal):
641
642 - def __init__(self, value):
643 omero.RInternal.__init__(self, value)
644
645 - def getValue(self, current = None):
646 return self._val
647
648 - def compare(self, rhs, current = None):
649 raise NotImplementedError("compare")
650
651 - def __eq__(self, obj):
652 if obj == None: 653 return False 654 elif obj is self: 655 return True 656 elif not isinstance(obj, omero.RInternal): 657 return False 658 return obj._val == self._val
659
660 - def __ne__(self, obj):
661 return not self.__eq__(obj)
662
663 - def __hash__(self):
664 return hash(self._val)
665
666 - def __getattr__(self, attr):
667 if attr == "val": 668 return self.getValue() 669 else: 670 raise AttributeError(attr)
671
672 - def __setattr__(self, attr, value):
673 if attr == "val": 674 if self.__dict__.has_key("_val"): 675 raise omero.ClientError("Cannot write to val") 676 else: 677 self.__dict__["_val"] = value 678 else: 679 object.__setattr__(self, attr, value)
680
681 - def ice_postUnmarshal(self):
682 """ 683 Provides additional initialization once all data loaded 684 Required due to __getattr__ implementation. 685 """ 686 pass # Currently unused
687
688 - def ice_preMarshal(self):
689 """ 690 Provides additional validation before data is sent 691 Required due to __getattr__ implementation. 692 """ 693 pass # Currently unused
694
695 -class RObjectI(omero.RObject):
696
697 - def __init__(self, value):
698 omero.RObject.__init__(self, value)
699
700 - def getValue(self, current = None):
701 return self._val
702
703 - def compare(self, rhs, current = None):
704 raise NotImplementedError("compare")
705
706 - def __eq__(self, obj):
707 if obj == None: 708 return False 709 elif obj is self: 710 return True 711 elif not isinstance(obj, omero.RObject): 712 return False 713 return obj._val == self._val
714
715 - def __ne__(self, obj):
716 return not self.__eq__(obj)
717
718 - def __hash__(self):
719 return hash(self._val)
720
721 - def __getattr__(self, attr):
722 if attr == "val": 723 return self.getValue() 724 else: 725 raise AttributeError(attr)
726
727 - def __setattr__(self, attr, value):
728 if attr == "val": 729 if self.__dict__.has_key("_val"): 730 raise omero.ClientError("Cannot write to val") 731 else: 732 self.__dict__["_val"] = value 733 else: 734 object.__setattr__(self, attr, value)
735
736 - def ice_postUnmarshal(self):
737 """ 738 Provides additional initialization once all data loaded 739 Required due to __getattr__ implementation. 740 """ 741 pass # Currently unused
742
743 - def ice_preMarshal(self):
744 """ 745 Provides additional validation before data is sent 746 Required due to __getattr__ implementation. 747 """ 748 pass # Currently unused
749
750 -class RStringI(omero.RString):
751
752 - def __init__(self, value):
753 omero.RString.__init__(self, value)
754
755 - def getValue(self, current = None):
756 return self._val
757
758 - def compare(self, rhs, current = None):
759 raise NotImplementedError("compare")
760
761 - def __eq__(self, obj):
762 if obj == None: 763 return False 764 elif obj is self: 765 return True 766 elif not isinstance(obj, omero.RString): 767 return False 768 return obj._val == self._val
769
770 - def __ne__(self, obj):
771 return not self.__eq__(obj)
772
773 - def __hash__(self):
774 return hash(self._val)
775
776 - def __getattr__(self, attr):
777 if attr == "val": 778 return self.getValue() 779 else: 780 raise AttributeError(attr)
781
782 - def __setattr__(self, attr, value):
783 if attr == "val": 784 if self.__dict__.has_key("_val"): 785 raise omero.ClientError("Cannot write to val") 786 else: 787 self.__dict__["_val"] = value 788 else: 789 object.__setattr__(self, attr, value)
790
791 - def ice_postUnmarshal(self):
792 """ 793 Provides additional initialization once all data loaded 794 Required due to __getattr__ implementation. 795 """ 796 pass # Currently unused
797
798 - def ice_preMarshal(self):
799 """ 800 Provides additional validation before data is sent 801 Required due to __getattr__ implementation. 802 """ 803 pass # Currently unused
804
805 -class RClassI(omero.RClass):
806
807 - def __init__(self, value):
808 omero.RClass.__init__(self, value)
809
810 - def getValue(self, current = None):
811 return self._val
812
813 - def compare(self, rhs, current = None):
814 raise NotImplementedError("compare")
815
816 - def __eq__(self, obj):
817 if obj == None: 818 return False 819 elif obj is self: 820 return True 821 elif not isinstance(obj, omero.RClass): 822 return False 823 return obj._val == self._val
824
825 - def __ne__(self, obj):
826 return not self.__eq__(obj)
827
828 - def __hash__(self):
829 return hash(self._val)
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 # Implementations (collections) 861 # ========================================================================= 862
863 -class RArrayI(omero.RArray):
864 """ 865 Guaranteed to never contain an empty list. 866 """ 867
868 - def __init__(self, arg = None, *args):
869 if arg == None: 870 self._val = [] 871 elif not hasattr(arg, "__iter__"): 872 self._val = [arg] 873 else: 874 self._val = list(arg) 875 self._val.extend(args) 876 for v in self._val: 877 if not isinstance(v, omero.RType): 878 raise ValueError("Item of wrong type: %s" % type(v))
879
880 - def compare(self, rhs, current = None):
881 raise NotImplementedError("compare")
882
883 - def getValue(self, current = None):
884 return self._val
885
886 - def get(self, index, current = None):
887 return self._val[index]
888
889 - def size(self, current = None):
890 return len(self._val)
891
892 - def add(self, value, current = None):
893 self._val.append(value)
894
895 - def addAll(self, values, current = None):
896 self.val.append(values)
897
898 - def __eq__(self, obj):
899 if obj == None: 900 return False 901 elif self is obj: 902 return True 903 elif not isinstance(obj, omero.RArray): 904 return False 905 return self._val == obj._val
906
907 - def __ne__(self, obj):
908 return not self.__eq__(obj)
909
910 - def __hash__(self, obj):
911 """ 912 Not allowed. Hashing a list is not supported. 913 """ 914 return hash(self._val) # Throws an exception
915
916 - def __getattr__(self, attr):
917 if attr == "val": 918 return self.getValue() 919 else: 920 raise AttributeError(attr)
921
922 - def __setattr__(self, attr, value):
923 if attr == "val": 924 if self.__dict__.has_key("_val"): 925 raise omero.ClientError("Cannot write to val") 926 else: 927 self.__dict__["_val"] = value 928 else: 929 object.__setattr__(self, attr, value)
930
931 - def ice_postUnmarshal(self):
932 """ 933 Provides additional initialization once all data loaded 934 Required due to __getattr__ implementation. 935 """ 936 pass # Currently unused
937
938 - def ice_preMarshal(self):
939 """ 940 Provides additional validation before data is sent 941 Required due to __getattr__ implementation. 942 """ 943 pass # Currently unused
944
945 -class RListI(omero.RList):
946 """ 947 Guaranteed to never contain an empty list. 948 """ 949
950 - def __init__(self, arg = None, *args):
951 if arg == None: 952 self._val = [] 953 elif not hasattr(arg, "__iter__"): 954 self._val = [arg] 955 else: 956 self._val = list(arg) 957 self._val.extend(args) 958 for v in self._val: 959 if not isinstance(v, omero.RType): 960 raise ValueError("Item of wrong type: %s" % type(v))
961 962
963 - def compare(self, rhs, current = None):
964 raise NotImplementedError("compare")
965
966 - def getValue(self, current = None):
967 return self._val
968
969 - def get(self, index, current = None):
970 return self._val[index]
971
972 - def size(self, current = None):
973 return len(self._val)
974
975 - def add(self, value, current = None):
976 self._val.append(value)
977
978 - def addAll(self, values, current = None):
979 self.val.append(values)
980
981 - def __eq__(self, obj):
982 if obj == None: 983 return False 984 elif self is obj: 985 return True 986 elif not isinstance(obj, omero.RList): 987 return False 988 return self._val == obj._val
989
990 - def __ne__(self, obj):
991 return not self.__eq__(obj)
992
993 - def __hash__(self, obj):
994 """ 995 Not allowed. Hashing a list is not supported. 996 """ 997 return hash(self._val) # Throws an exception
998
999 - def __getattr__(self, attr):
1000 if attr == "val": 1001 return self.getValue() 1002 else: 1003 raise AttributeError(attr)
1004
1005 - def __setattr__(self, attr, value):
1006 if attr == "val": 1007 if self.__dict__.has_key("_val"): 1008 raise omero.ClientError("Cannot write to val") 1009 else: 1010 self.__dict__["_val"] = value 1011 else: 1012 object.__setattr__(self, attr, value)
1013
1014 - def ice_postUnmarshal(self):
1015 """ 1016 Provides additional initialization once all data loaded 1017 Required due to __getattr__ implementation. 1018 """ 1019 pass # Currently unused
1020
1021 - def ice_preMarshal(self):
1022 """ 1023 Provides additional validation before data is sent 1024 Required due to __getattr__ implementation. 1025 """ 1026 pass # Currently unused
1027
1028 -class RSetI(omero.RSet):
1029 """ 1030 Guaranteed to never contain an empty list. 1031 """ 1032
1033 - def __init__(self, arg = None, *args):
1034 if arg == None: 1035 self._val = [] 1036 elif not hasattr(arg, "__iter__"): 1037 self._val = [arg] 1038 else: 1039 self._val = list(arg) 1040 self._val.extend(args) 1041 for v in self._val: 1042 if not isinstance(v, omero.RType): 1043 raise ValueError("Item of wrong type: %s" % type(v))
1044 1045
1046 - def compare(self, rhs, current = None):
1047 raise NotImplementedError("compare")
1048
1049 - def getValue(self, current = None):
1050 return self._val
1051
1052 - def get(self, index, current = None):
1053 return self._val[index]
1054
1055 - def size(self, current = None):
1056 return len(self._val)
1057
1058 - def add(self, value, current = None):
1059 self._val.append(value)
1060
1061 - def addAll(self, values, current = None):
1062 self.val.append(values)
1063
1064 - def __eq__(self, obj):
1065 if obj == None: 1066 return False 1067 elif self is obj: 1068 return True 1069 elif not isinstance(obj, omero.RSet): 1070 return False 1071 return self._val == obj._val
1072
1073 - def __ne__(self, obj):
1074 return not self.__eq__(obj)
1075
1076 - def __hash__(self, obj):
1077 """ 1078 Not allowed. Hashing a list is not supported. 1079 """ 1080 return hash(self._val) # Throws an exception
1081
1082 - def __getattr__(self, attr):
1083 if attr == "val": 1084 return self.getValue() 1085 else: 1086 raise AttributeError(attr)
1087
1088 - def __setattr__(self, attr, value):
1089 if attr == "val": 1090 if self.__dict__.has_key("_val"): 1091 raise omero.ClientError("Cannot write to val") 1092 else: 1093 self.__dict__["_val"] = value 1094 else: 1095 object.__setattr__(self, attr, value)
1096
1097 - def ice_postUnmarshal(self):
1098 """ 1099 Provides additional initialization once all data loaded 1100 Required due to __getattr__ implementation. 1101 """ 1102 pass # Currently unused
1103
1104 - def ice_preMarshal(self):
1105 """ 1106 Provides additional validation before data is sent 1107 Required due to __getattr__ implementation. 1108 """ 1109 pass # Currently unused
1110
1111 -class RMapI(omero.RMap):
1112
1113 - def __init__(self, arg = None, **kwargs):
1114 if arg == None: 1115 self._val = {} 1116 else: 1117 self._val = dict(arg) # May throw an exception 1118 self._val.update(kwargs) 1119 self._validate()
1120
1121 - def _validate(self):
1122 for k, v in self._val.items(): 1123 if not isinstance(k, str): 1124 raise ValueError("Key of wrong type: %s" % type(k)) 1125 if v is not None and not isinstance(v, omero.RType): 1126 raise ValueError("Value of wrong type: %s" % type(v))
1127
1128 - def compare(self, rhs, current = None):
1129 raise NotImplementedError("compare")
1130
1131 - def getValue(self, current = None):
1132 return self._val
1133
1134 - def get(self, key, current = None):
1135 return self._val[key]
1136
1137 - def put(self, key, value, current = None):
1138 self._val[key] = value
1139
1140 - def size(self, current = None):
1141 return len(self._val)
1142
1143 - def __eq__(self, obj):
1144 if obj == None: 1145 return False 1146 elif self is obj: 1147 return True 1148 elif not isinstance(obj, omero.RMap): 1149 return False 1150 return self._val == obj._val
1151
1152 - def __ne__(self, obj):
1153 return not self.__eq__(obj)
1154
1155 - def __hash__(self, obj):
1156 """ 1157 Not allowed. Hashing a list is not supported. 1158 """ 1159 return hash(self._val) # Throws an exception
1160
1161 - def __getattr__(self, attr):
1162 if attr == "val": 1163 return self.getValue() 1164 else: 1165 raise AttributeError(attr)
1166
1167 - def __setattr__(self, attr, value):
1168 if attr == "val": 1169 if self.__dict__.has_key("_val"): 1170 raise omero.ClientError("Cannot write to val") 1171 else: 1172 self.__dict__["_val"] = value 1173 else: 1174 object.__setattr__(self, attr, value)
1175
1176 - def ice_postUnmarshal(self):
1177 """ 1178 Provides additional initialization once all data loaded 1179 Required due to __getattr__ implementation. 1180 """ 1181 pass # Currently unused
1182
1183 - def ice_preMarshal(self):
1184 """ 1185 Provides additional validation before data is sent 1186 Required due to __getattr__ implementation. 1187 """ 1188 pass # Currently unused
1189 1190 # Helpers 1191 # ======================================================================== 1192 1193 # Conversion classes are for omero.model <--> ome.model only (no python) 1194
1195 -class ObjectFactory(Ice.ObjectFactory):
1196
1197 - def __init__(self, cls, f):
1198 self.id = cls.ice_staticId() 1199 self.f = f
1200
1201 - def create(self, string):
1202 return self.f()
1203
1204 - def destroy(self):
1205 pass
1206
1207 - def register(self, ic):
1208 ic.addObjectFactory(self, self.id)
1209 1210 1211 # Shared state (flyweight) 1212 # ========================================================================= 1213 1214 rtrue = RBoolI(True) 1215 1216 rfalse = RBoolI(False) 1217 1218 rlong0 = RLongI(0) 1219 1220 rint0 = RIntI(0) 1221 1222 remptystr = RStringI("") 1223 1224 remptyclass = RClassI("") 1225 1226 rnullinternal = RInternalI(None) 1227 1228 rnullobject = RObjectI(None) 1229 1230 # Object factories 1231 # ========================================================================= 1232 1233 ObjectFactories = { 1234 RBoolI: ObjectFactory(RBoolI, lambda: RBoolI(False)), 1235 RDoubleI: ObjectFactory(RDoubleI, lambda: RDoubleI(0.0)), 1236 RFloatI: ObjectFactory(RFloatI, lambda: RFloatI(0.0)), 1237 RIntI: ObjectFactory(RIntI, lambda: RIntI(0)), 1238 RLongI: ObjectFactory(RLongI, lambda: RLongI(0)), 1239 RTimeI: ObjectFactory(RTimeI, lambda: RTimeI(0)), 1240 RClassI: ObjectFactory(RClassI, lambda: RClassI("")), 1241 RStringI: ObjectFactory(RStringI, lambda: RStringI("")), 1242 RInternalI: ObjectFactory(RInternalI, lambda: RInternalI(None)), 1243 RObjectI: ObjectFactory(RObjectI, lambda: RObjectI(None)), 1244 RArrayI: ObjectFactory(RArrayI, lambda: RArrayI()), 1245 RListI: ObjectFactory(RListI, lambda: RListI()), 1246 RSetI: ObjectFactory(RSetI, lambda: RSetI()), 1247 RMapI: ObjectFactory(RMapI, lambda: RMapI()) 1248 } 1249