227 | | repr(name)]) |
---|
| 325 | repr(name),]) |
---|
| 326 | |
---|
| 327 | def __setattr__(self,name,value): |
---|
| 328 | """ |
---|
| 329 | Protect variable values from overwriting. |
---|
| 330 | |
---|
| 331 | observation_instance.variable_name = variable_value |
---|
| 332 | |
---|
| 333 | But retrieve any other bound attribute values. |
---|
| 334 | |
---|
| 335 | >>> observation = Observation(good_observation,good_variables) |
---|
| 336 | >>> observation.z = 'OK' |
---|
| 337 | Traceback (most recent call last): |
---|
| 338 | ... |
---|
| 339 | AttributeError: Rebinding attribute 'z' disallowed in |
---|
| 340 | 'Observation' object |
---|
| 341 | >>> observation.y = 'OK' |
---|
| 342 | >>> observation.y |
---|
| 343 | 'OK' |
---|
| 344 | >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', |
---|
| 345 | ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', |
---|
| 346 | ... 'error':'0'} |
---|
| 347 | True |
---|
| 348 | """ |
---|
| 349 | |
---|
| 350 | if name in self: |
---|
| 351 | # Protect observation variables |
---|
| 352 | raise AttributeError, ' '.join(['Rebinding attribute', |
---|
| 353 | repr(name), |
---|
| 354 | 'disallowed in', |
---|
| 355 | repr(self.__class__.__name__), |
---|
| 356 | 'object',]) |
---|
| 357 | else: |
---|
| 358 | # Otherwise, do it the normal way. |
---|
| 359 | super(self.__class__, self).__setattr__(name,value) |
---|
| 360 | |
---|
| 361 | def __delattr__(self,name): |
---|
| 362 | """ |
---|
| 363 | Protect variable values from deletion. |
---|
| 364 | |
---|
| 365 | del observation_instance.variable_name |
---|
| 366 | |
---|
| 367 | But delete any other bound attribute values. |
---|
| 368 | |
---|
| 369 | >>> observation = Observation(good_observation,good_variables) |
---|
| 370 | >>> del observation.z |
---|
| 371 | Traceback (most recent call last): |
---|
| 372 | ... |
---|
| 373 | AttributeError: Unbinding attribute 'z' disallowed in |
---|
| 374 | 'Observation' object |
---|
| 375 | >>> del observation.y |
---|
| 376 | Traceback (most recent call last): |
---|
| 377 | ... |
---|
| 378 | AttributeError: 'Observation' object has no attribute 'y' |
---|
| 379 | >>> observation.y = 'OK' |
---|
| 380 | >>> del observation.y |
---|
| 381 | >>> del observation.y |
---|
| 382 | Traceback (most recent call last): |
---|
| 383 | ... |
---|
| 384 | AttributeError: y |
---|
| 385 | >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', |
---|
| 386 | ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', |
---|
| 387 | ... 'error':'0'} |
---|
| 388 | True |
---|
| 389 | """ |
---|
| 390 | |
---|
| 391 | if name in self: |
---|
| 392 | # Protect observation variables |
---|
| 393 | raise AttributeError, ' '.join(['Unbinding attribute', |
---|
| 394 | repr(name), |
---|
| 395 | 'disallowed in', |
---|
| 396 | repr(self.__class__.__name__), |
---|
| 397 | 'object',]) |
---|
| 398 | else: |
---|
| 399 | # Otherwise, do it the normal way. |
---|
| 400 | super(self.__class__, self).__delattr__(name) |
---|
| 401 | |
---|
| 402 | def __setitem__(self,key,value): |
---|
| 403 | """ |
---|
| 404 | Protect items. |
---|
| 405 | |
---|
| 406 | observation_instance[variable_name] = variable_value |
---|
| 407 | |
---|
| 408 | >>> observation = Observation(good_observation,good_variables) |
---|
| 409 | >>> observation['z'] = 'OK' |
---|
| 410 | Traceback (most recent call last): |
---|
| 411 | ... |
---|
| 412 | TypeError: 'Observation' object's items are read-only |
---|
| 413 | >>> observation['y'] = 'OK' |
---|
| 414 | Traceback (most recent call last): |
---|
| 415 | ... |
---|
| 416 | TypeError: 'Observation' object's items are read-only |
---|
| 417 | >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', |
---|
| 418 | ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', |
---|
| 419 | ... 'error':'0'} |
---|
| 420 | True |
---|
| 421 | """ |
---|
| 422 | |
---|
| 423 | raise TypeError, ' '.join([repr(self.__class__.__name__), |
---|
| 424 | 'object\'s items are read-only',]) |
---|
| 425 | |
---|
| 426 | def __delitem__(self,key): |
---|
| 427 | """ |
---|
| 428 | Protect items. |
---|
| 429 | |
---|
| 430 | observation_instance[variable_name] = variable_value |
---|
| 431 | |
---|
| 432 | >>> observation = Observation(good_observation,good_variables) |
---|
| 433 | >>> del observation['z'] |
---|
| 434 | Traceback (most recent call last): |
---|
| 435 | ... |
---|
| 436 | TypeError: 'Observation' object's items are read-only |
---|
| 437 | >>> del observation['y'] |
---|
| 438 | Traceback (most recent call last): |
---|
| 439 | ... |
---|
| 440 | TypeError: 'Observation' object's items are read-only |
---|
| 441 | >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', |
---|
| 442 | ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', |
---|
| 443 | ... 'error':'0'} |
---|
| 444 | True |
---|
| 445 | """ |
---|
| 446 | |
---|
| 447 | raise TypeError, ' '.join([repr(self.__class__.__name__), |
---|
| 448 | 'object\'s items are read-only',]) |
---|
| 449 | |
---|
| 450 | def clear(self): |
---|
| 451 | """ |
---|
| 452 | Protect items. |
---|
| 453 | |
---|
| 454 | >>> observation = Observation(good_observation,good_variables) |
---|
| 455 | >>> observation.clear() |
---|
| 456 | Traceback (most recent call last): |
---|
| 457 | ... |
---|
| 458 | TypeError: 'Observation' object's items are read-only |
---|
| 459 | >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', |
---|
| 460 | ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', |
---|
| 461 | ... 'error':'0'} |
---|
| 462 | True |
---|
| 463 | """ |
---|
| 464 | |
---|
| 465 | raise TypeError, ' '.join([repr(self.__class__.__name__), |
---|
| 466 | 'object\'s items are read-only',]) |
---|
| 467 | |
---|
| 468 | def pop(self,key,*args): |
---|
| 469 | """ |
---|
| 470 | Protect items. |
---|
| 471 | |
---|
| 472 | >>> observation = Observation(good_observation,good_variables) |
---|
| 473 | >>> observation.pop('z') |
---|
| 474 | Traceback (most recent call last): |
---|
| 475 | ... |
---|
| 476 | TypeError: 'Observation' object's items are read-only |
---|
| 477 | >>> observation.pop('y') |
---|
| 478 | Traceback (most recent call last): |
---|
| 479 | ... |
---|
| 480 | TypeError: 'Observation' object's items are read-only |
---|
| 481 | >>> observation.pop('y','OK') |
---|
| 482 | Traceback (most recent call last): |
---|
| 483 | ... |
---|
| 484 | TypeError: 'Observation' object's items are read-only |
---|
| 485 | >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', |
---|
| 486 | ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', |
---|
| 487 | ... 'error':'0'} |
---|
| 488 | True |
---|
| 489 | """ |
---|
| 490 | |
---|
| 491 | raise TypeError, ' '.join([repr(self.__class__.__name__), |
---|
| 492 | 'object\'s items are read-only',]) |
---|
| 493 | |
---|
| 494 | def popitem(self): |
---|
| 495 | """ |
---|
| 496 | Protect items. |
---|
| 497 | |
---|
| 498 | >>> observation = Observation(good_observation,good_variables) |
---|
| 499 | >>> observation.popitem() |
---|
| 500 | Traceback (most recent call last): |
---|
| 501 | ... |
---|
| 502 | TypeError: 'Observation' object's items are read-only |
---|
| 503 | >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', |
---|
| 504 | ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', |
---|
| 505 | ... 'error':'0'} |
---|
| 506 | True |
---|
| 507 | """ |
---|
| 508 | |
---|
| 509 | raise TypeError, ' '.join([repr(self.__class__.__name__), |
---|
| 510 | 'object\'s items are read-only',]) |
---|
| 511 | |
---|
| 512 | def setdefault(self,key,*args): |
---|
| 513 | """ |
---|
| 514 | Protect items. |
---|
| 515 | |
---|
| 516 | >>> observation = Observation(good_observation,good_variables) |
---|
| 517 | >>> observation.setdefault('z') |
---|
| 518 | Traceback (most recent call last): |
---|
| 519 | ... |
---|
| 520 | TypeError: 'Observation' object's items are read-only |
---|
| 521 | >>> observation.setdefault('y') |
---|
| 522 | Traceback (most recent call last): |
---|
| 523 | ... |
---|
| 524 | TypeError: 'Observation' object's items are read-only |
---|
| 525 | >>> observation.setdefault('y','OK') |
---|
| 526 | Traceback (most recent call last): |
---|
| 527 | ... |
---|
| 528 | TypeError: 'Observation' object's items are read-only |
---|
| 529 | >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', |
---|
| 530 | ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', |
---|
| 531 | ... 'error':'0'} |
---|
| 532 | True |
---|
| 533 | """ |
---|
| 534 | |
---|
| 535 | raise TypeError, ' '.join([repr(self.__class__.__name__), |
---|
| 536 | 'object\'s items are read-only',]) |
---|
| 537 | |
---|
| 538 | def update(self,*args,**kwargs): |
---|
| 539 | """ |
---|
| 540 | Protect items. |
---|
| 541 | |
---|
| 542 | >>> observation = Observation(good_observation,good_variables) |
---|
| 543 | >>> observation.update({'UP':'up','DOWN':'down',}) |
---|
| 544 | Traceback (most recent call last): |
---|
| 545 | ... |
---|
| 546 | TypeError: 'Observation' object's items are read-only |
---|
| 547 | >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', |
---|
| 548 | ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', |
---|
| 549 | ... 'error':'0'} |
---|
| 550 | True |
---|
| 551 | >>> observation.update((('UP','up'),('DOWN','down'),)) |
---|
| 552 | Traceback (most recent call last): |
---|
| 553 | ... |
---|
| 554 | TypeError: 'Observation' object's items are read-only |
---|
| 555 | >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', |
---|
| 556 | ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', |
---|
| 557 | ... 'error':'0'} |
---|
| 558 | True |
---|
| 559 | >>> observation.update(UP='up',DOWN='down') |
---|
| 560 | Traceback (most recent call last): |
---|
| 561 | ... |
---|
| 562 | TypeError: 'Observation' object's items are read-only |
---|
| 563 | >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', |
---|
| 564 | ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', |
---|
| 565 | ... 'error':'0'} |
---|
| 566 | True |
---|
| 567 | """ |
---|
| 568 | |
---|
| 569 | raise TypeError, ' '.join([repr(self.__class__.__name__), |
---|
| 570 | 'object\'s items are read-only',]) |
---|