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


Python ConfigParser.DEFAULTSECT属性代码示例

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


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

示例1: write

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def write(self, fp):
        fp.writelines('\xef\xbb\xbf')
        if self._defaults:
            fp.write('[%s]\n' % DEFAULTSECT)
            for key, value in self._defaults.items():
                if type(value) is not str and type(value) is not unicode:
                    value = str(value)
                fp.write((key + ' = ' + value + '\n').encode('utf_8'))

            fp.write('\n')
        for section in self._sections:
            fp.write('[%s]\n' % section)
            for key, value in self._sections[section].items():
                if key != '__name__':
                    if type(value) is not str and type(value) is not unicode:
                        value = str(value)
                    try:
                        fp.write((key + ' = ' + value + '\n').encode('utf_8'))
                    except UnicodeDecodeError:
                        fp.write(key + ' = ' + value + '\n')

            fp.write('\n') 
开发者ID:alesnav,项目名称:p2ptv-pi,代码行数:24,代码来源:configreader.py

示例2: write

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def write(self, fp):
        """
        Write an .ini-format representation of the configuration state.
        """

        if self._defaults:
            fp.write("[%s]\n" % DEFAULTSECT)

            for (key, value) in self._defaults.items():
                fp.write("%s = %s\n" % (key, getUnicode(value, UNICODE_ENCODING).replace('\n', '\n\t')))

            fp.write("\n")

        for section in self._sections:
            fp.write("[%s]\n" % section)

            for (key, value) in self._sections[section].items():
                if key != "__name__":
                    if value is None:
                        fp.write("%s\n" % (key))
                    else:
                        fp.write("%s = %s\n" % (key, getUnicode(value, UNICODE_ENCODING).replace('\n', '\n\t')))

            fp.write("\n") 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:26,代码来源:common.py

示例3: write

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def write(self, fp):
        """
        Write an .ini-format representation of the configuration state.
        """

        if self._defaults:
            fp.write("[%s]\n" % DEFAULTSECT)

            for (key, value) in self._defaults.items():
                fp.write("%s = %s\n" % (key, getUnicode(value, "UTF8").replace('\n', '\n\t')))

            fp.write("\n")

        for section in self._sections:
            fp.write("[%s]\n" % section)

            for (key, value) in self._sections[section].items():
                if key != "__name__":
                    if value is None:
                        fp.write("%s\n" % (key))
                    else:
                        fp.write("%s = %s\n" % (key, getUnicode(value, "UTF8").replace('\n', '\n\t')))

            fp.write("\n") 
开发者ID:w-digital-scanner,项目名称:w9scan,代码行数:26,代码来源:configfile.py

示例4: dump_cfg_info

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def dump_cfg_info(self):
        cfg = cparser.ConfigParser()
        for key, val in self.config_params.iteritems():
            cfg.set(cparser.DEFAULTSECT, key, val)
        cfg.set(cparser.DEFAULTSECT,
                'json_hostname', 'unix://%s' % self.socket_path)
        cfg.set(cparser.DEFAULTSECT,
                'controller_instance_number',
                self.instance_number)
        connected_intfs = [itf
                           for itf in self.intfList()
                           if L3Router.is_l3router_intf(otherIntf(itf)) and
                           itf.name != 'lo']
        for itf in connected_intfs:
            cfg.add_section(itf.name)
            n = otherIntf(itf).node
            cfg.set(itf.name, 'hello_interval', n.hello_interval)
            cfg.set(itf.name, 'dead_interval', n.dead_interval)
        with open(self.cfg_path, 'w') as f:
            cfg.write(f)
        return (itf.name for itf in connected_intfs) 
开发者ID:Fibbing,项目名称:FibbingNode,代码行数:23,代码来源:fibbingcontroller.py

示例5: __init__

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def __init__(self):
        self.BASE_NET = ip_network(CFG.get(DEFAULTSECT, 'base_net'))
        self.private_addresses = PrivateAddressStore(CFG.get(DEFAULTSECT,
                                                             'private_ips'))
        self.last_line = ''
        self.leader_watchdog = None
        self.transaction = False
        self.uncommitted_changes = 0
        self.graph = IGPGraph()
        self._lsdb = {NetworkLSA.TYPE: {},
                      RouterLSA.TYPE: {},
                      ASExtLSA.TYPE: {}}
        self.controllers = defaultdict(list)  # controller nr : ip_list
        self.listener = {}
        self.keep_running = True
        self.queue = Queue()
        self.processing_thread = start_daemon_thread(
                target=self.process_lsa, name='lsa processing thread') 
开发者ID:Fibbing,项目名称:FibbingNode,代码行数:20,代码来源:lsdb.py

示例6: start

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def start(self, phys_ports, nodecount=None):
        """
        Start the fibbing network
        :param nodecount: Pre-allocate nodecount fibbing nodes
        """
        # Create root node
        self.root = self.add_node(id='root', cls=RootRouter, start=False)
        self.root.lsdb.set_leader_watchdog(self)
        del self.nodes[self.root.id]  # The root node should not originate LSA
        self.graph_thread.start()
        self.json_thread.start()
        # And map all physical ports to it
        ports = gen_physical_ports(phys_ports)
        for name, addr in ports:
            link = PhysicalLink(self.root, name, addr)
            self.root.add_physical_link(link)
        self.root.start()
        # Create additional nodes if requested
        if nodecount is None:
            nodecount = CFG.getint(DEFAULTSECT, 'initial_node_count')
        while nodecount > 0:
            self.add_node()
            nodecount -= 1 
开发者ID:Fibbing,项目名称:FibbingNode,代码行数:25,代码来源:fibbing.py

示例7: __contains__

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def __contains__(self, name):
    """Determine if a binding name is defined."""

    key = _normalize_key(name)
    if (key in self.__overrides
        or key in self.__lazy_initializers
        or key in self.__defaults
        or key in self.__config_parser.defaults()):
      return True

    all_sections = ([self.__section]
                    if self.__section
                    else self.__config_parser.sections())
    if not all_sections:
      all_sections = [ConfigParser.DEFAULTSECT]

    for section in all_sections:
      if self.__config_parser.has_option(section, key):
        return True
    return False 
开发者ID:google,项目名称:citest,代码行数:22,代码来源:bindings.py

示例8: do_cfg

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def do_cfg(self, line=''):
        part = line.split(' ')
        val = part.pop()
        key = part.pop()
        sect = part.pop() if part else DEFAULTSECT
        CFG.set(sect, key, val) 
开发者ID:Fibbing,项目名称:FibbingNode,代码行数:8,代码来源:main.py

示例9: handle_args

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def handle_args():
    parser = argparse.ArgumentParser(description='Starts a fibbing node.')
    parser.add_argument('ports', metavar='IF', type=str, nargs='*',
                        help='A physical interface to use')
    parser.add_argument('--debug', action='store_true', default=False,
                        help='Debug (default: disabled)')
    parser.add_argument('--nocli', action='store_true', default=False,
                        help='Disable the CLI')
    parser.add_argument('--cfg', help='Use specified config file',
                        default=None)
    args = parser.parse_args()

    instance_count = CFG.getint(DEFAULTSECT, 'controller_instance_number')

    # Update default config
    if args.cfg:
        CFG.read(args.cfg)
        fibbingnode.BIN = CFG.get(DEFAULTSECT, 'quagga_path')
    # Check if we need to force debug mode
    if args.debug:
        CFG.set(DEFAULTSECT, 'debug', '1')
    if CFG.getboolean(DEFAULTSECT, 'debug'):
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)
    # Check for any specified physical port to use both in config file
    # or in args
    ports = set(p for p in CFG.sections()
                if not (p == 'fake' or p == 'physical' or p == DEFAULTSECT))
    ports.update(args.ports)
    if not ports:
        log.warning('The fibbing node will not be connected '
                    'to any physical ports!')
    else:
        log.info('Using the physical ports: %s', ports)
    return ports, instance_count, not args.nocli 
开发者ID:Fibbing,项目名称:FibbingNode,代码行数:38,代码来源:main.py

示例10: __init__

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def __init__(self, instance_number):
        """
        :param instance_number: the controller instance number
        :param net: the subnet allocated for the fibbing nodes
        """
        self.leader = False
        self.instance = instance_number
        self.name = 'c%s' % instance_number
        self.nodes = {}
        self.bridge = Bridge('br0', self.name)
        self.root = None
        net = ip_network(CFG.get(DEFAULTSECT, 'base_net'))
        controller_prefix = CFG.getint(DEFAULTSECT, 'controller_prefixlen')
        host_prefix = net.max_prefixlen - controller_prefix
        controller_base = (int(net.network_address) +
                           (instance_number << host_prefix))
        controller_net = ip_address(controller_base)
        self.net = ip_network('%s/%s' % (controller_net, controller_prefix))
        self.graph_thread = daemon_thread(target=self.infer_graph,
                                          name="Graph inference thread")
        self.json_proxy = SJMPServer(hostname=CFG.get(DEFAULTSECT,
                                                      'json_hostname'),
                                     port=CFG.getint(DEFAULTSECT,
                                                     'json_port'),
                                     invoke=self.proxy_connected,
                                     target=FakeNodeProxyImplem(self))
        self.json_thread = daemon_thread(target=self.json_proxy.communicate,
                                         name="JSON proxy thread")
        # Used to assign unique router-id to each node
        self.next_id = 1
        self.links = []
        # The fibbing routes
        self.routes = {}
        self.route_mappings = {} 
开发者ID:Fibbing,项目名称:FibbingNode,代码行数:36,代码来源:fibbing.py

示例11: __init__

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def __init__(self, *args, **kwargs):
        super(SouthboundListener, self).__init__(*args, **kwargs)
        self.igp_graph = IGPGraph()
        self.dirty = False
        self.json_proxy = SJMPClient(hostname=CFG.get(DEFAULTSECT,
                                                      'json_hostname'),
                                     port=CFG.getint(DEFAULTSECT, 'json_port'),
                                     target=self)
        self.quagga_manager = ProxyCloner(FakeNodeProxy, self.json_proxy) 
开发者ID:Fibbing,项目名称:FibbingNode,代码行数:11,代码来源:southbound_interface.py

示例12: _do_get

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def _do_get(self, name, default_value):
    """Helper function for looking up binding values.

    Args:
      name: [string] The name of the binding will be normalized internally.
      default_value: [string] The value to return if not otherwise found.

    Returns:
      The binding value as either an override, config_value or default value.
      Config values will come from the first section it is found in (or the
      specific section this instance was configured for).
    """
    key = _normalize_key(name)
    if key in self.__overrides:
      return _normalize_value(self.__overrides[key])

    all_sections = ([self.__section]
                    if self.__section
                    else self.__config_parser.sections())
    if not all_sections:
      all_sections = [ConfigParser.DEFAULTSECT]

    for section in all_sections:
      if self.__config_parser.has_option(section, key):
        return _normalize_value(self.__config_parser.get(section, key)
                                or default_value)

    lazy_init = self.__lazy_initializers.get(key)
    if lazy_init is not None:
      lazy_value = lazy_init(self, key)
      if lazy_value is not None:
        self.__overrides[key] = lazy_value
        return _normalize_value(lazy_value)

    if key in self.__config_parser.defaults():
      return _normalize_value(self.__config_parser.defaults()[key])

    return _normalize_value(self.__defaults.get(key, default_value)) 
开发者ID:google,项目名称:citest,代码行数:40,代码来源:bindings.py

示例13: _write

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def _write(self, fp):
        """Write an .ini-format representation of the configuration state in
        git compatible format"""
        def write_section(name, section_dict):
            fp.write(("[%s]\n" % name).encode(defenc))
            for (key, value) in section_dict.items():
                if key != "__name__":
                    fp.write(("\t%s = %s\n" % (key, self._value_to_string(value).replace('\n', '\n\t'))).encode(defenc))
                # END if key is not __name__
        # END section writing

        if self._defaults:
            write_section(cp.DEFAULTSECT, self._defaults)
        for name, value in self._sections.items():
            write_section(name, value) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:17,代码来源:config.py

示例14: build_graph

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import DEFAULTSECT [as 别名]
def build_graph(self):
        self.controllers.clear()
        new_graph = IGPGraph()
        # Rebuild the graph from the LSDB
        for lsa in chain(self.routers.itervalues(),
                         self.networks.itervalues(),
                         self.ext_networks.itervalues()):

            if is_expired_lsa(lsa):
                log.debug("LSA %s is too old (%d) ignoring it!",
                          lsa, lsa.age)
            else:
                lsa.apply(new_graph, self)
        # Contract all IPs to their respective router-id
        for rlsa in self.routers.itervalues():
            rlsa.contract_graph(new_graph,
                                self.private_addresses
                                .addresses_of(rlsa.routerid))
        # Figure out the controllers layout
        controller_prefix = CFG.getint(DEFAULTSECT, 'controller_prefixlen')
        # Group by controller and log them
        for ip in new_graph.nodes_iter():
            try:
                addr = ip_address(ip)
            except ValueError:
                continue  # Have a prefix
            if addr in self.BASE_NET:
                """1. Compute address diff to remove base_net
                   2. Right shift to remove host bits
                   3. Mask with controller mask"""
                cid = (((int(addr) - int(self.BASE_NET.network_address)) >>
                        self.BASE_NET.max_prefixlen - controller_prefix) &
                       ((1 << controller_prefix) - 1))
                self.controllers[cid].append(ip)
        # Contract them on the graph
        for id, ips in self.controllers.iteritems():
            cname = 'C_%s' % id
            new_graph.add_controller(cname)
            new_graph.contract(cname, ips)
        # Remove generated self loops
        new_graph.remove_edges_from(new_graph.selfloop_edges())
        self.apply_secondary_addresses(new_graph)
        return new_graph 
开发者ID:Fibbing,项目名称:FibbingNode,代码行数:45,代码来源:lsdb.py


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