Coder Social home page Coder Social logo

Comments (3)

charleseidsness avatar charleseidsness commented on July 19, 2024

Here's the code (from signature.pyx) ...

   31 cdef const char* _object_signature(object obj):                                                                                                
   32     cdef bytes signature = b''                                                                                                                 
   33                                                                                                                                                
   34     if obj is None:                                                                                                                            
   35         return signature                                                                                                                       
   36                                                                                                                                                
   37     if hasattr(obj, 'dbus_signature'):                                                                                                         
   38         return obj.dbus_signature.encode('utf-8')                                                                                              
   39                                                                                                                                                
   40     elif isinstance(obj, dict):                                                                                                                
   41         signature += signature_array                                                                                                           
   42         signature += signature_dict_begin                                                                                                      
   43         signature += _object_signature_basic(next(iter(obj.keys())))                                                                           
   44         signature += _object_signature(next(iter(obj.values())))                                                                               
   45         signature += signature_dict_end                                                                                                        
   46                                                                                                                                                
   47     elif isinstance(obj, list):                                                                                                                
   48         if all(isinstance(v, type(obj[0])) for v in obj):                                                                                      
   49             # if all the same type it's an array                                                                                               
   50             signature += signature_array                                                                                                       
   51             signature += _object_signature(obj[0])                                                                                             
   52         else:                                                                                                                                  
   53             # otherwise it's a struct                                                                                                          
   54             signature += signature_struct_begin                                                                                                
   55             for v in obj:                                                                                                                      
   56                 signature += _object_signature(v)                                                                                              
   57             signature += signature_struct_end                                                                                                  
   58                                                                                                                                                
   59     elif isinstance(obj, tuple):                                                                                                               
   60         signature += signature_struct_begin                                                                                                    
   61         for v in obj:                                                                                                                          
   62             signature += _object_signature(v)                                                                                                  
   63         signature += signature_struct_end                                                                                                      
   64                                                                                                                                                
   65     elif isinstance(obj, GenericMeta) and (obj.__extra__ == dict):                                                                             
   66         signature += signature_array                                                                                                           
   67         signature += signature_dict_begin                                                                                                      
   68         signature += _object_signature_basic(obj.__args__[0])                                                                                  
   69         signature += _object_signature(obj.__args__[1])                                                                                        
   70         signature += signature_dict_end                                                                                                        
   71                                                                                                                                                
   72     elif isinstance(obj, GenericMeta) and (obj.__extra__ == list):                                                                             
   73         signature += signature_array                                                                                                           
   74         signature += _object_signature(obj.__args__[0])                                                                                        
   75                                                                                                                                                
   76     elif isinstance(obj, TupleMeta) and (obj.__extra__ == tuple):                                                                              
   77         signature += signature_struct_begin                                                                                                    
   78         for v in obj.__args__:                                                                                                                 
   79             signature += _object_signature(v)                                                                                                  
   80         signature += signature_struct_end                                                                                                      
   81                                                                                                                                                
   82     else:                                                                                                                                      
   83         signature += _object_signature_basic(obj)                                                                                              
   84                                                                                                                                                
   85     return signature
   90 cdef bytes _dbus_signature(obj):                                                                                                               
   91     signature = _object_signature(obj)                                                                                                         
   92                                                                                                                                                
   93     if signature_invalid in signature:                                                                                                         
   94         raise TypeError(f"No D-Bus type equivalent for {obj}")                                                                                 
   95                                                                                                                                                
   96     return signature  
   98 def dbus_signature(obj):                                                                                                                       
   99     """Calculates a D-Bus Signature from a Python object or type.                                                                              
  100                                                                                                                                                
  101     Args:                                                                                                                                      
  102         obj (object or type): Python object or type,                                                                                           
  103             If the object has a dbus_signature attribute it will                                                                               
  104             be used, otherwise the object or type will be parsed                                                                               
  105             to calculate the D-Bus Signature.                                                                                                  
  106             Supports bool, int, str, float, bytes, and from the                                                                                
  107             typing library, List, Dict, and Tuple.                                                                                             
  108                                                                                                                                                
  109     Returns:                                                                                                                                   
  110         A string representing the D-Bus Signature.                                                                                             
  111                                                                                                                                                
  112     Raises:                                                                                                                                    
  113         TypeError: If no D-Bus Equivalent for objects type.                                                                                    
  114     """                                                                                                                                        
  115     signature = _dbus_signature(obj)                                                                                                           
  116                                                                                                                                                
  117     try:                                                                                                                                       
  118         return signature.decode()                                                                                                              
  119     except UnicodeDecodeError:                                                                                                                 
  120         # There is a memory management bug that rarely results in a Unicode Decode                                                             
  121         # error, this was added to get a little more info when it happens, but it                                                              
  122         # hasn't happened since this was added...                                                                                              
  123         import syslog                                                                                                                          
  124         syslog.syslog(f"==> {obj} === {signature}")                                                                                            
  125         raise 

from adbus.

charleseidsness avatar charleseidsness commented on July 19, 2024

Maybe line 91 needs to have the type defined, will define it and see.

from adbus.

charleseidsness avatar charleseidsness commented on July 19, 2024

Problem appears to be fixed.

from adbus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.