Changeset 1648

Show
Ignore:
Timestamp:
09/02/08 23:15:33 (3 months ago)
Author:
nick
Message:

Merged source:pyamf/branches/raise-python3.0-351

Fixes: #351
Author: nick
Reviewer: thijs

Location:
pyamf/trunk
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • pyamf/trunk

    • Property svn:mergeinfo
      •  

        old new  
        44/pyamf/branches/error-stacktrace-331:1624-1644 
        55/pyamf/branches/nan-failures-345:1624-1640 
         6/pyamf/branches/raise-python3.0-351:1642-1647 
        67/pyamf/branches/register_class-args-check-334:1542-1592 
        78/pyamf/branches/remoting-request-context-309-2:1595-1607 
        89/pyamf/branches/tempfile-338:1588-1596 
        910/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 
  • pyamf/trunk/pyamf/__init__.py

    r1608 r1648  
    200200            return self[k] 
    201201        except KeyError: 
    202             raise AttributeError('unknown attribute \'%s\'' % k) 
     202            raise AttributeError('Unknown attribute \'%s\'' % k) 
    203203 
    204204    def __setattr__(self, k, v): 
     
    316316        """ 
    317317        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") 
    319319 
    320320        self.metadata = ClassMetaData(metadata) 
     
    342342 
    343343            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__)) 
    346346 
    347347            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__)) 
    350350 
    351351        if 'dynamic' in self.metadata: 
    352352            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") 
    354354 
    355355        if 'static' in self.metadata: 
    356356            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") 
    358358 
    359359    def __call__(self, *args, **kwargs): 
     
    369369            elif type(self.klass) is types.ClassType: # classic class 
    370370                return util.make_classic_instance(self.klass) 
    371             raise TypeError, 'invalid class type %r' % self.klass 
     371            raise TypeError('Invalid class type %r' % self.klass) 
    372372         
    373373        return self.klass(*args, **kwargs) 
     
    467467            self.context = context 
    468468        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__)) 
    471471 
    472472    def readType(self): 
     
    491491            func = getattr(self, self.type_map[type]) 
    492492        except KeyError: 
    493             raise DecodeError, "Unsupported ActionScript type 0x%02x" % type 
     493            raise DecodeError("Unsupported ActionScript type 0x%02x" % type) 
    494494 
    495495        return func() 
     
    555555            self.context = context 
    556556        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__)) 
    559559 
    560560        self._write_elem_func_cache = {} 
     
    642642    """ 
    643643    if not callable(klass): 
    644         raise TypeError, "klass must be callable" 
     644        raise TypeError("klass must be callable") 
    645645 
    646646    if klass in CLASS_CACHE: 
    647         raise ValueError, "klass %s already registered" % klass 
     647        raise ValueError("klass %s already registered" % klass) 
    648648 
    649649    if alias is not None and alias in CLASS_CACHE.keys(): 
    650         raise ValueError, "alias '%s' already registered" % alias 
     650        raise ValueError("alias '%s' already registered" % alias) 
    651651 
    652652    # Check that the constructor of the class doesn't require any additonal 
     
    701701        del CLASS_CACHE[alias] 
    702702    except KeyError: 
    703         raise UnknownClassAlias, "Unknown alias %s" % alias 
     703        raise UnknownClassAlias("Unknown alias %s" % alias) 
    704704 
    705705def register_class_loader(loader): 
     
    717717    """ 
    718718    if not callable(loader): 
    719         raise TypeError, "loader must be callable" 
     719        raise TypeError("loader must be callable") 
    720720 
    721721    if loader in CLASS_LOADERS: 
    722         raise ValueError, "loader has already been registered" 
     722        raise ValueError("loader has already been registered") 
    723723 
    724724    CLASS_LOADERS.append(loader) 
     
    734734    """ 
    735735    if loader not in CLASS_LOADERS: 
    736         raise LookupError, "loader not found" 
     736        raise LookupError("loader not found") 
    737737 
    738738    del CLASS_LOADERS[CLASS_LOADERS.index(loader)] 
     
    749749    """ 
    750750    if mod_name is '': 
    751         raise ImportError, "Unable to import empty module" 
     751        raise ImportError("Unable to import empty module") 
    752752 
    753753    mod = __import__(mod_name) 
     
    794794            CLASS_CACHE[str(alias)] = klass 
    795795        else: 
    796             raise TypeError, "Expecting class type or ClassAlias from loader" 
     796            raise TypeError("Expecting class type or ClassAlias from loader") 
    797797 
    798798        return klass 
     
    819819 
    820820    # All available methods for finding the class have been exhausted 
    821     raise UnknownClassAlias, "Unknown alias %s" % alias 
     821    raise UnknownClassAlias("Unknown alias %s" % alias) 
    822822 
    823823def get_class_alias(klass): 
     
    849849        return load_class(klass) 
    850850 
    851     raise UnknownClassAlias, "Unknown alias %s" % klass 
     851    raise UnknownClassAlias("Unknown alias %s" % klass) 
    852852 
    853853def has_alias(obj): 
     
    935935        return amf3.Decoder 
    936936 
    937     raise ValueError, "Unknown encoding %s" % encoding 
     937    raise ValueError("Unknown encoding %s" % encoding) 
    938938 
    939939def get_encoder(encoding, data=None, context=None): 
     
    961961        return amf3.Encoder 
    962962 
    963     raise ValueError, "Unknown encoding %s" % encoding 
     963    raise ValueError("Unknown encoding %s" % encoding) 
    964964 
    965965def get_context(encoding): 
     
    987987        return amf3.Context 
    988988 
    989     raise ValueError, "Unknown encoding %s" % encoding 
     989    raise ValueError("Unknown encoding %s" % encoding) 
    990990 
    991991def flex_loader(alias): 
     
    10081008        return CLASS_CACHE[alias] 
    10091009    except KeyError: 
    1010         raise UnknownClassAlias, alias 
     1010        raise UnknownClassAlias(alias) 
    10111011 
    10121012register_class_loader(flex_loader) 
     
    10221022    def _check_type(type_): 
    10231023        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_) 
    10251025 
    10261026    if isinstance(type_, list): 
     
    10281028 
    10291029    if type_ in TYPE_MAP: 
    1030         raise KeyError, 'Type %r already exists' % type_ 
     1030        raise KeyError('Type %r already exists' % type_) 
    10311031 
    10321032    if isinstance(type_, types.TupleType): 
     
    10511051            return v 
    10521052 
    1053     raise KeyError, "Unknown type %r" % type_ 
     1053    raise KeyError("Unknown type %r" % type_) 
    10541054 
    10551055def remove_type(type_): 
     
    10861086 
    10871087    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") 
    10891089 
    10901090    mro = util.get_mro(klass) 
    10911091 
    10921092    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') 
    10941094 
    10951095    if code in ERROR_CLASS_MAP.keys(): 
    1096         raise ValueError, 'Code %s is already registered' % code 
     1096        raise ValueError('Code %s is already registered' % code) 
    10971097 
    10981098    ERROR_CLASS_MAP[code] = klass 
     
    11081108    if isinstance(klass, basestring): 
    11091109        if not klass in ERROR_CLASS_MAP.keys(): 
    1110             raise ValueError, 'Code %s is not registered' % klass 
     1110            raise ValueError('Code %s is not registered' % klass) 
    11111111    elif isinstance(klass, (type, types.ClassType)): 
    11121112        classes = ERROR_CLASS_MAP.values() 
    11131113        if not klass in classes: 
    1114             raise ValueError, 'Class %s is not registered' % klass 
     1114            raise ValueError('Class %s is not registered' % klass) 
    11151115 
    11161116        klass = ERROR_CLASS_MAP.keys()[classes.index(klass)] 
    11171117    else: 
    1118         raise TypeError, "Invalid type, expected class or string" 
     1118        raise TypeError("Invalid type, expected class or string") 
    11191119 
    11201120    del ERROR_CLASS_MAP[klass] 
  • pyamf/trunk/pyamf/amf0.py

    r1641 r1648  
    528528        @param  data: The data to be encoded to the AMF0 data stream. 
    529529 
     530        @raise EncodeError: Cannot find encoder func. 
    530531        @raise EncodeError: Unable to encode the data. 
    531532        """ 
     
    542543                raise 
    543544            except: 
    544                 raise pyamf.EncodeError, "Unable to encode '%r'" % (data,) 
     545                raise pyamf.EncodeError("Unable to encode '%r'" % (data,)) 
    545546 
    546547    def writeNull(self, n): 
  • pyamf/trunk/pyamf/amf3.py

    r1609 r1648  
    586586        if not hasattr(self, '_alias'): 
    587587            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') 
    589589 
    590590            self._alias = pyamf.load_class(self.alias) 
     
    877877 
    878878        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)) 
    880880 
    881881        return type 
     
    11071107 
    11081108        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") 
    11101110 
    11111111        if class_def.alias: 
     
    11261126            readStatic(class_ref, class_def, obj_attrs, num_attrs) 
    11271127        else: 
    1128             raise pyamf.DecodeError, "Unknown object encoding" 
     1128            raise pyamf.DecodeError("Unknown object encoding") 
    11291129 
    11301130        if hasattr(obj, '__setstate__'): 
     
    14841484                str_keys.append(x) 
    14851485            else: 
    1486                 raise ValueError, "Non int/str key value found in dict" 
     1486                raise ValueError("Non int/str key value found in dict") 
    14871487 
    14881488        # Make sure the integer keys are within range 
     
    15101510            # for more info 
    15111511            if x == '': 
    1512                 raise pyamf.EncodeError, "dicts cannot contain empty string keys" 
     1512                raise pyamf.EncodeError("dicts cannot contain empty string keys") 
    15131513 
    15141514            self._writeString(x) 
     
    15561556                        class_def.static_attrs.append(unicode(k)) 
    15571557                else: 
    1558                     raise pyamf.EncodeError, 'Unable to determine object attributes' 
     1558                    raise pyamf.EncodeError('Unable to determine object attributes') 
    15591559 
    15601560        return class_def 
     
    16101610 
    16111611            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") 
    16131613 
    16141614            if class_def.encoding != ObjectEncoding.EXTERNAL: 
     
    17351735    """ 
    17361736    if n & 0xf0000000 not in [0, 0xf0000000]: 
    1737         raise ValueError, "Out of range" 
     1737        raise OverflowError("Out of range") 
    17381738 
    17391739    bytes = '' 
  • pyamf/trunk/pyamf/remoting/__init__.py

    r1645 r1648  
    483483    """ 
    484484    if not isinstance(message, (Request, Response)): 
    485         raise TypeError, "Unknown message type" 
     485        raise TypeError("Unknown message type") 
    486486 
    487487    target = None 
     
    617617 
    618618    if strict and stream.remaining() > 0: 
    619         raise RuntimeError, "Unable to fully consume the buffer" 
     619        raise RuntimeError("Unable to fully consume the buffer") 
    620620 
    621621    return msg 
  • pyamf/trunk/pyamf/remoting/amf3.py

    r1571 r1648  
    102102            return self._processAsyncMessage(amf_request, ro_request, **kwargs) 
    103103        else: 
    104             raise ServerCallFailed, "Unknown request: %s" % ro_request 
     104            raise ServerCallFailed("Unknown request: %s" % ro_request) 
    105105 
    106106    def _processCommandMessage(self, amf_request, ro_request, **kwargs): 
     
    115115            return remoting.Response(ro_response) 
    116116        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") 
    118118        elif ro_request.operation == messaging.CommandMessage.DISCONNECT_OPERATION: 
    119119            return remoting.Response(ro_response) 
    120120        else: 
    121             raise ServerCallFailed, "Unknown Command operation %s" % ro_request.operation 
     121            raise ServerCallFailed("Unknown Command operation %s" % ro_request.operation) 
    122122 
    123123    def _processAsyncMessage(self, amf_request, ro_request, **kwargs): 
  • pyamf/trunk/pyamf/remoting/client/__init__.py

    r1610 r1648  
    160160        """ 
    161161        if not hasattr(self, '_result'): 
    162             raise AttributeError, "'RequestWrapper' object has no attribute 'result'" 
     162            raise AttributeError("'RequestWrapper' object has no attribute 'result'") 
    163163 
    164164        return self._result 
     
    256256            self.connection = httplib.HTTPSConnection(hostname, port) 
    257257        else: 
    258             raise ValueError, 'Unknown scheme' 
     258            raise ValueError('Unknown scheme') 
    259259 
    260260        self.logger.info('Creating connection to %s://%s:%s' % (self.url[0], 
     
    298298        """ 
    299299        if not isinstance(name, basestring): 
    300             raise TypeError, 'string type required' 
     300            raise TypeError('string type required') 
    301301 
    302302        return ServiceProxy(self, name, auto_execute) 
     
    312312                return request 
    313313 
    314         raise LookupError, "request %s not found" % id_ 
     314        raise LookupError("Request %s not found" % id_) 
    315315 
    316316    def addRequest(self, service, *args): 
     
    348348                return 
    349349 
    350         raise LookupError, "request not found" 
     350        raise LookupError("Request not found") 
    351351 
    352352    def getAMFRequest(self, requests): 
     
    446446 
    447447            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,)) 
    453453 
    454454        content_type = http_response.getheader('Content-Type') 
     
    457457            self.logger.debug('Body = %s' % http_response.read()) 
    458458 
    459             raise remoting.RemotingError, "Incorrect MIME type received. (got: %s)" % content_type 
     459            raise remoting.RemotingError("Incorrect MIME type received. (got: %s)" % content_type) 
    460460 
    461461        content_length = http_response.getheader('Content-Length') 
  • pyamf/trunk/pyamf/remoting/gateway/__init__.py

    r1571 r1648  
    8787 
    8888            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") 
    9191 
    9292            try: 
    9393                func = getattr(service, method) 
    9494            except AttributeError: 
    95                 raise UnknownServiceMethodError, \ 
    96                     "Unknown method %s" % str(method) 
     95                raise UnknownServiceMethodError( 
     96                    "Unknown method %s" % str(method)) 
    9797 
    9898            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)) 
    101101 
    102102            return func 
    103103 
    104104        if not callable(service): 
    105             raise UnknownServiceMethodError, \ 
    106                 "Unknown method %s" % str(self.service) 
     105            raise UnknownServiceMethodError( 
     106                "Unknown method %s" % str(self.service)) 
    107107 
    108108        return service 
     
    253253        preprocessor=None, debug=None): 
    254254        """ 
    255         @raise TypeError: The C{dict} type is required for C{services}. 
     255        @raise TypeError: C{dict} type is required for C{services}. 
    256256        """ 
    257257        self.logger = logging.instance_logger(self) 
     
    265265 
    266266        if not hasattr(services, 'iteritems'): 
    267             raise TypeError, "dict type required for services" 
     267            raise TypeError("dict type required for services") 
    268268 
    269269        for name, service in services.iteritems(): 
     
    284284        """ 
    285285        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") 
    287287 
    288288        allowed_types = (types.ModuleType, types.FunctionType, types.DictType, 
     
    290290 
    291291        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") 
    293293 
    294294        if name is None: 
     
    304304 
    305305        if name in self.services: 
    306             raise remoting.RemotingError, "Service %s already exists" % name 
     306            raise remoting.RemotingError("Service %s already exists" % name) 
    307307 
    308308        self.services[name] = ServiceWrapper(service, description, 
     
    318318        """ 
    319319        if service not in self.services: 
    320             raise NameError, "Service %s not found" % str(service) 
     320            raise NameError("Service %s not found" % str(service)) 
    321321 
    322322        for name, wrapper in self.services.iteritems(): 
     
    336336 
    337337        # shouldn't ever get here 
    338         raise RuntimeError, "Something went wrong ..." 
     338        raise RuntimeError("Something went wrong ...") 
    339339 
    340340    def getServiceRequest(self, request, target): 
     
    362362            pass 
    363363 
    364         raise UnknownServiceError, "Unknown service %s" % target 
     364        raise UnknownServiceError("Unknown service %s" % target) 
    365365 
    366366    def getProcessor(self, request): 
     
    502502    """ 
    503503    if not callable(func): 
    504         raise TypeError, "func must be callable" 
     504        raise TypeError('func must be callable') 
    505505 
    506506    if not callable(c): 
    507         raise TypeError, "authenticator must be callable" 
     507        raise TypeError('Authenticator must be callable')