当前位置: 首页>>代码示例>>Python>>正文


Python ConfigParser.Error方法代码示例

本文整理汇总了Python中ConfigParser.Error方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.Error方法的具体用法?Python ConfigParser.Error怎么用?Python ConfigParser.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigParser的用法示例。


在下文中一共展示了ConfigParser.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_user

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def create_user(conn, username, password):
    try:
        cur = conn.cursor()
        cur.execute("SELECT passwd FROM pg_shadow WHERE usename = %s", [username])
        row = cur.fetchone()
        if row:
            m = hashlib.md5()
            m.update(password + username)
            encrypted_password = "md5" + m.hexdigest()
            if encrypted_password != row[0]:
                cur.execute("ALTER USER " + username + " ENCRYPTED PASSWORD %s SUPERUSER REPLICATION", [password])
        else:
            cur.execute("CREATE USER " + username + " WITH ENCRYPTED PASSWORD %s SUPERUSER REPLICATION", [password])
        conn.commit()
        return True
    except psycopg2.Error as e:
        print(e)
        conn.rollback()
        return False 
开发者ID:rtshome,项目名称:pgrepup,代码行数:21,代码来源:database.py

示例2: get_pg_hba_contents

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def get_pg_hba_contents(conn):
    pg_hba_path = get_setting_value(conn, "hba_file")
    if not pg_hba_path:
        return None

    try:
        temp_table = "pghba_" + uuid.uuid4().hex
        cur = conn.cursor()
        cur.execute("CREATE TEMP TABLE " + temp_table + " (content text)")
        cur.execute("COPY " + temp_table + " FROM %s", [pg_hba_path])
        cur.execute("SELECT * FROM " + temp_table + ";")
        rows = cur.fetchall()
        conn.rollback()
        return rows
    except psycopg2.Error as e:
        print(e)
        return None 
开发者ID:rtshome,项目名称:pgrepup,代码行数:19,代码来源:database.py

示例3: saveProxyLog

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def saveProxyLog(name, config):
    '''
    Save proxy log database into a new file

    :param name: Name of file to save data into (should be .db)
    :param config: Proxy ConfigParser object from proxy.ini
    :return: None
    '''

    log = config.get("DATABASE", "filename")
    oldpath = os.path.join(faradayHelper.userPath, 'lib', log)
    newpath = os.path.join(faradayHelper.userPath, 'lib', name)

    try:
        shutil.move(oldpath, newpath)
        sys.exit(0)

    except shutil.Error as e:
        logger.error(e)
    except IOError as e:
        logger.error(e) 
开发者ID:FaradayRF,项目名称:Faraday-Software,代码行数:23,代码来源:proxy.py

示例4: sqlBeginRead

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def sqlBeginRead(conn):
    """
    Starts a read by executing SQL and returning a cursor

    :param conn: Database connection
    :return: cursor or None if we encountered a problem
    """

    sql = "SELECT KEYID, PORT, BASE64, EPOCH FROM PROXY"
    cursor = None

    try:
        # Use connection as context manager to rollback automatically if error
        with conn:
            cursor = conn.cursor()
            cursor.execute(sql)

    except sqlite3.Error as e:
        logger.error("Sqlite3.Error: " + str(e))
        conn.close()
        return None

    return cursor 
开发者ID:FaradayRF,项目名称:Faraday-Software,代码行数:25,代码来源:proxy.py

示例5: saveTelemetryLog

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def saveTelemetryLog(name, config):
    '''
    Save telemetry log database into a new file

    :param name: Name of file to save data into (should be .db)
    :param config: Telemetry ConfigParser object from telmetry.ini
    :return: None
    '''

    log = config.get("DATABASE", "filename")
    oldpath = os.path.join(faradayHelper.userPath, 'lib', log)
    newpath = os.path.join(faradayHelper.userPath, 'lib', name)
    try:
        shutil.move(oldpath, newpath)
        sys.exit(0)

    except shutil.Error as e:
        logger.error(e)
    except IOError as e:
        logger.error(e) 
开发者ID:FaradayRF,项目名称:Faraday-Software,代码行数:22,代码来源:telemetry.py

示例6: callSolver

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def callSolver(self, isMIP):
            """Solves the problem with cplex
            """
            #solve the problem
            self.cplexTime = -clock()
            if isMIP and self.mip:
                status= CPLEX_DLL.lib.CPXmipopt(self.env, self.hprob)
                if status != 0:
                    raise PulpSolverError("Error in CPXmipopt status="
                                        + str(status))
            else:
                status = CPLEX_DLL.lib.CPXlpopt(self.env, self.hprob)
                if status != 0:
                    raise PulpSolverError("Error in CPXlpopt status="
                                            + str(status))
            self.cplexTime += clock() 
开发者ID:QuantEcon,项目名称:MatchingMarkets.py,代码行数:18,代码来源:solvers.py

示例7: _applyConfigurationToValues

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def _applyConfigurationToValues(self, parser, config, values):
        for name, value, filename in config:
            if name in option_blacklist:
                continue
            try:
                self._processConfigValue(name, value, values, parser)
            except NoSuchOptionError, exc:
                self._file_error(
                    "Error reading config file %r: "
                    "no such option %r" % (filename, exc.name),
                    name=name, filename=filename)
            except optparse.OptionValueError, exc:
                msg = str(exc).replace('--' + name, repr(name), 1)
                self._file_error("Error reading config file %r: "
                                 "%s" % (filename, msg),
                                 name=name, filename=filename) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:18,代码来源:config.py

示例8: is_valid

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def is_valid(self):
        # Using BytesIO as configparser in 2.7 can't work with unicode
        # see http://bugs.python.org/issue11597
        with BytesIO(self.content) as buf:
            self.config = configparser.ConfigParser()
            try:
                try:
                    # Try python3 method
                    self.config.read_string(self._content)
                except AttributeError:
                    # Fall back to python2 method
                    self.config.readfp(buf)  # pylint: disable=deprecated-method
            except configparser.Error:
                logger.warning("Invalid repo file found: '%s'", self.content)
                return False
            else:
                return True 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:19,代码来源:yum.py

示例9: set_from_config_file

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def set_from_config_file(self, filename):
        """ Loads lint config from a ini-style config file """
        if not os.path.exists(filename):
            raise LintConfigError(u"Invalid file path: {0}".format(filename))
        self._config_path = os.path.realpath(filename)
        try:
            parser = ConfigParser()

            with io.open(filename, encoding=DEFAULT_ENCODING) as config_file:
                # readfp() is deprecated in python 3.2+, but compatible with 2.7
                parser.readfp(config_file, filename)  # pylint: disable=deprecated-method

            for section_name in parser.sections():
                for option_name, option_value in parser.items(section_name):
                    self.set_option(section_name, option_name, ustr(option_value))

        except ConfigParserError as e:
            raise LintConfigError(ustr(e)) 
开发者ID:jorisroovers,项目名称:gitlint,代码行数:20,代码来源:config.py

示例10: get_repository_config

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def get_repository_config(self, repository):
        """Get config dictionary for the given repository.

        If the repository section is not found in the config file,
        return ``None``.  If the file is invalid, raise
        :exc:`configparser.Error`.

        Otherwise return a dictionary with:

        * ``'repository'`` -- the repository URL
        * ``'username'`` -- username for authentication
        * ``'password'`` -- password for authentication

        :param repository:
            Name or URL of the repository to find in the ``.pypirc`` file.
            The repository section must be defined in the config file.

        """
        servers = self._read_index_servers()
        repo_config = self._find_repo_config(servers, repository)
        return repo_config 
开发者ID:dagster-io,项目名称:dagster,代码行数:23,代码来源:pypirc.py

示例11: get_database_count

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def get_database_count(conn):
    try:
        cur = conn.cursor()
        cur.execute("SELECT COUNT(*) FROM pg_database WHERE datallowconn='t';")
        return cur.fetchone()[0]
    except psycopg2.Error:
        return None 
开发者ID:rtshome,项目名称:pgrepup,代码行数:9,代码来源:database.py

示例12: get_cluster_databases

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def get_cluster_databases(conn):
    try:
        databases = []
        cur = conn.cursor()
        cur.execute("SELECT datname FROM pg_database WHERE datallowconn='t';")
        for d in cur.fetchall():
            databases.append(d[0])
        return databases
    except psycopg2.Error:
        return None 
开发者ID:rtshome,项目名称:pgrepup,代码行数:12,代码来源:database.py

示例13: drop_extension

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def drop_extension(conn, extension_name):
    cur = conn.cursor()
    try:
        cur.execute("DROP EXTENSION IF EXISTS %s CASCADE" % extension_name)
        cur.execute("DROP SCHEMA IF EXISTS pglogical CASCADE")
        conn.commit()
    except psycopg2.Error:
        conn.rollback()
    return True 
开发者ID:rtshome,项目名称:pgrepup,代码行数:11,代码来源:database.py

示例14: get_setting_value

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def get_setting_value(conn, name):
    try:
        cur = conn.cursor()
        cur.execute("SELECT setting FROM pg_settings WHERE name=%s;", [name])
        return cur.fetchone()[0]
    except psycopg2.Error:
        return None 
开发者ID:rtshome,项目名称:pgrepup,代码行数:9,代码来源:database.py

示例15: drop_user

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import Error [as 别名]
def drop_user(conn, username):
    try:
        cur = conn.cursor()
        cur.execute("SELECT passwd FROM pg_shadow WHERE usename = %s", [username])
        row = cur.fetchone()
        if row:
            cur.execute("DROP OWNED BY " + username + " CASCADE")
        cur.execute("DROP USER IF EXISTS " + username)
        conn.commit()
        return True
    except psycopg2.Error as e:
        print(e)
        conn.rollback()
        return False 
开发者ID:rtshome,项目名称:pgrepup,代码行数:16,代码来源:database.py


注:本文中的ConfigParser.Error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。