Esempio n. 1
0
    def _read_txt(self, stream):
        '''
        Load a PLY element from an ASCII-format PLY file.  The element
        may contain list properties.

        '''
        self._data = _np.empty(self.count, dtype=self.dtype())

        k = 0
        for line in _islice(iter(stream.readline, b''), self.count):
            fields = iter(line.strip().split())
            for prop in self.properties:
                try:
                    self._data[prop.name][k] = prop._from_fields(fields)
                except StopIteration:
                    raise PlyElementParseError("early end-of-line",
                                               self, k, prop)
                except ValueError:
                    raise PlyElementParseError("malformed input",
                                               self, k, prop)
            try:
                next(fields)
            except StopIteration:
                pass
            else:
                raise PlyElementParseError("expected end-of-line",
                                           self, k)
            k += 1

        if k < self.count:
            del self._data
            raise PlyElementParseError("early end-of-file", self, k)
Esempio n. 2
0
    def _from_fields(self, fields):
        (len_t, val_t) = self.list_dtype()

        n = int(_np.dtype(len_t).type(next(fields)))

        data = _np.loadtxt(list(_islice(fields, n)), val_t, ndmin=1)
        if len(data) < n:
            raise StopIteration

        return data
Esempio n. 3
0
    def _from_fields(self, fields):
        (len_t, val_t) = self.list_dtype()

        n = int(_np.dtype(len_t).type(next(fields)))

        data = _np.loadtxt(list(_islice(fields, n)), val_t, ndmin=1)
        if len(data) < n:
            raise StopIteration

        return data
Esempio n. 4
0
    def _from_fields(self, fields):
        '''
        Parse textual data from a generator.

        '''
        (len_t, val_t) = self.list_dtype()

        n = int(next(fields))

        return _np.loadtxt(list(_islice(fields, n)), val_t, ndmin=1)
Esempio n. 5
0
    def _from_fields(self, fields):
        '''
        Parse textual data from a generator.

        '''
        (len_t, val_t) = self.list_dtype()

        n = int(next(fields))

        return _np.loadtxt(list(_islice(fields, n)), val_t, ndmin=1)
Esempio n. 6
0
 def notify(self, n=1):
     if not self._is_owned():
         raise RuntimeError("cannot notify on un-acquired lock")
     all_waiters = self._waiters
     waiters_to_notify = _deque(_islice(all_waiters, n))
     if not waiters_to_notify:
         return
     for waiter in waiters_to_notify:
         waiter.release()
         try:
             all_waiters.remove(waiter)
         except ValueError:
             pass
Esempio n. 7
0
    def consume_payload(self, it: _Union[_ByteString, _Iterator[int]]) -> None:

        it = iter(it)

        self.protocol = _iterutils.consume_varint(it)
        self.address = _iterutils.consume_string(it)
        self.port = int.from_bytes(_islice(it, 2), 'big')
        self.next_state, = it

        assert self.protocol == 578
        assert self.address
        assert self.port > 0
        assert self.next_state in [1, 2]
Esempio n. 8
0
 def notify(self, n=1):
     if not self._is_owned():
         raise RuntimeError("cannot notify on un-acquired lock")
     all_waiters = self._waiters
     waiters_to_notify = _deque(_islice(all_waiters, n))
     if not waiters_to_notify:
         return
     for waiter in waiters_to_notify:
         waiter.release()
         try:
             all_waiters.remove(waiter)
         except ValueError:
             pass
Esempio n. 9
0
    def _read_txt(self, stream):
        '''
        Load a PLY element from an ASCII-format PLY file.  The element
        may contain list properties.

        '''
        self.data = _np.empty(self.count,
                              dtype=self.dtype())

        for (k, line) in enumerate(_islice(iter(stream.readline, ''),
                                           self.count)):
            fields = iter(line.strip().split())
            for prop in self.properties:
                self.data[prop.name][k] = prop._from_fields(fields)
Esempio n. 10
0
    def _read_txt(self, stream):
        '''
        Load a PLY element from an ASCII-format PLY file.  The element
        may contain list properties.

        '''
        self.data = _np.empty(self.count, dtype=self.dtype())

        for (k,
             line) in enumerate(_islice(iter(stream.readline, ''),
                                        self.count)):
            fields = iter(line.strip().split())
            for prop in self.properties:
                self.data[prop.name][k] = prop._from_fields(fields)
Esempio n. 11
0
def unzip(n, iterable):
    '''inverse of zip()

unzip(n, iterable) -> n lists
assert all(len(list(e)) == n for e in iterable)
'''
    if not n >= 0:
        raise ValueError('not n >= 0')

    lsls = tuple([] for _ in range(n))
    for xs in iterable:
        xs = _islice(xs, n + 1)
        xs = tuple(xs)
        if not len(xs) == n:
            raise ValueError('not all(len(list(e)) == n for e in iterable)')
        for x, ls in zip(xs, lsls):
            ls.append(x)
    return lsls
Esempio n. 12
0
 def notify(self, n=1):
     """Wake up one or more threads waiting on this condition, if any.
     If the calling thread has not acquired the lock when this method is
     called, a RuntimeError is raised.
     This method wakes up at most n of the threads waiting for the condition
     variable; it is a no-op if no threads are waiting.
     """
     if not self._is_owned():
         raise RuntimeError("cannot notify on un-acquired lock")
     all_waiters = self._waiters
     waiters_to_notify = _deque(_islice(all_waiters, n))
     if not waiters_to_notify:
         return
     for waiter in waiters_to_notify:
         waiter.release()
         try:
             all_waiters.remove(waiter)
         except ValueError:
             pass
Esempio n. 13
0
def cycle_thru_list(list_obj, i):
    """
    Cycles through a list
    
    Parameters
    ----------
    list_obj : list
        List to be cycled through
    i : int
        Index of list to be put in the first position
    
    Returns
    -------
    cycled_list : list
        List with index `i` now in the first position
    """
    cycle_obj = _cycle(list_obj)
    L = len(list_obj)
    slice_obj = _islice(cycle_obj, i, i + L)
    cycled_list = list(slice_obj)
    return(cycled_list)   
Esempio n. 14
0
    def _read(self, stream, text, byte_order):
        '''
        Read the actual data from a PLY file.

        '''
        if self._have_list:
            # There are list properties, so a simple load is
            # impossible.
            if text:
                self._read_txt(stream)
            else:
                self._read_bin(stream, byte_order)
        else:
            # There are no list properties, so loading the data is
            # much more straightforward.
            if text:
                self.data = _np.loadtxt(
                    _islice(iter(stream.readline, ''), self.count),
                    self.dtype())
            else:
                self.data = _np.fromfile(
                    stream, self.dtype(byte_order), self.count)
Esempio n. 15
0
    def _read(self, stream, text, byte_order):
        '''
        Read the actual data from a PLY file.

        '''
        if self._have_list:
            # There are list properties, so a simple load is
            # impossible.
            if text:
                self._read_txt(stream)
            else:
                self._read_bin(stream, byte_order)
        else:
            # There are no list properties, so loading the data is
            # much more straightforward.
            if text:
                self.data = _np.loadtxt(
                    _islice(iter(stream.readline, ''), self.count),
                    self.dtype())
            else:
                self.data = _np.fromfile(stream, self.dtype(byte_order),
                                         self.count)
Esempio n. 16
0
    def notify(self, n=1):
        """Wake up one or more threads waiting on this condition, if any.

        If the calling thread has not acquired the lock when this method is
        called, a RuntimeError is raised.

        This method wakes up at most n of the threads waiting for the condition
        variable; it is a no-op if no threads are waiting.

        """
        if not self._is_owned():
            raise RuntimeError("cannot notify on un-acquired lock")
        all_waiters = self._waiters
        waiters_to_notify = _deque(_islice(all_waiters, n))
        if not waiters_to_notify:
            return
        for waiter in waiters_to_notify:
            waiter.release()
            try:
                all_waiters.remove(waiter)
            except ValueError:
                pass
Esempio n. 17
0
def consume_string(it: _Iterator[int]) -> str:

    n = consume_varint(it)
    return bytes(_islice(it, n)).decode()
Esempio n. 18
0
 def clean(self):
     self._lock.clean()
     for waiters in _deque(_islice(self._waiters, len(self._waiters))):
         waiters.clean()
Esempio n. 19
0
 def take(n, iterable):
     "Return first n items of the iterable as a tuple"
     return tuple(_islice(iterable, n))
Esempio n. 20
0
def Islice(iterable, start, stop, step):
    return _islice(iterable, start if start is None else start % len(iterable),
                   stop if stop is None else stop % len(iterable), step)