Generate argument pairs for queries like where("id > ?", 7)

def _custom_items(self, restrictions):
        """Generate argument pairs for queries like where("id > ?", 7)"""
        def scope_name(query, table):
            # The first entry in the query is the column
            # If the column already has a ".", that means that the table has
            # already been chosen
            for splitter in (" and ", " or "):
                split_query = re.split(splitter, query, re.IGNORECASE)
                query = splitter.join("{}.{}".format(table, entry)
                                      if "." not in entry else entry
                                      for entry in split_query)
            return query

        names = [scope_name(restriction[0], self.table_name)
                 for restriction in restrictions]
        values = list(chain(
            *[restriction[1:] for restriction in restrictions]))
        return (names, values)