_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q18500
Nipap._parse_vrf_query
train
def _parse_vrf_query(self, query_str): """ Parse a smart search query for VRFs This is a helper function to smart_search_vrf for easier unit testing of the parser. """ sp = smart_parsing.VrfSmartParser() query = sp.parse(query_str) return query
python
{ "resource": "" }
q18501
Nipap.add_pool
train
def add_pool(self, auth, attr): """ Create a pool according to `attr`. * `auth` [BaseAuth] AAA options. * `attr` [pool_attr] A dict containing the attributes the new pool should have. Returns a dict describing the pool which was added. ...
python
{ "resource": "" }
q18502
Nipap.list_pool
train
def list_pool(self, auth, spec=None): """ Return a list of pools. * `auth` [BaseAuth] AAA options. * `spec` [pool_spec] Specifies what pool(s) to list. Of omitted, all will be listed. Returns a list of dicts. This is the document...
python
{ "resource": "" }
q18503
Nipap._check_pool_attr
train
def _check_pool_attr(self, attr, req_attr=None): """ Check pool attributes. """ if req_attr is None: req_attr = [] # check attribute names self._check_attr(attr, req_attr, _pool_attrs) # validate IPv4 prefix length if attr.get('ipv4_default_prefix_l...
python
{ "resource": "" }
q18504
Nipap._get_pool
train
def _get_pool(self, auth, spec): """ Get a pool. Shorthand function to reduce code in the functions below, since more or less all of them needs to perform the actions that are specified here. The major difference to :func:`list_pool` is that an exception ...
python
{ "resource": "" }
q18505
Nipap.edit_pool
train
def edit_pool(self, auth, spec, attr): """ Update pool given by `spec` with attributes `attr`. * `auth` [BaseAuth] AAA options. * `spec` [pool_spec] Specifies what pool to edit. * `attr` [pool_attr] Attributes to update and the...
python
{ "resource": "" }
q18506
Nipap.smart_search_pool
train
def smart_search_pool(self, auth, query_str, search_options=None, extra_query=None): """ Perform a smart search on pool list. * `auth` [BaseAuth] AAA options. * `query_str` [string] Search string * `search_options` [options_dict] ...
python
{ "resource": "" }
q18507
Nipap._parse_pool_query
train
def _parse_pool_query(self, query_str): """ Parse a smart search query for pools This is a helper function to smart_search_pool for easier unit testing of the parser. """ sp = smart_parsing.PoolSmartParser() query = sp.parse(query_str) return query
python
{ "resource": "" }
q18508
Nipap._expand_prefix_spec
train
def _expand_prefix_spec(self, spec, prefix = ''): """ Expand prefix specification to SQL. """ # sanity checks if type(spec) is not dict: raise NipapInputError('invalid prefix specification') for key in spec.keys(): if key not in _prefix_spec: ...
python
{ "resource": "" }
q18509
Nipap._expand_prefix_query
train
def _expand_prefix_query(self, query, table_name = None): """ Expand prefix query dict into a WHERE-clause. If you need to prefix each column reference with a table name, that can be supplied via the table_name argument. """ where = unicode() opt = list() ...
python
{ "resource": "" }
q18510
Nipap._db_remove_prefix
train
def _db_remove_prefix(self, spec, recursive = False): """ Do the underlying database operations to delete a prefix """ if recursive: prefix = spec['prefix'] del spec['prefix'] where, params = self._expand_prefix_spec(spec) spec['prefix'] = prefix ...
python
{ "resource": "" }
q18511
Nipap.remove_prefix
train
def remove_prefix(self, auth, spec, recursive = False): """ Remove prefix matching `spec`. * `auth` [BaseAuth] AAA options. * `spec` [prefix_spec] Specifies prefixe to remove. * `recursive` [bool] When set to True, also remove ...
python
{ "resource": "" }
q18512
Nipap.smart_search_prefix
train
def smart_search_prefix(self, auth, query_str, search_options=None, extra_query=None): """ Perform a smart search on prefix list. * `auth` [BaseAuth] AAA options. * `query_str` [string] Search string * `search_options` [options_dict] ...
python
{ "resource": "" }
q18513
Nipap._parse_prefix_query
train
def _parse_prefix_query(self, query_str): """ Parse a smart search query for prefixes This is a helper function to smart_search_prefix for easier unit testing of the parser. """ sp = smart_parsing.PrefixSmartParser() query = sp.parse(query_str) return que...
python
{ "resource": "" }
q18514
Nipap.list_asn
train
def list_asn(self, auth, asn=None): """ List AS numbers matching `spec`. * `auth` [BaseAuth] AAA options. * `spec` [asn_spec] An automous system number specification. If omitted, all ASNs are returned. Returns a list of dicts....
python
{ "resource": "" }
q18515
Nipap.add_asn
train
def add_asn(self, auth, attr): """ Add AS number to NIPAP. * `auth` [BaseAuth] AAA options. * `attr` [asn_attr] ASN attributes. Returns a dict describing the ASN which was added. This is the documentation of the internal backend ...
python
{ "resource": "" }
q18516
Nipap.edit_asn
train
def edit_asn(self, auth, asn, attr): """ Edit AS number * `auth` [BaseAuth] AAA options. * `asn` [integer] AS number to edit. * `attr` [asn_attr] New AS attributes. This is the documentation of the internal backend...
python
{ "resource": "" }
q18517
Nipap.remove_asn
train
def remove_asn(self, auth, asn): """ Remove an AS number. * `auth` [BaseAuth] AAA options. * `spec` [asn] An ASN specification. Remove ASNs matching the `asn` argument. This is the documentation of the internal backend function. ...
python
{ "resource": "" }
q18518
Nipap.smart_search_asn
train
def smart_search_asn(self, auth, query_str, search_options=None, extra_query=None): """ Perform a smart search operation among AS numbers * `auth` [BaseAuth] AAA options. * `query_str` [string] Search string * `search_options` [options_dict] ...
python
{ "resource": "" }
q18519
Nipap._parse_asn_query
train
def _parse_asn_query(self, query_str): """ Parse a smart search query for ASNs This is a helper function to smart_search_asn for easier unit testing of the parser. """ # find query parts query_str_parts = self._get_query_parts(query_str) # go through par...
python
{ "resource": "" }
q18520
Nipap._expand_tag_query
train
def _expand_tag_query(self, query, table_name = None): """ Expand Tag query dict into a WHERE-clause. If you need to prefix each column reference with a table name, that can be supplied via the table_name argument. """ where = unicode() opt = list() # h...
python
{ "resource": "" }
q18521
setup_connection
train
def setup_connection(): """ Set up the global pynipap connection object """ # get connection parameters, first from environment variables if they are # defined, otherwise from .nipaprc try: con_params = { 'username': os.getenv('NIPAP_USERNAME') or cfg.get('global', 'username'), ...
python
{ "resource": "" }
q18522
get_pool
train
def get_pool(arg = None, opts = None, abort = False): """ Returns pool to work with Returns a pynipap.Pool object representing the pool we are working with. """ # yep, global variables are evil global pool try: pool = Pool.list({ 'name': arg })[0] except IndexError: if ...
python
{ "resource": "" }
q18523
get_vrf
train
def get_vrf(arg = None, default_var = 'default_vrf_rt', abort = False): """ Returns VRF to work in Returns a pynipap.VRF object representing the VRF we are working in. If there is a VRF set globally, return this. If not, fetch the VRF named 'arg'. If 'arg' is None, fetch the default_vrf ...
python
{ "resource": "" }
q18524
list_pool
train
def list_pool(arg, opts, shell_opts): """ List pools matching a search criteria """ search_string = '' if type(arg) == list or type(arg) == tuple: search_string = ' '.join(arg) v = get_vrf(opts.get('vrf_rt'), default_var='default_list_vrf_rt', abort=True) if v.rt == 'all': vrf...
python
{ "resource": "" }
q18525
list_vrf
train
def list_vrf(arg, opts, shell_opts): """ List VRFs matching a search criteria """ search_string = '' if type(arg) == list or type(arg) == tuple: search_string = ' '.join(arg) offset = 0 limit = 100 while True: res = VRF.smart_search(search_string, { 'offset': offset, 'max_r...
python
{ "resource": "" }
q18526
_prefix_from_opts
train
def _prefix_from_opts(opts): """ Return a prefix based on options passed from command line Used by add_prefix() and add_prefix_from_pool() to avoid duplicate parsing """ p = Prefix() p.prefix = opts.get('prefix') p.type = opts.get('type') p.description = opts.get('description') ...
python
{ "resource": "" }
q18527
add_vrf
train
def add_vrf(arg, opts, shell_opts): """ Add VRF to NIPAP """ v = VRF() v.rt = opts.get('rt') v.name = opts.get('name') v.description = opts.get('description') v.tags = list(csv.reader([opts.get('tags', '')], escapechar='\\'))[0] for avp in opts.get('extra-attribute', []): try: ...
python
{ "resource": "" }
q18528
view_vrf
train
def view_vrf(arg, opts, shell_opts): """ View a single VRF """ if arg is None: print("ERROR: Please specify the RT of the VRF to view.", file=sys.stderr) sys.exit(1) # interpret as default VRF (ie, RT = None) if arg.lower() in ('-', 'none'): arg = None try: v =...
python
{ "resource": "" }
q18529
modify_vrf
train
def modify_vrf(arg, opts, shell_opts): """ Modify a VRF with the options set in opts """ res = VRF.list({ 'rt': arg }) if len(res) < 1: print("VRF with [RT: %s] not found." % arg, file=sys.stderr) sys.exit(1) v = res[0] if 'rt' in opts: v.rt = opts['rt'] if 'name' ...
python
{ "resource": "" }
q18530
modify_pool
train
def modify_pool(arg, opts, shell_opts): """ Modify a pool with the options set in opts """ res = Pool.list({ 'name': arg }) if len(res) < 1: print("No pool with name '%s' found." % arg, file=sys.stderr) sys.exit(1) p = res[0] if 'name' in opts: p.name = opts['name'] ...
python
{ "resource": "" }
q18531
grow_pool
train
def grow_pool(arg, opts, shell_opts): """ Expand a pool with the ranges set in opts """ if not pool: print("No pool with name '%s' found." % arg, file=sys.stderr) sys.exit(1) if not 'add' in opts: print("Please supply a prefix to add to pool '%s'" % pool.name, file=sys.stderr) ...
python
{ "resource": "" }
q18532
shrink_pool
train
def shrink_pool(arg, opts, shell_opts): """ Shrink a pool by removing the ranges in opts from it """ if not pool: print("No pool with name '%s' found." % arg, file=sys.stderr) sys.exit(1) if 'remove' in opts: res = Prefix.list({'prefix': opts['remove'], 'pool_id': pool.id}) ...
python
{ "resource": "" }
q18533
prefix_attr_add
train
def prefix_attr_add(arg, opts, shell_opts): """ Add attributes to a prefix """ spec = { 'prefix': arg } v = get_vrf(opts.get('vrf_rt'), abort=True) spec['vrf_rt'] = v.rt res = Prefix.list(spec) if len(res) == 0: print("Prefix %s not found in %s." % (arg, vrf_format(v)), file=sys.st...
python
{ "resource": "" }
q18534
vrf_attr_add
train
def vrf_attr_add(arg, opts, shell_opts): """ Add attributes to a VRF """ if arg is None: print("ERROR: Please specify the RT of the VRF to view.", file=sys.stderr) sys.exit(1) # interpret as default VRF (ie, RT = None) if arg.lower() in ('-', 'none'): arg = None try: ...
python
{ "resource": "" }
q18535
pool_attr_add
train
def pool_attr_add(arg, opts, shell_opts): """ Add attributes to a pool """ res = Pool.list({ 'name': arg }) if len(res) < 1: print("No pool with name '%s' found." % arg, file=sys.stderr) sys.exit(1) p = res[0] for avp in opts.get('extra-attribute', []): try: ...
python
{ "resource": "" }
q18536
_complete_string
train
def _complete_string(key, haystack): """ Returns valid string completions Takes the string 'key' and compares it to each of the strings in 'haystack'. The ones which beginns with 'key' are returned as result. """ if len(key) == 0: return haystack match = [] for straw in ha...
python
{ "resource": "" }
q18537
complete_tags
train
def complete_tags(arg): """ Complete NIPAP prefix type """ search_string = '^' if arg is not None: search_string += arg res = Tag.search({ 'operator': 'regex_match', 'val1': 'name', 'val2': search_string }) ret = [] for t in res['result']: ret.ap...
python
{ "resource": "" }
q18538
complete_pool_members
train
def complete_pool_members(arg): """ Complete member prefixes of pool """ # pool should already be globally set res = [] for member in Prefix.list({ 'pool_id': pool.id }): res.append(member.prefix) return _complete_string(arg, res)
python
{ "resource": "" }
q18539
complete_node
train
def complete_node(arg): """ Complete node hostname This function is currently a bit special as it looks in the config file for a command to use to complete a node hostname from an external system. It is configured by setting the config attribute "complete_node_cmd" to a she...
python
{ "resource": "" }
q18540
complete_pool_name
train
def complete_pool_name(arg): """ Returns list of matching pool names """ search_string = '^' if arg is not None: search_string += arg res = Pool.search({ 'operator': 'regex_match', 'val1': 'name', 'val2': search_string }) ret = [] for p in res['result']...
python
{ "resource": "" }
q18541
SmartParser._string_to_ast
train
def _string_to_ast(self, input_string): """ Parse a smart search string and return it in an AST like form """ # simple words # we need to use a regex to match on words because the regular # Word(alphanums) will only match on American ASCII alphanums and since # we try to...
python
{ "resource": "" }
q18542
Command._examine_key
train
def _examine_key(self, key_name, key_val, p, i, option_parsing): """ Examine the current matching key Extracts information, such as function to execute and command options, from the current key (passed to function as 'key_name' and 'key_val'). """ # if the e...
python
{ "resource": "" }
q18543
Command.parse_cmd
train
def parse_cmd(self, tree, inp_cmd = None): """ Extract command and options from string. The tree argument should contain a specifically formatted dict which describes the available commands, options, arguments and callbacks to methods for completion of arguments. ...
python
{ "resource": "" }
q18544
Command.complete
train
def complete(self): """ Return list of valid completions Returns a list of valid completions on the current level in the tree. If an element of type 'value' is found, its complete callback function is called (if set). """ comp = [] for k, v in self.k...
python
{ "resource": "" }
q18545
Command.next_values
train
def next_values(self): """ Return list of valid next values """ nval = [] for k, v in self.children.items(): # if we have reached a value, try to fetch valid completions if v['type'] == 'value': if 'complete' in v: nval += v[...
python
{ "resource": "" }
q18546
PoolController.remove
train
def remove(self, id): """ Remove pool. """ p = Pool.get(int(id)) p.remove() redirect(url(controller = 'pool', action = 'list'))
python
{ "resource": "" }
q18547
PoolController.remove_prefix
train
def remove_prefix(self, id): """ Remove a prefix from pool 'id'. """ if 'prefix' not in request.params: abort(400, 'Missing prefix.') prefix = Prefix.get(int(request.params['prefix'])) prefix.pool = None prefix.save() redirect(url(controller = 'pool'...
python
{ "resource": "" }
q18548
add_ip_to_net
train
def add_ip_to_net(networks, host): """ Add hosts from ipplan to networks object. """ for network in networks: if host['ipaddr'] in network['network']: network['hosts'].append(host) return
python
{ "resource": "" }
q18549
get_networks
train
def get_networks(base_file, ipaddr_file): """ Gather network and host information from ipplan export files. """ networks = [] base = open(base_file, 'r') csv_reader = csv.reader(base, delimiter='\t') buffer = "" for row in csv_reader: # Fixes quotation bug in ipplan exporter for base...
python
{ "resource": "" }
q18550
add_prefix
train
def add_prefix(network): """ Put your network information in the prefix object. """ p = new_prefix() p.prefix = str(network['network']) p.type = "assignment" p.description = network['description'] p.tags = ['ipplan-import'] p.comment = "" if 'additional' in network: p.comment +=...
python
{ "resource": "" }
q18551
add_host
train
def add_host(host): """ Put your host information in the prefix object. """ p = new_prefix() p.prefix = str(host['ipaddr']) p.type = "host" p.description = host['description'] p.node = host['fqdn'] p.avps = {} # Use remaining data from ipplan to populate comment field. if 'additiona...
python
{ "resource": "" }
q18552
nipapd_version
train
def nipapd_version(): """ Get version of nipapd we're connected to. Maps to the function :py:func:`nipap.xmlrpc.NipapXMLRPC.version` in the XML-RPC API. Please see the documentation for the XML-RPC function for information regarding the return value. """ xmlrpc = XMLRPCConnection()...
python
{ "resource": "" }
q18553
nipap_db_version
train
def nipap_db_version(): """ Get schema version of database we're connected to. Maps to the function :py:func:`nipap.backend.Nipap._get_db_version` in the backend. Please see the documentation for the backend function for information regarding the return value. """ xmlrpc = XMLRPCCo...
python
{ "resource": "" }
q18554
_fault_to_exception
train
def _fault_to_exception(f): """ Converts XML-RPC Fault objects to Pynipap-exceptions. TODO: Is this one neccesary? Can be done inline... """ e = _fault_to_exception_map.get(f.faultCode) if e is None: e = NipapError return e(f.faultString)
python
{ "resource": "" }
q18555
Tag.from_dict
train
def from_dict(cls, tag=None): """ Create new Tag-object from dict. Suitable for creating objects from XML-RPC data. All available keys must exist. """ if tag is None: tag = {} l = Tag() l.name = tag['name'] return l
python
{ "resource": "" }
q18556
Tag.search
train
def search(cls, query, search_opts=None): """ Search tags. For more information, see the backend function :py:func:`nipap.backend.Nipap.search_tag`. """ if search_opts is None: search_opts = {} xmlrpc = XMLRPCConnection() try: se...
python
{ "resource": "" }
q18557
VRF.list
train
def list(cls, vrf=None): """ List VRFs. Maps to the function :py:func:`nipap.backend.Nipap.list_vrf` in the backend. Please see the documentation for the backend function for information regarding input arguments and return values. """ if vrf is None: ...
python
{ "resource": "" }
q18558
VRF.from_dict
train
def from_dict(cls, parm, vrf = None): """ Create new VRF-object from dict. Suitable for creating objects from XML-RPC data. All available keys must exist. """ if vrf is None: vrf = VRF() vrf.id = parm['id'] vrf.rt = parm['rt'] vrf.na...
python
{ "resource": "" }
q18559
VRF.get
train
def get(cls, id): """ Get the VRF with id 'id'. """ # cached? if CACHE: if id in _cache['VRF']: log.debug('cache hit for VRF %d' % id) return _cache['VRF'][id] log.debug('cache miss for VRF %d' % id) try: vrf =...
python
{ "resource": "" }
q18560
VRF.search
train
def search(cls, query, search_opts=None): """ Search VRFs. Maps to the function :py:func:`nipap.backend.Nipap.search_vrf` in the backend. Please see the documentation for the backend function for information regarding input arguments and return values. """ i...
python
{ "resource": "" }
q18561
VRF.save
train
def save(self): """ Save changes made to object to NIPAP. If the object represents a new VRF unknown to NIPAP (attribute `id` is `None`) this function maps to the function :py:func:`nipap.backend.Nipap.add_vrf` in the backend, used to create a new VRF. Otherwise ...
python
{ "resource": "" }
q18562
VRF.remove
train
def remove(self): """ Remove VRF. Maps to the function :py:func:`nipap.backend.Nipap.remove_vrf` in the backend. Please see the documentation for the backend function for information regarding input arguments and return values. """ xmlrpc = XMLRPCConnection(...
python
{ "resource": "" }
q18563
Pool.save
train
def save(self): """ Save changes made to pool to NIPAP. If the object represents a new pool unknown to NIPAP (attribute `id` is `None`) this function maps to the function :py:func:`nipap.backend.Nipap.add_pool` in the backend, used to create a new pool. Otherwise...
python
{ "resource": "" }
q18564
Pool.get
train
def get(cls, id): """ Get the pool with id 'id'. """ # cached? if CACHE: if id in _cache['Pool']: log.debug('cache hit for pool %d' % id) return _cache['Pool'][id] log.debug('cache miss for pool %d' % id) try: ...
python
{ "resource": "" }
q18565
Pool.search
train
def search(cls, query, search_opts=None): """ Search pools. Maps to the function :py:func:`nipap.backend.Nipap.search_pool` in the backend. Please see the documentation for the backend function for information regarding input arguments and return values. """ ...
python
{ "resource": "" }
q18566
Pool.from_dict
train
def from_dict(cls, parm, pool = None): """ Create new Pool-object from dict. Suitable for creating objects from XML-RPC data. All available keys must exist. """ if pool is None: pool = Pool() pool.id = parm['id'] pool.name = parm['name'] ...
python
{ "resource": "" }
q18567
Pool.list
train
def list(self, spec=None): """ List pools. Maps to the function :py:func:`nipap.backend.Nipap.list_pool` in the backend. Please see the documentation for the backend function for information regarding input arguments and return values. """ if spec is None: ...
python
{ "resource": "" }
q18568
Prefix.get
train
def get(cls, id): """ Get the prefix with id 'id'. """ # cached? if CACHE: if id in _cache['Prefix']: log.debug('cache hit for prefix %d' % id) return _cache['Prefix'][id] log.debug('cache miss for prefix %d' % id) try: ...
python
{ "resource": "" }
q18569
Prefix.find_free
train
def find_free(cls, vrf, args): """ Finds a free prefix. Maps to the function :py:func:`nipap.backend.Nipap.find_free_prefix` in the backend. Please see the documentation for the backend function for information regarding input arguments and return values. ...
python
{ "resource": "" }
q18570
Prefix.search
train
def search(cls, query, search_opts=None): """ Search for prefixes. Maps to the function :py:func:`nipap.backend.Nipap.search_prefix` in the backend. Please see the documentation for the backend function for information regarding input arguments and return values....
python
{ "resource": "" }
q18571
Prefix.smart_search
train
def smart_search(cls, query_string, search_options=None, extra_query = None): """ Perform a smart prefix search. Maps to the function :py:func:`nipap.backend.Nipap.smart_search_prefix` in the backend. Please see the documentation for the backend function for info...
python
{ "resource": "" }
q18572
Prefix.list
train
def list(cls, spec=None): """ List prefixes. Maps to the function :py:func:`nipap.backend.Nipap.list_prefix` in the backend. Please see the documentation for the backend function for information regarding input arguments and return values. """ if spec is Non...
python
{ "resource": "" }
q18573
Prefix.save
train
def save(self, args=None): """ Save prefix to NIPAP. If the object represents a new prefix unknown to NIPAP (attribute `id` is `None`) this function maps to the function :py:func:`nipap.backend.Nipap.add_prefix` in the backend, used to create a new prefix. Otherw...
python
{ "resource": "" }
q18574
Prefix.remove
train
def remove(self, recursive = False): """ Remove the prefix. Maps to the function :py:func:`nipap.backend.Nipap.remove_prefix` in the backend. Please see the documentation for the backend function for information regarding input arguments and return values. ...
python
{ "resource": "" }
q18575
Prefix.from_dict
train
def from_dict(cls, pref, prefix = None): """ Create a Prefix object from a dict. Suitable for creating Prefix objects from XML-RPC input. """ if prefix is None: prefix = Prefix() prefix.id = pref['id'] if pref['vrf_id'] is not None: # VRF is not mandato...
python
{ "resource": "" }
q18576
VrfController.edit
train
def edit(self, id): """ Edit a VRF """ c.action = 'edit' c.edit_vrf = VRF.get(int(id)) # Did we have any action passed to us? if 'action' in request.params: if request.params['action'] == 'edit': if request.params['rt'].strip() == '': ...
python
{ "resource": "" }
q18577
VrfController.remove
train
def remove(self, id): """ Removes a VRF. """ v = VRF.get(int(id)) v.remove() redirect(url(controller='vrf', action='list'))
python
{ "resource": "" }
q18578
setup_app
train
def setup_app(command, conf, vars): """Place any commands to setup nipapwww here""" # Don't reload the app if it was loaded under the testing environment if not pylons.test.pylonsapp: load_environment(conf.global_conf, conf.local_conf)
python
{ "resource": "" }
q18579
PrefixController.edit
train
def edit(self, id): """ Edit a prefix. """ # find prefix c.prefix = Prefix.get(int(id)) # we got a HTTP POST - edit object if request.method == 'POST': c.prefix.prefix = request.params['prefix_prefix'] c.prefix.description = request.params['prefi...
python
{ "resource": "" }
q18580
ConfigExport.get_prefixes
train
def get_prefixes(self, query): """ Get prefix data from NIPAP """ try: res = Prefix.smart_search(query, {}) except socket.error: print >> sys.stderr, "Connection refused, please check hostname & port" sys.exit(1) except xmlrpclib.ProtocolError:...
python
{ "resource": "" }
q18581
ConfigExport.write_conf
train
def write_conf(self): """ Write the config to file """ f = open(self.output_filename, 'w') print(self.t.render(prefixes=self.prefixes), file=f) f.close()
python
{ "resource": "" }
q18582
_mangle_prefix
train
def _mangle_prefix(res): """ Mangle prefix result """ # fugly cast from large numbers to string to deal with XML-RPC res['total_addresses'] = unicode(res['total_addresses']) res['used_addresses'] = unicode(res['used_addresses']) res['free_addresses'] = unicode(res['free_addresses']) # postg...
python
{ "resource": "" }
q18583
requires_auth
train
def requires_auth(f): """ Class decorator for XML-RPC functions that requires auth """ @wraps(f) def decorated(self, *args, **kwargs): """ """ # Fetch auth options from args auth_options = {} nipap_args = {} # validate function arguments if len(...
python
{ "resource": "" }
q18584
NipapXMLRPC.echo
train
def echo(self, args): """ An echo function An API test function which simply echoes what is is passed in the 'message' element in the args-dict.. Valid keys in the `args`-struct: * `auth` [struct] Authentication options passed to the :class:`Aut...
python
{ "resource": "" }
q18585
NipapXMLRPC.find_free_prefix
train
def find_free_prefix(self, args): """ Find a free prefix. Valid keys in the `args`-struct: * `auth` [struct] Authentication options passed to the :class:`AuthFactory`. * `args` [struct] Arguments for the find_free_prefix-function such as what...
python
{ "resource": "" }
q18586
NewsFile._readfile
train
def _readfile(self, filename): """ Read content of specified NEWS file """ f = open(filename) self.content = f.readlines() f.close()
python
{ "resource": "" }
q18587
DchFile._parse
train
def _parse(self): """ Parse content of DCH file """ cur_ver = None cur_line = None for line in self.content: m = re.match('[^ ]+ \(([0-9]+\.[0-9]+\.[0-9]+)-[0-9]+\) [^ ]+; urgency=[^ ]+', line) if m: cur_ver = m.group(1) sel...
python
{ "resource": "" }
q18588
JsonFormatter.format
train
def format(self, record: logging.LogRecord) -> str: """ Formats a record and serializes it as a JSON str. If record message isnt already a dict, initializes a new dict and uses `default_msg_fieldname` as a key as the record msg as the value. """ msg: Union[str, dict] = re...
python
{ "resource": "" }
q18589
BaseAsyncRotatingFileHandler.rotation_filename
train
def rotation_filename(self, default_name: str) -> str: """ Modify the filename of a log file when rotating. This is provided so that a custom filename can be provided. :param default_name: The default name for the log file. """ if self.namer is None: return ...
python
{ "resource": "" }
q18590
BaseAsyncRotatingFileHandler.rotate
train
async def rotate(self, source: str, dest: str): """ When rotating, rotate the current log. The default implementation calls the 'rotator' attribute of the handler, if it's callable, passing the source and dest arguments to it. If the attribute isn't callable (the default is None...
python
{ "resource": "" }
q18591
AsyncTimedRotatingFileHandler.compute_rollover
train
def compute_rollover(self, current_time: int) -> int: """ Work out the rollover time based on the specified time. If we are rolling over at midnight or weekly, then the interval is already known. need to figure out is WHEN the next interval is. In other words, if you are rolling...
python
{ "resource": "" }
q18592
AsyncTimedRotatingFileHandler.get_files_to_delete
train
async def get_files_to_delete(self) -> List[str]: """ Determine the files to delete when rolling over. """ dir_name, base_name = os.path.split(self.absolute_file_path) file_names = await self.loop.run_in_executor( None, lambda: os.listdir(dir_name) ) r...
python
{ "resource": "" }
q18593
AsyncStreamHandler.handle
train
async def handle(self, record: LogRecord) -> bool: # type: ignore """ Conditionally emit the specified logging record. Emission depends on filters which may have been added to the handler. """ rv = self.filter(record) if rv: await self.emit(record) re...
python
{ "resource": "" }
q18594
AsyncStreamHandler.emit
train
async def emit(self, record: LogRecord): # type: ignore """ Actually log the specified logging record to the stream. """ if self.writer is None: self.writer = await self._init_writer() try: msg = self.format(record) + self.terminator self.wr...
python
{ "resource": "" }
q18595
Logger.callHandlers
train
async def callHandlers(self, record): """ Pass a record to all relevant handlers. Loop through all handlers for this logger and its parents in the logger hierarchy. If no handler was found, raises an error. Stop searching up the hierarchy whenever a logger with the "propagate" ...
python
{ "resource": "" }
q18596
Logger.handle
train
async def handle(self, record): """ Call the handlers for the specified record. This method is used for unpickled records received from a socket, as well as those created locally. Logger-level filtering is applied. """ if (not self.disabled) and self.filter(record): ...
python
{ "resource": "" }
q18597
Logger._make_log_task
train
def _make_log_task(self, level, msg, *args, **kwargs) -> Task: """ Creates an asyncio.Task for a msg if logging is enabled for level. Returns a dummy task otherwise. """ if not self.isEnabledFor(level): if self._dummy_task is None: self._dummy_task = s...
python
{ "resource": "" }
q18598
Logger.debug
train
def debug(self, msg, *args, **kwargs) -> Task: # type: ignore """ Log msg with severity 'DEBUG'. To pass exception information, use the keyword argument exc_info with a true value, e.g. await logger.debug("Houston, we have a %s", "thorny problem", exc_info=1) """ ...
python
{ "resource": "" }
q18599
Logger.info
train
def info(self, msg, *args, **kwargs) -> Task: # type: ignore """ Log msg with severity 'INFO'. To pass exception information, use the keyword argument exc_info with a true value, e.g. await logger.info("Houston, we have an interesting problem", exc_info=1) """ ...
python
{ "resource": "" }