예제 #1
0
 def __init__(self, size, source):
     super(SendMsg, self).__init__()
     if isinstance(source, Msg):
         self.msg = source = byteme(source)
     elif isunicode(source):
         self.msg = source = tobytes(source)
     else:
         self.msg = source
     self.size = len(source) if size is None else size
예제 #2
0
 def __init__(self, source):
     super(SendMsg32, self).__init__()
     if isinstance(source, Msg):
         self.msg = source.msg
     else:
         self.msg = xs.msg_t()
         source = tobytes(source)
         length = len(source)
         self.rc = xs.msg_init_size(self.msg, length)
         xs.memmove(xs.msg_data(self.msg), source, length)
예제 #3
0
파일: base.py 프로젝트: lcrees/knife
    def ascii(self, errors='strict'):
        '''
        `byte <http://docs.python.org/py3k/library/functions.html#bytes>`_
        `encode() <http://docs.python.org/py3k/library/stdtypes.html#str.
        encode>`_ outgoing things with the ``'ascii'`` codec.

        :keyword string errors: error handling for decoding issues

        :rtype: :const:`self` (:obj:`knife` object)

        >>> from stuf.six import u, b
        >>> test = __([1], True, r't', b('i'), u('g'), None, (1,))
        >>> test.ascii().oneach().peek()
        ['[1]', 'True', 't', 'i', 'g', 'None', '(1,)']
        '''
        self._wrapper = lambda x: tobytes(x, 'ascii', errors)
        return self
예제 #4
0
파일: base.py 프로젝트: lcrees/knife
    def bytes(self, encoding='utf-8', errors='strict'):
        '''
        `byte <http://docs.python.org/py3k/library/functions.html#bytes>`_
        `encode() <http://docs.python.org/py3k/library/stdtypes.html#str.
        encode>`_ outgoing things.

        :keyword string encoding: Unicode encoding

        :keyword string errors: error handling for encoding issues

        :rtype: :const:`self` (:obj:`knife` object)

        >>> test = __([1], True, r't', b('i'), u('g'), None, (1,))
        >>> test.bytes().oneach().peek()
        ['[1]', 'True', 't', 'i', 'g', 'None', '(1,)']
        '''
        self._wrapper = lambda x: tobytes(x, encoding, errors)
        return self
예제 #5
0
 def test_bytes(self):
     from stuf.six import u, b, tobytes
     self.assertEqual(
         [tobytes(i) for i in [[1], True, r't', b('i'), u('g'), None, (1,)]],
         [b('[1]'), b('True'), b('t'), b('i'), b('g'), b('None'), b('(1,)')]
     )
예제 #6
0
파일: low.py 프로젝트: lcrees/crossroads
 def _sconnect(self, prefix, *addresses):
     for address in addresses:
         self.last_rc = self._connect(prefix + tobytes(address))
         self.connections[unique_id()] = self.last_rc
     return self
예제 #7
0
파일: low.py 프로젝트: lcrees/crossroads
 def _sbind(self, prefix, *addresses):
     for address in addresses:
         self.last_rc = self._bind(prefix + tobytes(address))
         self.bindings[unique_id()] = self.last_rc
     return self
예제 #8
0
 def __bytes__(self):
     if self.msg is None:
         return b''
     return tobytes(string_at(byref(self.msg), self.size))