# Path: collectors/lib/utils.py
# PY3 = sys.version_info[0] > 2
# USER = "nobody"
# def drop_privileges(user=USER):
# def is_sockfile(path):
# def err(msg):
#     def is_numeric(value):
#     def is_numeric(value):


import errno
import os
import re
import socket
import sys
import time
  import MySQLdb
from collectors.etc import mysqlconf
from collectors.lib import utils
    self.cursor = self.db.cursor()


def mysql_connect(sockfile):
  """Connects to the MySQL server using the specified socket file."""
  user, passwd = mysqlconf.get_user_password(sockfile)
  return MySQLdb.connect(unix_socket=sockfile,
                         connect_timeout=CONNECT_TIMEOUT,
                         user=user, passwd=passwd)


def todict(db, row):
  """Transforms a row (returned by DB.query) into a dict keyed by column names.

  Args:
    db: The DB instance from which this row was obtained.
    row: A row as returned by DB.query
  """
  d = {}
  for i, field in enumerate(db.cursor.description):
    column = field[0].lower()  # Lower-case to normalize field names.
    d[column] = row[i]
  return d

def get_dbname(sockfile):
  """Returns the name of the DB based on the path to the socket file."""
  if sockfile in DEFAULT_SOCKFILES:
    return "default"
  m = re.search("/mysql-(.+)/[^.]+\.sock$", sockfile)
  if not m:

# Path: collectors/lib/utils.py
# PY3 = sys.version_info[0] > 2
# USER = "nobody"
# def drop_privileges(user=USER):
# def is_sockfile(path):
# def err(msg):
#     def is_numeric(value):
#     def is_numeric(value):


# Path: collectors/0/mysql.py
import errno
import os
import re
import socket
import sys
import time
  import MySQLdb
from collectors.etc import mysqlconf
from collectors.lib import utils

    self.cursor = self.db.cursor()


def mysql_connect(sockfile):
  """Connects to the MySQL server using the specified socket file."""
  user, passwd = mysqlconf.get_user_password(sockfile)
  return MySQLdb.connect(unix_socket=sockfile,
                         connect_timeout=CONNECT_TIMEOUT,
                         user=user, passwd=passwd)


def todict(db, row):
  """Transforms a row (returned by DB.query) into a dict keyed by column names.

  Args:
    db: The DB instance from which this row was obtained.
    row: A row as returned by DB.query
  """
  d = {}
  for i, field in enumerate(db.cursor.description):
    column = field[0].lower()  # Lower-case to normalize field names.
    d[column] = row[i]
  return d

def get_dbname(sockfile):
  """Returns the name of the DB based on the path to the socket file."""
  if sockfile in DEFAULT_SOCKFILES:
    return "default"
  m = re.search("/mysql-(.+)/[^.]+\.sock$", sockfile)
  if not m:

    utils.err("error: couldn't guess the name of the DB for " + sockfile)