Python ConfigParser.DEFAULTSECT Examples
The following are 18
code examples of ConfigParser.DEFAULTSECT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ConfigParser
, or try the search function
.
Example #1
Source File: common.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
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")
Example #2
Source File: common.py From EasY_HaCk with Apache License 2.0 | 6 votes |
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")
Example #3
Source File: common.py From POC-EXP with GNU General Public License v3.0 | 6 votes |
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")
Example #4
Source File: bindings.py From citest with Apache License 2.0 | 6 votes |
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
Example #5
Source File: fibbing.py From FibbingNode with GNU General Public License v2.0 | 6 votes |
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
Example #6
Source File: lsdb.py From FibbingNode with GNU General Public License v2.0 | 6 votes |
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')
Example #7
Source File: fibbingcontroller.py From FibbingNode with GNU General Public License v2.0 | 6 votes |
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)
Example #8
Source File: configfile.py From w9scan with GNU General Public License v2.0 | 6 votes |
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")
Example #9
Source File: common.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
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")
Example #10
Source File: configreader.py From p2ptv-pi with MIT License | 6 votes |
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')
Example #11
Source File: main.py From FibbingNode with GNU General Public License v2.0 | 5 votes |
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
Example #12
Source File: main.py From FibbingNode with GNU General Public License v2.0 | 5 votes |
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)
Example #13
Source File: fibbing.py From FibbingNode with GNU General Public License v2.0 | 5 votes |
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 = {}
Example #14
Source File: fibbing.py From FibbingNode with GNU General Public License v2.0 | 5 votes |
def __init__(self, address, metric, node): """ :param address: The forwarding address to specify for this attraction point :param metric: The metric of this attraction point :param node: The node advertizing this :return: """ self._address = address self.metric = metric self.node = node self.advertized = False self.ttl = CFG.get(DEFAULTSECT, 'fake_lsa_ttl')
Example #15
Source File: southbound_interface.py From FibbingNode with GNU General Public License v2.0 | 5 votes |
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)
Example #16
Source File: bindings.py From citest with Apache License 2.0 | 5 votes |
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))
Example #17
Source File: config.py From bazarr with GNU General Public License v3.0 | 5 votes |
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)
Example #18
Source File: lsdb.py From FibbingNode with GNU General Public License v2.0 | 4 votes |
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