Changeset 1648
- Timestamp:
- 09/02/08 23:15:33 (3 months ago)
- Location:
- pyamf/trunk
- Files:
-
- 12 modified
-
. (modified) (1 prop)
-
pyamf/__init__.py (modified) (24 diffs)
-
pyamf/amf0.py (modified) (2 diffs)
-
pyamf/amf3.py (modified) (9 diffs)
-
pyamf/remoting/__init__.py (modified) (2 diffs)
-
pyamf/remoting/amf3.py (modified) (2 diffs)
-
pyamf/remoting/client/__init__.py (modified) (7 diffs)
-
pyamf/remoting/gateway/__init__.py (modified) (12 diffs)
-
pyamf/sol.py (modified) (7 diffs)
-
pyamf/tests/test_gateway.py (modified) (3 diffs)
-
pyamf/util/__init__.py (modified) (3 diffs)
-
pyamf/util/imports.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pyamf/trunk
- Property svn:mergeinfo
-
old new 4 4 /pyamf/branches/error-stacktrace-331:1624-1644 5 5 /pyamf/branches/nan-failures-345:1624-1640 6 /pyamf/branches/raise-python3.0-351:1642-1647 6 7 /pyamf/branches/register_class-args-check-334:1542-1592 7 8 /pyamf/branches/remoting-request-context-309-2:1595-1607 8 9 /pyamf/branches/tempfile-338:1588-1596 9 10 /pyamf/branches/win-sol-test-failures-344:1624-1645 10 /pyamf/trunk:1525-1526,1541,1583-1587,1594 11 /pyamf/trunk:1525-1526,1541,1583-1587,1594,1624-1641
-
- Property svn:mergeinfo
-
pyamf/trunk/pyamf/__init__.py
r1608 r1648 200 200 return self[k] 201 201 except KeyError: 202 raise AttributeError(' unknown attribute \'%s\'' % k)202 raise AttributeError('Unknown attribute \'%s\'' % k) 203 203 204 204 def __setattr__(self, k, v): … … 316 316 """ 317 317 if not isinstance(klass, (type, types.ClassType)): 318 raise TypeError , "klass must be a class type"318 raise TypeError("klass must be a class type") 319 319 320 320 self.metadata = ClassMetaData(metadata) … … 342 342 343 343 if not isinstance(klass.__readamf__, types.UnboundMethodType): 344 raise TypeError ,"%s.__readamf__ must be callable" % (345 klass.__name__) 344 raise TypeError("%s.__readamf__ must be callable" % ( 345 klass.__name__)) 346 346 347 347 if not isinstance(klass.__writeamf__, types.UnboundMethodType): 348 raise TypeError ,"%s.__writeamf__ must be callable" % (349 klass.__name__) 348 raise TypeError("%s.__writeamf__ must be callable" % ( 349 klass.__name__)) 350 350 351 351 if 'dynamic' in self.metadata: 352 352 if attr_func is not None and not callable(attr_func): 353 raise TypeError , "attr_func must be callable"353 raise TypeError("attr_func must be callable") 354 354 355 355 if 'static' in self.metadata: 356 356 if attrs is None: 357 raise ValueError , "attrs keyword must be specified for static classes"357 raise ValueError("attrs keyword must be specified for static classes") 358 358 359 359 def __call__(self, *args, **kwargs): … … 369 369 elif type(self.klass) is types.ClassType: # classic class 370 370 return util.make_classic_instance(self.klass) 371 raise TypeError , 'invalid class type %r' % self.klass371 raise TypeError('Invalid class type %r' % self.klass) 372 372 373 373 return self.klass(*args, **kwargs) … … 467 467 self.context = context 468 468 else: 469 raise TypeError ,"context must be of type %s.%s" % (470 self.context_class.__module__, self.context_class.__name__) 469 raise TypeError("context must be of type %s.%s" % ( 470 self.context_class.__module__, self.context_class.__name__)) 471 471 472 472 def readType(self): … … 491 491 func = getattr(self, self.type_map[type]) 492 492 except KeyError: 493 raise DecodeError , "Unsupported ActionScript type 0x%02x" % type493 raise DecodeError("Unsupported ActionScript type 0x%02x" % type) 494 494 495 495 return func() … … 555 555 self.context = context 556 556 else: 557 raise TypeError ,"context must be of type %s.%s" % (558 self.context_class.__module__, self.context_class.__name__) 557 raise TypeError("context must be of type %s.%s" % ( 558 self.context_class.__module__, self.context_class.__name__)) 559 559 560 560 self._write_elem_func_cache = {} … … 642 642 """ 643 643 if not callable(klass): 644 raise TypeError , "klass must be callable"644 raise TypeError("klass must be callable") 645 645 646 646 if klass in CLASS_CACHE: 647 raise ValueError , "klass %s already registered" % klass647 raise ValueError("klass %s already registered" % klass) 648 648 649 649 if alias is not None and alias in CLASS_CACHE.keys(): 650 raise ValueError , "alias '%s' already registered" % alias650 raise ValueError("alias '%s' already registered" % alias) 651 651 652 652 # Check that the constructor of the class doesn't require any additonal … … 701 701 del CLASS_CACHE[alias] 702 702 except KeyError: 703 raise UnknownClassAlias , "Unknown alias %s" % alias703 raise UnknownClassAlias("Unknown alias %s" % alias) 704 704 705 705 def register_class_loader(loader): … … 717 717 """ 718 718 if not callable(loader): 719 raise TypeError , "loader must be callable"719 raise TypeError("loader must be callable") 720 720 721 721 if loader in CLASS_LOADERS: 722 raise ValueError , "loader has already been registered"722 raise ValueError("loader has already been registered") 723 723 724 724 CLASS_LOADERS.append(loader) … … 734 734 """ 735 735 if loader not in CLASS_LOADERS: 736 raise LookupError , "loader not found"736 raise LookupError("loader not found") 737 737 738 738 del CLASS_LOADERS[CLASS_LOADERS.index(loader)] … … 749 749 """ 750 750 if mod_name is '': 751 raise ImportError , "Unable to import empty module"751 raise ImportError("Unable to import empty module") 752 752 753 753 mod = __import__(mod_name) … … 794 794 CLASS_CACHE[str(alias)] = klass 795 795 else: 796 raise TypeError , "Expecting class type or ClassAlias from loader"796 raise TypeError("Expecting class type or ClassAlias from loader") 797 797 798 798 return klass … … 819 819 820 820 # All available methods for finding the class have been exhausted 821 raise UnknownClassAlias , "Unknown alias %s" % alias821 raise UnknownClassAlias("Unknown alias %s" % alias) 822 822 823 823 def get_class_alias(klass): … … 849 849 return load_class(klass) 850 850 851 raise UnknownClassAlias , "Unknown alias %s" % klass851 raise UnknownClassAlias("Unknown alias %s" % klass) 852 852 853 853 def has_alias(obj): … … 935 935 return amf3.Decoder 936 936 937 raise ValueError , "Unknown encoding %s" % encoding937 raise ValueError("Unknown encoding %s" % encoding) 938 938 939 939 def get_encoder(encoding, data=None, context=None): … … 961 961 return amf3.Encoder 962 962 963 raise ValueError , "Unknown encoding %s" % encoding963 raise ValueError("Unknown encoding %s" % encoding) 964 964 965 965 def get_context(encoding): … … 987 987 return amf3.Context 988 988 989 raise ValueError , "Unknown encoding %s" % encoding989 raise ValueError("Unknown encoding %s" % encoding) 990 990 991 991 def flex_loader(alias): … … 1008 1008 return CLASS_CACHE[alias] 1009 1009 except KeyError: 1010 raise UnknownClassAlias , alias1010 raise UnknownClassAlias(alias) 1011 1011 1012 1012 register_class_loader(flex_loader) … … 1022 1022 def _check_type(type_): 1023 1023 if not (isinstance(type_, (type, types.ClassType)) or callable(type_)): 1024 raise TypeError , "Unable to add '%r' as a custom type (expected a class or callable)" % type_1024 raise TypeError("Unable to add '%r' as a custom type (expected a class or callable)" % type_) 1025 1025 1026 1026 if isinstance(type_, list): … … 1028 1028 1029 1029 if type_ in TYPE_MAP: 1030 raise KeyError , 'Type %r already exists' % type_1030 raise KeyError('Type %r already exists' % type_) 1031 1031 1032 1032 if isinstance(type_, types.TupleType): … … 1051 1051 return v 1052 1052 1053 raise KeyError , "Unknown type %r" % type_1053 raise KeyError("Unknown type %r" % type_) 1054 1054 1055 1055 def remove_type(type_): … … 1086 1086 1087 1087 if not isinstance(klass, (type, types.ClassType)): 1088 raise TypeError , "klass must be a class type"1088 raise TypeError("klass must be a class type") 1089 1089 1090 1090 mro = util.get_mro(klass) 1091 1091 1092 1092 if not Exception in mro: 1093 raise TypeError , 'error classes must subclass the __builtin__.Exception class'1093 raise TypeError('Error classes must subclass the __builtin__.Exception class') 1094 1094 1095 1095 if code in ERROR_CLASS_MAP.keys(): 1096 raise ValueError , 'Code %s is already registered' % code1096 raise ValueError('Code %s is already registered' % code) 1097 1097 1098 1098 ERROR_CLASS_MAP[code] = klass … … 1108 1108 if isinstance(klass, basestring): 1109 1109 if not klass in ERROR_CLASS_MAP.keys(): 1110 raise ValueError , 'Code %s is not registered' % klass1110 raise ValueError('Code %s is not registered' % klass) 1111 1111 elif isinstance(klass, (type, types.ClassType)): 1112 1112 classes = ERROR_CLASS_MAP.values() 1113 1113 if not klass in classes: 1114 raise ValueError , 'Class %s is not registered' % klass1114 raise ValueError('Class %s is not registered' % klass) 1115 1115 1116 1116 klass = ERROR_CLASS_MAP.keys()[classes.index(klass)] 1117 1117 else: 1118 raise TypeError , "Invalid type, expected class or string"1118 raise TypeError("Invalid type, expected class or string") 1119 1119 1120 1120 del ERROR_CLASS_MAP[klass] -
pyamf/trunk/pyamf/amf0.py
r1641 r1648 528 528 @param data: The data to be encoded to the AMF0 data stream. 529 529 530 @raise EncodeError: Cannot find encoder func. 530 531 @raise EncodeError: Unable to encode the data. 531 532 """ … … 542 543 raise 543 544 except: 544 raise pyamf.EncodeError , "Unable to encode '%r'" % (data,)545 raise pyamf.EncodeError("Unable to encode '%r'" % (data,)) 545 546 546 547 def writeNull(self, n): -
pyamf/trunk/pyamf/amf3.py
r1609 r1648 586 586 if not hasattr(self, '_alias'): 587 587 if self.name == '': 588 raise pyamf.UnknownClassAlias , 'Anonymous class definitions do not have class aliases'588 raise pyamf.UnknownClassAlias('Anonymous class definitions do not have class aliases') 589 589 590 590 self._alias = pyamf.load_class(self.alias) … … 877 877 878 878 if type not in ACTIONSCRIPT_TYPES: 879 raise pyamf.DecodeError , "Unknown AMF3 type 0x%02x at %d" % (type, self.stream.tell() - 1)879 raise pyamf.DecodeError("Unknown AMF3 type 0x%02x at %d" % (type, self.stream.tell() - 1)) 880 880 881 881 return type … … 1107 1107 1108 1108 if class_def.alias and 'amf0' in class_def.alias.metadata: 1109 raise pyamf.EncodeError , "Decoding an object in amf3 tagged as amf0 only is not allowed"1109 raise pyamf.EncodeError("Decoding an object in amf3 tagged as amf0 only is not allowed") 1110 1110 1111 1111 if class_def.alias: … … 1126 1126 readStatic(class_ref, class_def, obj_attrs, num_attrs) 1127 1127 else: 1128 raise pyamf.DecodeError , "Unknown object encoding"1128 raise pyamf.DecodeError("Unknown object encoding") 1129 1129 1130 1130 if hasattr(obj, '__setstate__'): … … 1484 1484 str_keys.append(x) 1485 1485 else: 1486 raise ValueError , "Non int/str key value found in dict"1486 raise ValueError("Non int/str key value found in dict") 1487 1487 1488 1488 # Make sure the integer keys are within range … … 1510 1510 # for more info 1511 1511 if x == '': 1512 raise pyamf.EncodeError , "dicts cannot contain empty string keys"1512 raise pyamf.EncodeError("dicts cannot contain empty string keys") 1513 1513 1514 1514 self._writeString(x) … … 1556 1556 class_def.static_attrs.append(unicode(k)) 1557 1557 else: 1558 raise pyamf.EncodeError , 'Unable to determine object attributes'1558 raise pyamf.EncodeError('Unable to determine object attributes') 1559 1559 1560 1560 return class_def … … 1610 1610 1611 1611 if class_def.alias and 'amf0' in class_def.alias.metadata: 1612 raise pyamf.EncodeError , "Encoding an object in amf3 tagged as amf0 only"1612 raise pyamf.EncodeError("Encoding an object in amf3 tagged as amf0 only") 1613 1613 1614 1614 if class_def.encoding != ObjectEncoding.EXTERNAL: … … 1735 1735 """ 1736 1736 if n & 0xf0000000 not in [0, 0xf0000000]: 1737 raise ValueError, "Out of range"1737 raise OverflowError("Out of range") 1738 1738 1739 1739 bytes = '' -
pyamf/trunk/pyamf/remoting/__init__.py
r1645 r1648 483 483 """ 484 484 if not isinstance(message, (Request, Response)): 485 raise TypeError , "Unknown message type"485 raise TypeError("Unknown message type") 486 486 487 487 target = None … … 617 617 618 618 if strict and stream.remaining() > 0: 619 raise RuntimeError , "Unable to fully consume the buffer"619 raise RuntimeError("Unable to fully consume the buffer") 620 620 621 621 return msg -
pyamf/trunk/pyamf/remoting/amf3.py
r1571 r1648 102 102 return self._processAsyncMessage(amf_request, ro_request, **kwargs) 103 103 else: 104 raise ServerCallFailed , "Unknown request: %s" % ro_request104 raise ServerCallFailed("Unknown request: %s" % ro_request) 105 105 106 106 def _processCommandMessage(self, amf_request, ro_request, **kwargs): … … 115 115 return remoting.Response(ro_response) 116 116 elif ro_request.operation == messaging.CommandMessage.LOGIN_OPERATION: 117 raise ServerCallFailed , "Authorization is not supported in RemoteObject"117 raise ServerCallFailed("Authorization is not supported in RemoteObject") 118 118 elif ro_request.operation == messaging.CommandMessage.DISCONNECT_OPERATION: 119 119 return remoting.Response(ro_response) 120 120 else: 121 raise ServerCallFailed , "Unknown Command operation %s" % ro_request.operation121 raise ServerCallFailed("Unknown Command operation %s" % ro_request.operation) 122 122 123 123 def _processAsyncMessage(self, amf_request, ro_request, **kwargs): -
pyamf/trunk/pyamf/remoting/client/__init__.py
r1610 r1648 160 160 """ 161 161 if not hasattr(self, '_result'): 162 raise AttributeError , "'RequestWrapper' object has no attribute 'result'"162 raise AttributeError("'RequestWrapper' object has no attribute 'result'") 163 163 164 164 return self._result … … 256 256 self.connection = httplib.HTTPSConnection(hostname, port) 257 257 else: 258 raise ValueError , 'Unknown scheme'258 raise ValueError('Unknown scheme') 259 259 260 260 self.logger.info('Creating connection to %s://%s:%s' % (self.url[0], … … 298 298 """ 299 299 if not isinstance(name, basestring): 300 raise TypeError , 'string type required'300 raise TypeError('string type required') 301 301 302 302 return ServiceProxy(self, name, auto_execute) … … 312 312 return request 313 313 314 raise LookupError , "request %s not found" % id_314 raise LookupError("Request %s not found" % id_) 315 315 316 316 def addRequest(self, service, *args): … … 348 348 return 349 349 350 raise LookupError , "request not found"350 raise LookupError("Request not found") 351 351 352 352 def getAMFRequest(self, requests): … … 446 446 447 447 if hasattr(httplib, 'responses'): 448 raise remoting.RemotingError ,"HTTP Gateway reported status %d %s" % (449 http_response.status, httplib.responses[http_response.status]) 450 451 raise remoting.RemotingError ,"HTTP Gateway reported status %d" % (452 http_response.status,) 448 raise remoting.RemotingError("HTTP Gateway reported status %d %s" % ( 449 http_response.status, httplib.responses[http_response.status])) 450 451 raise remoting.RemotingError("HTTP Gateway reported status %d" % ( 452 http_response.status,)) 453 453 454 454 content_type = http_response.getheader('Content-Type') … … 457 457 self.logger.debug('Body = %s' % http_response.read()) 458 458 459 raise remoting.RemotingError , "Incorrect MIME type received. (got: %s)" % content_type459 raise remoting.RemotingError("Incorrect MIME type received. (got: %s)" % content_type) 460 460 461 461 content_length = http_response.getheader('Content-Length') -
pyamf/trunk/pyamf/remoting/gateway/__init__.py
r1571 r1648 87 87 88 88 if method.startswith('_'): 89 raise InvalidServiceMethodError , \90 "Calls to private methods are not allowed" 89 raise InvalidServiceMethodError( 90 "Calls to private methods are not allowed") 91 91 92 92 try: 93 93 func = getattr(service, method) 94 94 except AttributeError: 95 raise UnknownServiceMethodError , \96 "Unknown method %s" % str(method) 95 raise UnknownServiceMethodError( 96 "Unknown method %s" % str(method)) 97 97 98 98 if not callable(func): 99 raise InvalidServiceMethodError , \100 "Service method %s must be callable" % str(method) 99 raise InvalidServiceMethodError( 100 "Service method %s must be callable" % str(method)) 101 101 102 102 return func 103 103 104 104 if not callable(service): 105 raise UnknownServiceMethodError , \106 "Unknown method %s" % str(self.service) 105 raise UnknownServiceMethodError( 106 "Unknown method %s" % str(self.service)) 107 107 108 108 return service … … 253 253 preprocessor=None, debug=None): 254 254 """ 255 @raise TypeError: TheC{dict} type is required for C{services}.255 @raise TypeError: C{dict} type is required for C{services}. 256 256 """ 257 257 self.logger = logging.instance_logger(self) … … 265 265 266 266 if not hasattr(services, 'iteritems'): 267 raise TypeError , "dict type required for services"267 raise TypeError("dict type required for services") 268 268 269 269 for name, service in services.iteritems(): … … 284 284 """ 285 285 if isinstance(service, (int, long, float, basestring)): 286 raise TypeError , "service cannot be a scalar value"286 raise TypeError("Service cannot be a scalar value") 287 287 288 288 allowed_types = (types.ModuleType, types.FunctionType, types.DictType, … … 290 290 291 291 if not callable(service) and not isinstance(service, allowed_types): 292 raise TypeError , "service must be callable, a module, or an object"292 raise TypeError("Service must be a callable, module, or an object") 293 293 294 294 if name is None: … … 304 304 305 305 if name in self.services: 306 raise remoting.RemotingError , "Service %s already exists" % name306 raise remoting.RemotingError("Service %s already exists" % name) 307 307 308 308 self.services[name] = ServiceWrapper(service, description, … … 318 318 """ 319 319 if service not in self.services: 320 raise NameError , "Service %s not found" % str(service)320 raise NameError("Service %s not found" % str(service)) 321 321 322 322 for name, wrapper in self.services.iteritems(): … … 336 336 337 337 # shouldn't ever get here 338 raise RuntimeError , "Something went wrong ..."338 raise RuntimeError("Something went wrong ...") 339 339 340 340 def getServiceRequest(self, request, target): … … 362 362 pass 363 363 364 raise UnknownServiceError , "Unknown service %s" % target364 raise UnknownServiceError("Unknown service %s" % target) 365 365 366 366 def getProcessor(self, request): … … 502 502 """ 503 503 if not callable(func): 504 raise TypeError , "func must be callable"504 raise TypeError('func must be callable') 505 505 506 506 if not callable(c): 507 raise TypeError , "authenticator must be callable"507 raise TypeError('Authenticator must be callable')
