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

Source Code for Module omero.rtypes

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