Exemplo 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)
Exemplo 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)
Exemplo 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
Exemplo n.º 4
0
def json_loads(s: str) -> Dict[str, Any]:
    """Read JSON in a consistent way."""
    return json.loads(ensure_text(s, 'ascii'))
Exemplo n.º 5
0
def json_loads(s):
    """Read JSON in a consistent way."""
    return json.loads(ensure_text(s, 'ascii'), cls=ZarrJsonDecoder)
Exemplo n.º 6
0
def json_loads(s):
    """Read JSON in a consistent way."""
    return json.loads(ensure_text(s, 'ascii'))