Ejemplo n.º 1
0
def test_ensure_text():
    bufs = [
        b'adsdasdas', u'adsdasdas',
        np.asarray(memoryview(b'adsdasdas')),
        array.array('B', b'qwertyuiqwertyui')
    ]
    for buf in bufs:
        b = ensure_text(buf)
        assert isinstance(b, text_type)
Ejemplo n.º 2
0
 def __init__(self, labels, dtype, astype='u1'):
     self.dtype = np.dtype(dtype)
     if self.dtype.kind == 'S':
         self.labels = [ensure_bytes(l) for l in labels]
     elif self.dtype.kind == 'U':
         self.labels = [ensure_text(l) for l in labels]
     else:
         self.labels = labels
     self.astype = np.dtype(astype)
Ejemplo n.º 3
0
 def get_config(self):
     if self.dtype.kind == 'S':
         labels = [ensure_text(l) for l in self.labels]
     else:
         labels = self.labels
     config = dict(id=self.codec_id,
                   labels=labels,
                   dtype=self.dtype.str,
                   astype=self.astype.str)
     return config
Ejemplo n.º 4
0
def json_loads(s: str) -> Dict[str, Any]:
    """Read JSON in a consistent way."""
    return json.loads(ensure_text(s, 'ascii'))
Ejemplo n.º 5
0
def json_loads(s):
    """Read JSON in a consistent way."""
    return json.loads(ensure_text(s, 'ascii'), cls=ZarrJsonDecoder)
Ejemplo n.º 6
0
def json_loads(s):
    """Read JSON in a consistent way."""
    return json.loads(ensure_text(s, 'ascii'))