예제 #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)