示例#1
0
    def _add_writer(self):
        for pa_device in self.pa_devices:
            self.ptv["name"] = pa_device
            self.config = self.ptv.to_config()
            writer = self._create_writer(
                self.stitcher.project_manager.panorama,
                self.stitcher.project_manager.controller, self.config,
                pa_device)

            self.shared_writer = vs.writerSharedPtr(writer.release())
            self.connect_writer_events(self.shared_writer)
            self.shared_video = vs.videoWriterSharedPtr(self.shared_writer)
            shared_audio = vs.audioWriterSharedPtr(self.shared_writer)
            self.has_audio = True
            if self.shared_video is not None and not self.stitcher.stitch_output.addWriter(
                    self.shared_video):
                raise errors.InternalError(
                    "Cannot add video writer to stitcher")
            if shared_audio is not None and not self.stitcher.project_manager.controller.addAudioOutput(
                    shared_audio):
                raise errors.InternalError(
                    "Cannot add audio writer to stitcher")

            self.timer.start()
            gc.collect()
示例#2
0
    def _add_writer(self):

        if "filename" not in self.ptv:
            raise errors.OutputError(
                'Configuration preset has no filename field')

        self.writer_name = str(self.ptv["filename"])
        self.config = self.ptv.to_config()
        writer = self._create_writer(self.stitcher.project_manager.panorama,
                                     self.stitcher.project_manager.controller,
                                     self.config, self.writer_name)

        self.shared_writer = vs.writerSharedPtr(writer.release())
        self.connect_writer_events(self.shared_writer)
        self.shared_video = vs.videoWriterSharedPtr(self.shared_writer)
        shared_audio = vs.audioWriterSharedPtr(self.shared_writer)
        self.has_audio = shared_audio is not None
        if self.shared_video is not None and not self.stitcher.stitch_output.addWriter(
                self.shared_video):
            raise errors.InternalError("Cannot add video writer to stitcher")
        if shared_audio is not None and not self.stitcher.project_manager.controller.addAudioOutput(
                shared_audio):
            raise errors.InternalError("Cannot add audio writer to stitcher")

        self.timer.start()
        gc.collect()
示例#3
0
    def executemany(self, operation, seq_params):
        """Execute the given operation multiple times
        
        The executemany() method will execute the operation iterating
        over the list of parameters in seq_params.
        
        Example: Inserting 3 new employees and their phone number
        
        data = [
            ('Jane','555-001'),
            ('Joe', '555-001'),
            ('John', '555-003')
            ]
        stmt = "INSERT INTO employees (name, phone) VALUES ('%s','%s')"
        cursor.executemany(stmt, data)
        
        INSERT statements are optimized by batching the data, that is
        using the MySQL multiple rows syntax.
        
        Results are discarded. If they are needed, consider looping over
        data using the execute() method.
        """
        if not operation:
            return
        if self._have_unread_result():
            raise errors.InternalError("Unread result found.")
        elif len(RE_SQL_SPLIT_STMTS.split(operation)) > 1:
            raise errors.InternalError(
                "executemany() does not support multiple statements")

        # Optimize INSERTs by batching them
        if re.match(RE_SQL_INSERT_STMT, operation):
            opnocom = re.sub(RE_SQL_COMMENT, '', operation)
            m = re.search(RE_SQL_INSERT_VALUES, opnocom)
            fmt = m.group(1)
            values = []
            for params in seq_params:
                values.append(fmt % self._process_params(params))
            operation = operation.replace(m.group(1), ','.join(values), 1)
            return self.execute(operation)

        rowcnt = 0
        try:
            for params in seq_params:
                self.execute(operation, params)
                if self.with_rows and self._have_unread_result():
                    self.fetchall()
                rowcnt += self._rowcount
        except (ValueError, TypeError) as err:
            raise errors.InterfaceError("Failed executing the operation; %s" %
                                        err)
        except:
            # Raise whatever execute() raises
            raise
        self._rowcount = rowcnt
示例#4
0
def index(event, context):
    """
  taskListの一覧を返す
  """
    try:
        logger.info(event)
        try:
            task_lists = TaskListModel.scan(TaskListModel.deleteFlag == False)
        except ScanError as e:
            logger.exception(e)
            raise errors.InternalError('Internal server error')

        return {
            'statusCode':
            200,
            'headers': {
                'Access-Control-Allow-Origin': '*',
                'Content-Type': 'application/json'
            },
            'body':
            json.dumps({
                'statusCode':
                200,
                'taskLists': [dict(task_list) for task_list in task_lists]
            })
        }

    except errors.InternalError as e:
        logger.exception(e)
        return build_response(e, 500)
示例#5
0
 def executemany(self, operation, seq_params):
     """Loops over seq_params and calls execute()
     
     INSERT statements are optimized by batching the data, that is
     using the MySQL multiple rows syntax.
     """
     if not operation:
         return 0
     if self.db().unread_result is True:
         raise errors.InternalError("Unread result found.")
     
     # Optimize INSERTs by batching them
     if re.match(RE_SQL_INSERT_STMT,operation):
         opnocom = re.sub(RE_SQL_COMMENT,'',operation)
         m = re.search(RE_SQL_INSERT_VALUES,opnocom)
         fmt = m.group(1)
         values = []
         for params in seq_params:
             values.append(fmt % self._process_params(params))
         operation = operation.replace(m.group(1),','.join(values),1)
         self.execute(operation)
     else:
         rowcnt = 0
         try:
             for params in seq_params:
                 self.execute(operation, params)
                 if self._have_result:
                     self.fetchall()
                 rowcnt += self.rowcount
         except (ValueError,TypeError), e:
             raise errors.InterfaceError(
                 "Failed executing the operation; %s" % e)
         except:
示例#6
0
    def cmd_query_iter(self, statements):
        """Send one or more statements to the MySQL server

        Similar to the cmd_query method, but instead returns a generator
        object to iterate through results. It sends the statements to the
        MySQL server and through the iterator you can get the results.
        
        statement = 'SELECT 1; INSERT INTO t1 VALUES (); SELECT 2'
        for result in cnx.cmd_query(statement, iterate=True):
            if 'columns' in result:
                columns = result['columns']
                rows = cnx.get_rows()
            else:
                # do something useful with INSERT result

        Returns a generator.
        """
        # Handle the first query result
        yield self._handle_result(self._send_cmd(ServerCmd.QUERY, statements))

        # Handle next results, if any
        while self._have_next_result:
            if self.unread_result:
                raise errors.InternalError("Unread result found.")
            else:
                result = self._handle_result(self._socket.recv())
            yield result
示例#7
0
    def _send_data(self, fp, send_empty_packet=False):
        """Send data to the MySQL server

        This method accepts a file-like object and sends its data
        as is to the MySQL server. If the send_empty_packet is
        True, it will send an extra empty package (for example
        when using LOAD LOCAL DATA INFILE).

        Returns a MySQL packet.
        """
        if self.unread_result:
            raise errors.InternalError("Unread result found.")

        if not hasattr(fp, 'read'):
            raise ValueError("expecting a file-like object")

        try:
            buf = fp.read(4096)
            while buf:
                self._socket.send(buf)
                buf = fp.read(4096)
        except AttributeError:
            raise errors.OperationalError("MySQL Connection not available.")

        if send_empty_packet:
            try:
                self._socket.send('')
            except AttributeError:
                raise errors.OperationalError(
                    "MySQL Connection not available.")

        return self._socket.recv()
示例#8
0
    def execute(self, operation, params=None, multi=False):
        """Executes the given operation
        
        Executes the given operation substituting any markers with
        the given parameters.
        
        For example, getting all rows where id is 5:
          cursor.execute("SELECT * FROM t1 WHERE id = %s", (5,))
        
        The multi argument should be set to True when executing multiple
        statements in one operation. If not set and multiple results are
        found, an InterfaceError will be raised.
        
        If warnings where generated, and connection.get_warnings is True, then
        self._warnings will be a list containing these warnings.
        
        Returns an iterator when multi is True, otherwise None.
        """
        if not operation:
            return
        if self._have_unread_result():
            raise errors.InternalError("Unread result found.")

        self._reset_result()
        stmt = ''

        try:
            if isinstance(operation, unicode):
                operation = operation.encode(self._connection.charset)
        except (UnicodeDecodeError, UnicodeEncodeError), e:
            raise errors.ProgrammingError(str(e))
示例#9
0
    def get_drive_info(self, parameters):
        """Returns the storage drive information

        Returns:
            - ``InternalError``
            - Structure::

                {
                    'results': {
                        'used': string,
                        'percent': float,
                        'free': string,
                        'label': string,
                        'fs': string,
                        'device': string,
                        'mountpoint': string,
                        'total': string
                    }
                }

        Note:
            Calling this function can create some overhead
        """
        try:
            drive = parameters['drive']
        except:
            raise errors.InvalidParameter('No specified drive')
        mp_stats = self.monitor.drive_info(drive)
        if mp_stats is None:
            raise errors.InternalError(
                'No information found for drive {}'.format(parameters))
示例#10
0
    def _remove_writer(self, writer_name):
        """Stops the stream
        """
        if self.has_audio:
            success = self.stitcher.project_manager.controller.removeAudioOutput(
                writer_name)
            if not success:
                raise errors.InternalError(
                    "Cannot remove audio writer {}".format(writer_name))
        success = self.stitcher.stitch_output.removeWriterNoGIL(writer_name)
        if not success:
            raise errors.InternalError("Cannot remove video writer")

        self.shared_writer = None
        self.shared_video = None
        self.timer.reset()
        gc.collect()
        self.flush_writer_events()
示例#11
0
 def _validateTable(self):
   """
   Checks that the table is internally consistent
   Verify that there is at least one column
   """
   if len(self.getColumns()) < 1:
     raise er.InternalError("Table %s has no columns." % self._name)
   # Verify that all columns have the same number of cells
   try:
     name_column = [c for c in self.getChildren() 
                    if c.getName(is_global_name=False) == NAME_COLUMN_STR][0]
   except Exception as e:
     import pdb; pdb.set_trace()
   if name_column is None:
     import pdb; pdb.set_trace()
   num_rows = self.numRows()
   for column in self.getColumns():
     if  column.numCells() != num_rows:
       import pdb; pdb.set_trace()
       msg = "In Table %s, Column %s differs in its number of rows." \
           % (self.getName(), column.getName())
       raise er.InternalError(msg)
   # Verify that the first Column is the Name Column
   if self.getChildAtPosition(0).getName(is_global_name=False) != NAME_COLUMN_STR:
     msg = "In Table %s, first column is not 'row' column" % self.getName()
     raise er.InternalError(msg)
   # Verify that names are unique
   if self.validateTree() is not None:
     raise RuntimeError(self.validateTree())
   # Verify the sequence of row names
   for nrow in range(self.numRows()):
     expected_row_name = Table._rowNameFromIndex(nrow)
     actual_row_name =  \
         self.getChildAtPosition(NAME_COLUMN_IDX).getCells()[nrow]
     if actual_row_name != expected_row_name:
       import pdb; pdb.set_trace()
       msg = "In Table %s, invalid row name at index %d: %s" % \
               (self.getName(), nrow, actual_row_name)
       raise er.InternalError(msg)
   # Verify that the name columns are identical
   for column in self.getColumns():
     if Table.isNameColumn(column):
       if not column.getCells() == name_column.getCells():
         raise RuntimeError("%s is not a consistent name column" % column.getName())
示例#12
0
    def execute(self, operation, params=None, multi=False):
        """Executes the given operation
        
        Executes the given operation substituting any markers with
        the given parameters.
        
        For example, getting all rows where id is 5:
          cursor.execute("SELECT * FROM t1 WHERE id = %s", (5,))
        
        The multi argument should be set to True when executing multiple
        statements in one operation. If not set and multiple results are
        found, an InterfaceError will be raised.
        
        If warnings where generated, and connection.get_warnings is True, then
        self._warnings will be a list containing these warnings.
        
        Returns an iterator when multi is True, otherwise None.
        """
        if not operation:
            return
        if self._have_unread_result():
            raise errors.InternalError("Unread result found.")

        self._reset_result()
        stmt = ''

        try:
            if isinstance(operation, unicode):
                operation = operation.encode(self._connection.charset)
        except (UnicodeDecodeError, UnicodeEncodeError) as e:
            raise errors.ProgrammingError(str(e))

        if params is not None:
            try:
                stmt = operation % self._process_params(params)
            except TypeError:
                raise errors.ProgrammingError(
                    "Wrong number of arguments during string formatting")
        else:
            stmt = operation

        if multi:
            self._executed = stmt
            self._executed_list = []
            return self._execute_iter(self._connection.cmd_query_iter(stmt))
        else:
            self._executed = stmt
            try:
                self._handle_result(self._connection.cmd_query(stmt))
            except errors.InterfaceError as err:
                if self._connection._have_next_result:
                    raise errors.InterfaceError(
                        "Use multi=True when executing multiple statements")
                raise
            return None
示例#13
0
def tasks(event, context):
  """
  taskListに紐づくtask一覧の取得
  """
  logger.info(event)
  logger.info(context)
  try:
    logger.info(event)
    if not event['pathParameters']:
      raise errors.BadRequest('Bad request')
    task_list_id = event['pathParameters']['id']

    # taskListが存在するか
    try:
      task_list = TaskListModel.get(task_list_id)
    except TaskListModel.DoesNotExist as e:
      logger.exception(e)
      raise errors.NotFound('The taskList does not exist')

    # tasksの取得
    try:
      tasks = TaskModel.tasks_gsi_taskListId.query(
        task_list_id,
        TaskModel.deleteFlag == False
      )
    except QueryError as e:
      logger.exception(e)
      raise errors.InternalError('Internal server error')

    return {
      'statusCode': 200,
      'headers': {
        'Access-Control-Allow-Origin': '*',
        'Content-Type': 'application/json'
      },
      'body': json.dumps(
        {
          'statusCode': 200,
          'taskList': task_list_id,
          'tasks': [dict(task) for task in tasks]
        }
      )
    }
  
  except errors.BadRequest as e:
    logger.exception(e)
    return build_response(e, 400)

  except errors.NotFound as e:
    logger.exception(e)
    return build_response(e, 404)

  except errors.InternalError as e:
    logger.exception(e)
    return build_response(e, 500)
示例#14
0
    def _start(self, profiling_time=0, preserve=False):
        # Todo I don't like that it's created differently from other outputs here, but for now I left it like this
        panorama = self.stitcher.project_manager.panorama
        self.writer = vs.Output_profiling(self.name,
                                          panorama.width,
                                          panorama.height,
                                          self.stitcher.project_manager.controller.getFrameRateFromInputController(),
                                          PROFILING_STITCH_FORMAT)
        if self.writer is None:
            raise errors.InternalError()

        self.shared_writer = vs.writerSharedPtr(self.writer.object())
        self.shared_video  = vs.videoWriterSharedPtr(self.shared_writer)
        self.has_audio = False
        if self.shared_video is not None and not self.stitcher.stitch_output.addWriter(self.shared_video):
            raise errors.InternalError("Cannot add profiling writer to stitcher")
        if profiling_time > 0:
            threading.Timer(profiling_time, self.t_stop).start()
        self.pid.cpu_percent(interval=None)
        #jump automatically from starting state to started state
        self.t_writer_ok()
示例#15
0
    def _execute_query(self, query):
        """Execute a query

        This method simply calles cmd_query() after checking for unread
        result. If there are still unread result, an errors.InterfaceError
        is raised. Otherwise whatever cmd_query() returns is returned.

        Returns a dict()
        """
        if self._unread_result is True:
            raise errors.InternalError("Unread result found.")

        self.cmd_query(query)
示例#16
0
def users(event, context):
  """
  taskに所属するuser一覧を返す
  """
  try:
    logger.info(event)
    if not event['pathParameters']:
      raise errors.BadRequest('Bad request')
    task_id = event['pathParameters']['id']

    # taskの取得
    try:
      task = TaskModel.get(task_id)
    except TaskModel.DoesNotExist:
      raise errors.NotFound('The task does not exist')
    if not task.userIds:
      task.userIds = []
    # usersの取得
    try:
      users = task.get_users()
    except UserModel.DoesNotExist as e:
      logger.exception(e)
      raise errors.InternalError('Internal server error')


    return {
        'statusCode': 200,
        'headers': {
          'Access-Control-Allow-Origin': '*',
          'Content-Type': 'application/json'
        },
        'body': json.dumps(
          {
            'statusCode': 200,
            'taskId': task_id,
            'users': [dict(user) for user in users]
          }
        )
      }

  except errors.BadRequest as e:
    logger.exception(e)
    return build_response(e, 400)

  except errors.NotFound as e:
    logger.exception(e)
    return build_response(e, 404)

  except errors.InternalError as e:
    logger.exception(e)
    return build_response(e, 500)
示例#17
0
    def cmd_statistics(self):
        """Send the statistics command to the MySQL Server

        This method sends the STATISTICS command to the MySQL server. The
        result is a dictionary with various statistical information.

        Returns a dict()
        """
        if self.unread_result:
            raise errors.InternalError("Unread result found.")

        packet = self._protocol.make_command(ServerCmd.STATISTICS)
        self._socket.send(packet, 0)
        return self._protocol.parse_statistics(self._socket.recv())
示例#18
0
def done_undone(event, context):
    try:
        logger.info(event)
        if not event['pathParameters']:
            raise errors.BadRequest('Bad request')
        task_id = event['pathParameters']['id']

        # done or undone で ture or false
        if re.match('.*/done$', event['resource']):
            flag = True
        else:
            flag = False

        # taskを取得
        try:
            task = TaskModel.get(task_id)
        except TaskModel.DoesNotExist:
            raise errors.NotFound('The task does not exist')

        # taskを更新
        try:
            task.status_update(flag)
        except UpdateError as e:
            logger.exception(e)
            raise errors.InternalError('Internal server error')

        return {
            'statusCode': 200,
            'headers': {
                'Access-Control-Allow-Origin': '*',
                'Content-Type': 'application/json'
            },
            'body': json.dumps({
                'statusCode': 200,
                'task': dict(task)
            })
        }

    except errors.BadRequest as e:
        logger.exception(e)
        return build_response(e, 400)

    except errors.NotFound as e:
        logger.exception(e)
        return build_response(e, 404)

    except errors.InternalError as e:
        logger.exception(e)
        return build_response(e, 500)
示例#19
0
def condition_to_tags(cond: Condition) -> List[str]:
    if cond is conditions.ALWAYS:
        return []

    assert not isinstance(cond, conditions.BaseCondition)

    if isinstance(cond, conditions.Terminal):
        return [conditions.get_term(cond.name).expectations_info.tag]

    op, args = cond
    if op == 'or':
        return [tag for arg in args for tag in condition_to_tags(arg)]

    raise errors.InternalError(
        f"Unable to express condition in test expectations format: {cond}")
示例#20
0
    def cmd_quit(self):
        """Close the current connection with the server

        This method sends the QUIT command to the MySQL server, closing the
        current connection. Since the no response can be returned to the
        client, cmd_quit() will return the packet it send.

        Returns a str()
        """
        if self.unread_result:
            raise errors.InternalError("Unread result found.")

        packet = self._protocol.make_command(ServerCmd.QUIT)
        self._socket.send(packet, 0)
        return packet
示例#21
0
def create(event, context):
    """
  taskListを作成
  削除済みレコードは復活させない
  """
    try:
        logger.info(event)
        # validation
        if not event['body']:
            raise errors.BadRequest('Bad request')
        body = json.loads(event['body'])
        validate_attributes(body)
        task_list = TaskListModel(str(uuid.uuid1()),
                                  name=body['name'],
                                  description=body['description'])

        # taskListの保存
        try:
            task_list.save()
        except InvalidNameError as e:
            logger.exception(e)
            raise errors.BadRequest(str(e.with_traceback(sys.exc_info()[2])))
        except InvalidDescriptionError as e:
            logger.exception(e)
            raise errors.BadRequest(str(e.with_traceback(sys.exc_info()[2])))
        except PutError as e:
            logger.exception(e)
            raise errors.InternalError('Internal server error')

        return {
            'statusCode': 200,
            'headers': {
                'Access-Control-Allow-Origin': '*',
                'Content-Type': 'application/json'
            },
            'body': json.dumps({
                'statusCode': 200,
                'taskList': dict(task_list)
            })
        }

    except errors.BadRequest as e:
        logger.exception(e)
        return build_response(e, 400)

    except errors.InternalError as e:
        logger.exception(e)
        return build_response(e, 500)
示例#22
0
def search_for_expectations(filename: str, test_name: str) -> str:
    # TODO: Is this ever not the case? If so we might need to just keep searching
    # upwards, directory by directory until we find a test expectations file
    # referencing this test.
    assert filename.endswith(test_name)

    expectations_dir = filename[:-len(test_name)]
    # TODO: I think ASan and some other conditions are handled via different
    # files.
    expectations_path = os.path.join(expectations_dir, 'TestExpectations')
    if os.path.exists(expectations_path):
        return expectations_path

    raise errors.InternalError(
        "Couldn't find TestExpectations file for test " + f"{test_name} " +
        f"(expected to find it at {expectations_path})")
示例#23
0
 def _stop(self):
     self.fps = vs.Output_getFps(self.writer.release())
     self.writer = None
     logging.info("fps is %f:" % self.fps)
     logging.info("cpu_util is %d" % self.pid.cpu_percent(interval=None))
     cuda = performance.getCudaInfo()
     logging.info("gpu_util is %d" % int(cuda['utilization.gpu']))
     logging.info("enc_util is %s" % cuda['utilization.enc'])
     success = self.stitcher.stitch_output.removeWriterNoGIL(self.name)
     signal("profiling_stopping").send()
     if not success:
         raise errors.InternalError("Cannot remove writer")
     self.shared_video = None
     self.shared_writer = None
     gc.collect()
     #jump automatically from stopping state to stopped state
     self.t_writer_completed()
示例#24
0
    def _send_cmd(self, command, argument=None, packet_number=0):
        """Send a command to the MySQL server

        This method sends a command with an optional argument.

        Returns a MySQL packet
        """
        if self.unread_result:
            raise errors.InternalError("Unread result found.")

        try:
            self._socket.send(self._protocol.make_command(command, argument),
                              packet_number)
        except AttributeError:
            raise errors.OperationalError("MySQL Connection not available.")

        return self._socket.recv()
示例#25
0
    def get_rows(self, count=None):
        """Get all rows returned by the MySQL server

        This method gets all rows returned by the MySQL server after sending,
        for example, the query command. The result is a tuple consisting of
        a list of rows and the EOF packet.

        Returns a tuple()
        """
        if not self.unread_result:
            raise errors.InternalError("No result set available.")

        rows = self._protocol.read_text_result(self._socket, count)
        if rows[-1] is not None:
            self._toggle_have_next_result(rows[-1]['status_flag'])
            self.unread_result = False

        return rows
示例#26
0
def delete(event, context):
    """
  delteFlagをfalseに変更
  """
    try:
        logger.info(event)
        if not event['pathParameters']:
            raise errors.BadRequest('Bad request')
        task_id = event['pathParameters']['id']

        # taskの取得
        try:
            task = TaskModel.get(task_id)
        except TaskModel.DoesNotExist:
            raise errors.NotFound('The task does not exist')

        # taskの削除
        try:
            task.logic_delete()
        except UpdateError as e:
            logger.exception(e)
            raise errors.InternalError('Internal server error')

        return {
            'statusCode': 200,
            'headers': {
                'Access-Control-Allow-Origin': '*',
                'Content-Type': 'application/json'
            },
            'body': json.dumps({'statusCode': 200})
        }

    except errors.BadRequest as e:
        logger.exception(e)
        return build_response(e, 400)

    except errors.NotFound as e:
        logger.exception(e)
        return build_response(e, 404)

    except errors.InternalError as e:
        logger.exception(e)
        return build_response(e, 500)
示例#27
0
    def _create_writer(self, panorama, controller, config, writer_name):
        """Creates an output writer to register to the stitcher
        """
        sampling_rate = self.ptv.get("sampling_rate", 0)
        sample_format = str(self.ptv.get("sample_format", ""))
        channel_layout = str(self.ptv.get("channel_layout", ""))

        writer = vs.Output_createNoGIL(
            config, writer_name, panorama.width, panorama.height,
            controller.getFrameRateFromInputController(), sampling_rate,
            sample_format, channel_layout)

        if not writer.status().ok():
            raise errors.InternalError(
                "Cannot create writer for output {}: {}, {}".format(
                    self.writer_name, str(writer.status().getOrigin()),
                    writer.status().getErrorMessage()))

        return writer
示例#28
0
 def execute(self, operation, params=None):
     """
     Executes the given operation. The parameters given through params
     are used to substitute %%s in the operation string.
     For example, getting all rows where id is 5:
       cursor.execute("SELECT * FROM t1 WHERE id = %s", (5,))
     
     If warnings where generated, and db.get_warnings is True, then
     self._warnings will be a list containing these warnings.
     
     Raises exceptions when any error happens.
     """
     if not operation:
         return 0
     if self.db().unread_result is True:
         raise errors.InternalError("Unread result found.")
     
     self._reset_result()
     stmt = ''
     
     try:
         if isinstance(operation, unicode):
             operation = operation.encode(self.db().charset_name)
         
         if params is not None:
             try:
                 stmt = operation % self._process_params(params)
             except TypeError:
                 raise errors.ProgrammingError(
                     "Wrong number of arguments during string formatting")
         else:
             stmt = operation
         
         res = self.db().protocol.cmd_query(stmt)
         self._handle_result(res)
     except (UnicodeDecodeError,UnicodeEncodeError), e:
         raise errors.ProgrammingError(str(e))
示例#29
0
    def cmd_change_user(self,
                        username='',
                        password='',
                        database='',
                        charset=33):
        """Change the current logged in user

        This method allows to change the current logged in user information.
        The result is a dictionary with OK packet information.

        Returns a dict()
        """
        if self.unread_result:
            raise errors.InternalError("Unread result found.")

        packet = self._protocol.make_change_user(
            seed=self._handshake['scramble'],
            username=username,
            password=password,
            database=database,
            charset=charset,
            client_flags=self._client_flags)
        self._socket.send(packet, 0)
        return self._handle_ok(self._socket.recv())
    def _execute_query(self, query):
        if self.unread_result is True:
            raise errors.InternalError("Unread result found.")

        self.protocol.cmd_query(query)