Beispiel #1
0
 def _to_ion_nature(obj):
     out = obj
     if not isinstance(out, _IonNature):
         ion_type = _ion_type(out)
         out = _FROM_ION_TYPE[ion_type].from_value(ion_type, out)
     if isinstance(out, dict):
         update = {}
         for field, value in six.iteritems(out):
             update[field] = _to_ion_nature(value)
         update = IonPyDict.from_value(out.ion_type, update, out.ion_annotations)
         out = update
     elif isinstance(out, list):
         update = []
         for value in out:
             update.append(_to_ion_nature(value))
         update = IonPyList.from_value(out.ion_type, update, out.ion_annotations)
         out = update
     return out
Beispiel #2
0
 def _to_ion_nature(obj):
     out = obj
     if not isinstance(out, _IonNature):
         ion_type = _ion_type(out)
         out = _FROM_ION_TYPE[ion_type].from_value(ion_type, out)
     if isinstance(out, dict):
         update = {}
         for field, value in six.iteritems(out):
             update[field] = _to_ion_nature(value)
         update = IonPyDict.from_value(out.ion_type, update,
                                       out.ion_annotations)
         out = update
     elif isinstance(out, list):
         update = []
         for value in out:
             update.append(_to_ion_nature(value))
         update = IonPyList.from_value(out.ion_type, update,
                                       out.ion_annotations)
         out = update
     return out
Beispiel #3
0
         [
             IonPyList.from_value(IonType.SEXP, [0]),
         ],
         _Expected(
             bytes_of([
                 0xC0 | 0x01,  # Int value 0 fits in 1 byte.
                 ION_ENCODED_INT_ZERO
             ]),
             b'(0)')),
 ),
 IonType.STRUCT: (
     ([
         {},
     ], _Expected(b'\xD0', b'{}')),
     ([
         IonPyDict.from_value(IonType.STRUCT, {}),
     ], _Expected(b'\xD0', b'{}')),
     (
         [
             {
                 u'foo': 0
             },
         ],
         _Expected(
             bytes_of([
                 0xDE,  # The lower nibble may vary. It does not indicate actual length unless it's 0.
                 VARUINT_END_BYTE
                 | 2,  # Field name 10 and value 0 each fit in 1 byte.
                 VARUINT_END_BYTE | 10,
                 ION_ENCODED_INT_ZERO
             ]),
Beispiel #4
0
         _Expected(
             bytes_of([
                 0xC0 | 0x01,  # Int value 0 fits in 1 byte.
                 ION_ENCODED_INT_ZERO
             ]),
             b'(0)'
         )
     ),
 ),
 IonType.STRUCT: (
     (
         [{}, ],
         _Expected(b'\xD0', b'{}')
     ),
     (
         [IonPyDict.from_value(IonType.STRUCT, {}), ],
         _Expected(b'\xD0', b'{}')
     ),
     (
         [{u'foo': 0}, ],
         _Expected(
             bytes_of([
                 0xDE,  # The lower nibble may vary. It does not indicate actual length unless it's 0.
                 VARUINT_END_BYTE | 2,  # Field name 10 and value 0 each fit in 1 byte.
                 VARUINT_END_BYTE | 10,
                 ION_ENCODED_INT_ZERO
             ]),
             b"{'foo':0}"
         )
     ),
     (