Comments (3)
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.
Maybe line 91 needs to have the type defined, will define it and see.
from adbus.
Problem appears to be fixed.
from adbus.
Related Issues (20)
- Please document why the library wants Python >= 3.7. HOT 5
- adbus.sdbus.SdbusError: Failed to enter array b'y' HOT 3
- Segfault in __pyx_f_5adbus_5sdbus_call_callback HOT 11
- Invalid read of size 1 in message.pyx HOT 1
- Python 3.5 compatibility? HOT 2
- NoReply: Method call timed out HOT 13
- Typing problem in `signal2` in the Readme server example code HOT 1
- `depreciated` and `deprectiated` parameters/properties should be spelled `deprecated` HOT 2
- Active Listen object is garbage collected HOT 3
- Failed to read value with signature s HOT 10
- new release HOT 1
- systemd dbus activation timeout on first try HOT 3
- travis integration is broken HOT 5
- Watch signal events HOT 2
- getting error while installing on ubuntu HOT 5
- dbus service thread count HOT 5
- Exception caused by typing issue when running example code HOT 2
- DepreciationWarning Python 3.8 HOT 2
- Dbus server method with an unsigned int HOT 5
- Cython compile type errors when trying to install adbus HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adbus.