Пример #1
0
 def test_to_bytes(self):
     self.assertEqual(to_bytes(b'ciao'), b'ciao')
     b = b'perch\xc3\xa9'
     u = b.decode('utf-8')
     l = u.encode('latin')
     self.assertEqual(to_bytes(b, 'latin'), l)
     self.assertEqual(to_string(l, 'latin'), u)
     self.assertEqual(to_bytes(1), b'1')
Пример #2
0
 def test_to_bytes(self):
     self.assertEqual(to_bytes(b'ciao'),b'ciao')
     b = b'perch\xc3\xa9'
     u = b.decode('utf-8')
     l = u.encode('latin')
     self.assertEqual(to_bytes(b,'latin'),l)
     self.assertEqual(to_string(l,'latin'),u)
     self.assertEqual(to_bytes(1), b'1')
Пример #3
0
def hashmodel(model, library=None):
    '''Calculate the Hash id of metaclass ``meta``'''
    library = library or 'python-stdnet'
    meta = model._meta
    sha = hashlib.sha1(to_bytes('{0}({1})'.format(library, meta)))
    hash = sha.hexdigest()[:8]
    meta.hash = hash
    if hash in _model_dict:
        raise KeyError('Model "{0}" already in hash table.\
 Rename your model or the module containing the model.'.format(meta))
    _model_dict[hash] = model
Пример #4
0
def hashmodel(model, library=None):
    '''Calculate the Hash id of metaclass ``meta``'''
    library = library or 'python-stdnet'
    meta = model._meta
    sha = hashlib.sha1(to_bytes('{0}({1})'.format(library, meta)))
    hash = sha.hexdigest()[:8]
    meta.hash = hash
    if hash in _model_dict:
        raise KeyError('Model "{0}" already in hash table.\
 Rename your model or the module containing the model.'.format(meta))
    _model_dict[hash] = model
Пример #5
0
 def __init__(self, data, text = True):
     fd, path = tempfile.mkstemp(text = text)
     self.handler = None
     self.path = path
     os.write(fd, to_bytes(data))
     os.close(fd)
Пример #6
0
 def __init__(self, data, text=True):
     fd, path = tempfile.mkstemp(text=text)
     self.handler = None
     self.path = path
     os.write(fd, to_bytes(data))
     os.close(fd)