Exemple #1
0
    def resume(self):
        "restore and re-raise any exception"

        if '_saved' not in vars(self):
            return

        type, exc = map(pickle.loads, self._saved)
        six.reraise(type, exc, self._tb)
Exemple #2
0
    def resume(self):
        "restore and re-raise any exception"

        if '_saved' not in vars(self):
            return

        type, exc = map(pickle.loads, self._saved)
        six.reraise(type, exc, self._tb)
Exemple #3
0
    def parse(self, f=sys.stdin, ctx=None):
        '''Function to parse a JSON stream.

        :type f: file
        :param f: stream to parse JSON from
        :type ctx: ctypes.POINTER
        :param ctx: passed to all callback functions as the first param this is
         a feature of yajl, and not very useful in yajl-py since the context is
         preserved using the content_handler instance.
        :raises YajlError: When invalid JSON in input stream found
        '''
        if f is sys.stdin and hasattr(f, 'buffer'):
            # raw binary buffer available use instead
            # needed to read bytes in python3
            f = f.buffer
        if self.content_handler:
            self.content_handler.parse_start()
        hand = yajl.yajl_alloc(self.callbacks, None, ctx)
        self.yajl_config(hand)
        try:
            while 1:
                fileData = f.read(self.buf_siz)
                if not fileData:
                    stat = yajl.yajl_complete_parse(hand)
                else:
                    stat = yajl.yajl_parse(hand, fileData, len(fileData))
                if self.content_handler:
                    self.content_handler.parse_buf()
                if stat != yajl_status_ok.value:
                    if stat == yajl_status_client_canceled.value:
                        # it means we have an exception
                        if self._exc_info:
                            exc_info = self._exc_info
                            six.reraise(exc_info[0], exc_info[1], exc_info[2])
                        else:  # for some reason we have no error stored
                            raise YajlParseCancelled()
                    else:
                        yajl.yajl_get_error.restype = c_char_p
                        error = yajl.yajl_get_error(hand, 1, fileData,
                                                    len(fileData))
                        # in python3 error is bytes so must be encoded
                        # to something printable
                        error = error.decode('latin-1')
                        raise YajlError(error)
                if not fileData:
                    if self.content_handler:
                        self.content_handler.complete_parse()
                    break
        finally:
            yajl.yajl_free(hand)
Exemple #4
0
        # dump the exception
        self._saved = UnpickleableException.dump(type, exc)
        self._tb = tb

        # suppress the exception
        return True

    def resume(self):
        "restore and re-raise any exception"

        if '_saved' not in vars(self):
            return

        type, exc = map(pickle.loads, self._saved)
<<<<<<< HEAD
        six.reraise(type, exc, self._tb)
=======
        raise exc.with_traceback(self._tb)
>>>>>>> 7e5c5fbd6c824de4d4c2b62da3f7cae87d462119


@contextlib.contextmanager
def save_modules():
    """
    Context in which imported modules are saved.

    Translates exceptions internal to the context into the equivalent exception
    outside the context.
    """
    saved = sys.modules.copy()
    with ExceptionSaver() as saved_exc: