MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / unpack_response

Function unpack_response

src/ext/makerbot_driver/Encoder/Coding.py:122–136  ·  view source on GitHub ↗

Attempt to unpack the given data using the specified format. Throws a protocol error if the unpacking fails. @param format Format string to use for unpacking @param data Data to unpack. We _cannot_ unpack strings! @return list of values unpacked, if successful.

(format, data)

Source from the content-addressed store, hash-verified

120
121
122def unpack_response(format, data):
123 """
124 Attempt to unpack the given data using the specified format. Throws a protocol
125 error if the unpacking fails.
126
127 @param format Format string to use for unpacking
128 @param data Data to unpack. We _cannot_ unpack strings!
129 @return list of values unpacked, if successful.
130 """
131
132 try:
133 return struct.unpack(format, buffer(data))
134 except struct.error as e:
135 raise makerbot_driver.errors.ProtocolError("Unexpected data returned from machine. Expected length=%i, got=%i, error=%s" %
136 (struct.calcsize(format), len(data), str(e)))
137
138
139def unpack_response_with_string(format, data):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected