Encodes an object using the Cloud API Expression form. If _is_compound is True, this will fill the _scope and _encoded properties. Args: obj: The object to encode. Returns: If _is_compound is True, a string that is the key under which the encoded object is stored i
(self, obj: Any)
| 179 | return result |
| 180 | |
| 181 | def _encode_cloud_object(self, obj: Any) -> Any: |
| 182 | """Encodes an object using the Cloud API Expression form. |
| 183 | |
| 184 | If _is_compound is True, this will fill the _scope and _encoded properties. |
| 185 | |
| 186 | Args: |
| 187 | obj: The object to encode. |
| 188 | |
| 189 | Returns: |
| 190 | If _is_compound is True, a string that is the key under which the |
| 191 | encoded object is stored in _scope. |
| 192 | If _is_compound is False, the encoded object as a single quasi-Expression. |
| 193 | """ |
| 194 | obj_id = id(obj) |
| 195 | hashval = self._hashcache.get(obj_id) |
| 196 | reference = self._encoded.get(hashval, None) |
| 197 | if reference: |
| 198 | return reference |
| 199 | elif obj is None or isinstance(obj, (bool, str)): |
| 200 | result = {'constantValue': obj} |
| 201 | elif isinstance(obj, (float, int)): |
| 202 | result = _cloud_api_utils.encode_number_as_cloud_value(obj) |
| 203 | elif isinstance(obj, datetime.datetime): |
| 204 | # A raw date slipped through. Wrap it. Calling ee.Date from here would |
| 205 | # cause a circular dependency, so we encode it manually. |
| 206 | result = { |
| 207 | 'functionInvocationValue': { |
| 208 | 'functionName': 'Date', |
| 209 | 'arguments': { |
| 210 | 'value': { |
| 211 | 'constantValue': DatetimeToMicroseconds(obj) / 1e3 |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | elif isinstance(obj, encodable.Encodable): |
| 217 | # Some objects know how to encode themselves. |
| 218 | result = obj.encode_cloud_value(self._encode_cloud_object) |
| 219 | elif isinstance(obj, (list, tuple)): |
| 220 | # Lists are encoded recursively. |
| 221 | if self._is_compound: |
| 222 | result = { |
| 223 | 'arrayValue': { |
| 224 | 'values': [{ |
| 225 | 'valueReference': self._encode_cloud_object(i) |
| 226 | } for i in obj] |
| 227 | } |
| 228 | } |
| 229 | else: |
| 230 | result = { |
| 231 | 'arrayValue': { |
| 232 | 'values': [self._encode_cloud_object(i) for i in obj] |
| 233 | } |
| 234 | } |
| 235 | elif isinstance(obj, dict): |
| 236 | # Dictionary are encoded recursively and wrapped in a type specifier. |
| 237 | # We iterate through the entries in a deterministic order, not because it |
| 238 | # affects the order of the entries in the output result, but because it |
no test coverage detected