repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
cackharot/suds-py3 | suds/client.py | SimClient.__reply | def __reply(self, reply, args, kwargs):
""" simulate the reply """
binding = self.method.binding.input
msg = binding.get_message(self.method, args, kwargs)
log.debug('inject (simulated) send message:\n%s', msg)
binding = self.method.binding.output
return self.succeeded(binding, reply) | python | def __reply(self, reply, args, kwargs):
""" simulate the reply """
binding = self.method.binding.input
msg = binding.get_message(self.method, args, kwargs)
log.debug('inject (simulated) send message:\n%s', msg)
binding = self.method.binding.output
return self.succeeded(binding, reply) | [
"def",
"__reply",
"(",
"self",
",",
"reply",
",",
"args",
",",
"kwargs",
")",
":",
"binding",
"=",
"self",
".",
"method",
".",
"binding",
".",
"input",
"msg",
"=",
"binding",
".",
"get_message",
"(",
"self",
".",
"method",
",",
"args",
",",
"kwargs",... | simulate the reply | [
"simulate",
"the",
"reply"
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/client.py#L787-L793 | train | 202,200 |
cackharot/suds-py3 | suds/__init__.py | tostr | def tostr(object, encoding=None):
""" get a unicode safe string representation of an object """
if isinstance(object, basestring):
if encoding is None:
return object
else:
return object.encode(encoding)
if isinstance(object, tuple):
s = ['(']
for item in object:
if isinstance(item, basestring):
s.append(item)
else:
s.append(tostr(item))
s.append(', ')
s.append(')')
return ''.join(s)
if isinstance(object, list):
s = ['[']
for item in object:
if isinstance(item, basestring):
s.append(item)
else:
s.append(tostr(item))
s.append(', ')
s.append(']')
return ''.join(s)
if isinstance(object, dict):
s = ['{']
for item in object.items():
if isinstance(item[0], basestring):
s.append(item[0])
else:
s.append(tostr(item[0]))
s.append(' = ')
if isinstance(item[1], basestring):
s.append(item[1])
else:
s.append(tostr(item[1]))
s.append(', ')
s.append('}')
return ''.join(s)
try:
return unicode(object)
except:
return str(object) | python | def tostr(object, encoding=None):
""" get a unicode safe string representation of an object """
if isinstance(object, basestring):
if encoding is None:
return object
else:
return object.encode(encoding)
if isinstance(object, tuple):
s = ['(']
for item in object:
if isinstance(item, basestring):
s.append(item)
else:
s.append(tostr(item))
s.append(', ')
s.append(')')
return ''.join(s)
if isinstance(object, list):
s = ['[']
for item in object:
if isinstance(item, basestring):
s.append(item)
else:
s.append(tostr(item))
s.append(', ')
s.append(']')
return ''.join(s)
if isinstance(object, dict):
s = ['{']
for item in object.items():
if isinstance(item[0], basestring):
s.append(item[0])
else:
s.append(tostr(item[0]))
s.append(' = ')
if isinstance(item[1], basestring):
s.append(item[1])
else:
s.append(tostr(item[1]))
s.append(', ')
s.append('}')
return ''.join(s)
try:
return unicode(object)
except:
return str(object) | [
"def",
"tostr",
"(",
"object",
",",
"encoding",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"object",
",",
"basestring",
")",
":",
"if",
"encoding",
"is",
"None",
":",
"return",
"object",
"else",
":",
"return",
"object",
".",
"encode",
"(",
"encodi... | get a unicode safe string representation of an object | [
"get",
"a",
"unicode",
"safe",
"string",
"representation",
"of",
"an",
"object"
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/__init__.py#L132-L177 | train | 202,201 |
cackharot/suds-py3 | suds/xsd/schema.py | SchemaCollection.load | def load(self, options):
"""
Load the schema objects for the root nodes.
- de-references schemas
- merge schemas
@param options: An options dictionary.
@type options: L{options.Options}
@return: The merged schema.
@rtype: L{Schema}
"""
if options.autoblend:
self.autoblend()
for child in self.children:
child.build()
for child in self.children:
child.open_imports(options)
for child in self.children:
child.dereference()
log.debug('loaded:\n%s', self)
merged = self.merge()
log.debug('MERGED:\n%s', merged)
return merged | python | def load(self, options):
"""
Load the schema objects for the root nodes.
- de-references schemas
- merge schemas
@param options: An options dictionary.
@type options: L{options.Options}
@return: The merged schema.
@rtype: L{Schema}
"""
if options.autoblend:
self.autoblend()
for child in self.children:
child.build()
for child in self.children:
child.open_imports(options)
for child in self.children:
child.dereference()
log.debug('loaded:\n%s', self)
merged = self.merge()
log.debug('MERGED:\n%s', merged)
return merged | [
"def",
"load",
"(",
"self",
",",
"options",
")",
":",
"if",
"options",
".",
"autoblend",
":",
"self",
".",
"autoblend",
"(",
")",
"for",
"child",
"in",
"self",
".",
"children",
":",
"child",
".",
"build",
"(",
")",
"for",
"child",
"in",
"self",
"."... | Load the schema objects for the root nodes.
- de-references schemas
- merge schemas
@param options: An options dictionary.
@type options: L{options.Options}
@return: The merged schema.
@rtype: L{Schema} | [
"Load",
"the",
"schema",
"objects",
"for",
"the",
"root",
"nodes",
".",
"-",
"de",
"-",
"references",
"schemas",
"-",
"merge",
"schemas"
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/xsd/schema.py#L76-L97 | train | 202,202 |
cackharot/suds-py3 | suds/xsd/schema.py | SchemaCollection.autoblend | def autoblend(self):
"""
Ensure that all schemas within the collection
import each other which has a blending effect.
@return: self
@rtype: L{SchemaCollection}
"""
namespaces = self.namespaces.keys()
for s in self.children:
for ns in namespaces:
tns = s.root.get('targetNamespace')
if tns == ns:
continue
for imp in s.root.getChildren('import'):
if imp.get('namespace') == ns:
continue
imp = Element('import', ns=Namespace.xsdns)
imp.set('namespace', ns)
s.root.append(imp)
return self | python | def autoblend(self):
"""
Ensure that all schemas within the collection
import each other which has a blending effect.
@return: self
@rtype: L{SchemaCollection}
"""
namespaces = self.namespaces.keys()
for s in self.children:
for ns in namespaces:
tns = s.root.get('targetNamespace')
if tns == ns:
continue
for imp in s.root.getChildren('import'):
if imp.get('namespace') == ns:
continue
imp = Element('import', ns=Namespace.xsdns)
imp.set('namespace', ns)
s.root.append(imp)
return self | [
"def",
"autoblend",
"(",
"self",
")",
":",
"namespaces",
"=",
"self",
".",
"namespaces",
".",
"keys",
"(",
")",
"for",
"s",
"in",
"self",
".",
"children",
":",
"for",
"ns",
"in",
"namespaces",
":",
"tns",
"=",
"s",
".",
"root",
".",
"get",
"(",
"... | Ensure that all schemas within the collection
import each other which has a blending effect.
@return: self
@rtype: L{SchemaCollection} | [
"Ensure",
"that",
"all",
"schemas",
"within",
"the",
"collection",
"import",
"each",
"other",
"which",
"has",
"a",
"blending",
"effect",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/xsd/schema.py#L99-L118 | train | 202,203 |
cackharot/suds-py3 | suds/xsd/schema.py | Schema.merge | def merge(self, schema):
"""
Merge the contents from the schema. Only objects not already contained
in this schema's collections are merged. This is to provide for
bidirectional import which produce cyclic includes.
@returns: self
@rtype: L{Schema}
"""
for item in schema.attributes.items():
if item[0] in self.attributes:
continue
self.all.append(item[1])
self.attributes[item[0]] = item[1]
for item in schema.elements.items():
if item[0] in self.elements:
continue
self.all.append(item[1])
self.elements[item[0]] = item[1]
for item in schema.types.items():
if item[0] in self.types:
continue
self.all.append(item[1])
self.types[item[0]] = item[1]
for item in schema.groups.items():
if item[0] in self.groups:
continue
self.all.append(item[1])
self.groups[item[0]] = item[1]
for item in schema.agrps.items():
if item[0] in self.agrps:
continue
self.all.append(item[1])
self.agrps[item[0]] = item[1]
schema.merged = True
return self | python | def merge(self, schema):
"""
Merge the contents from the schema. Only objects not already contained
in this schema's collections are merged. This is to provide for
bidirectional import which produce cyclic includes.
@returns: self
@rtype: L{Schema}
"""
for item in schema.attributes.items():
if item[0] in self.attributes:
continue
self.all.append(item[1])
self.attributes[item[0]] = item[1]
for item in schema.elements.items():
if item[0] in self.elements:
continue
self.all.append(item[1])
self.elements[item[0]] = item[1]
for item in schema.types.items():
if item[0] in self.types:
continue
self.all.append(item[1])
self.types[item[0]] = item[1]
for item in schema.groups.items():
if item[0] in self.groups:
continue
self.all.append(item[1])
self.groups[item[0]] = item[1]
for item in schema.agrps.items():
if item[0] in self.agrps:
continue
self.all.append(item[1])
self.agrps[item[0]] = item[1]
schema.merged = True
return self | [
"def",
"merge",
"(",
"self",
",",
"schema",
")",
":",
"for",
"item",
"in",
"schema",
".",
"attributes",
".",
"items",
"(",
")",
":",
"if",
"item",
"[",
"0",
"]",
"in",
"self",
".",
"attributes",
":",
"continue",
"self",
".",
"all",
".",
"append",
... | Merge the contents from the schema. Only objects not already contained
in this schema's collections are merged. This is to provide for
bidirectional import which produce cyclic includes.
@returns: self
@rtype: L{Schema} | [
"Merge",
"the",
"contents",
"from",
"the",
"schema",
".",
"Only",
"objects",
"not",
"already",
"contained",
"in",
"this",
"schema",
"s",
"collections",
"are",
"merged",
".",
"This",
"is",
"to",
"provide",
"for",
"bidirectional",
"import",
"which",
"produce",
... | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/xsd/schema.py#L261-L295 | train | 202,204 |
cackharot/suds-py3 | suds/resolver.py | PathResolver.leaf | def leaf(self, parent, parts):
"""
Find the leaf.
@param parts: A list of path parts.
@type parts: [str,..]
@param parent: The leaf's parent.
@type parent: L{xsd.sxbase.SchemaObject}
@return: The leaf.
@rtype: L{xsd.sxbase.SchemaObject}
"""
name = splitPrefix(parts[-1])[1]
if name.startswith('@'):
result, path = parent.get_attribute(name[1:])
else:
result, ancestry = parent.get_child(name)
if result is None:
raise PathResolver.BadPath(name)
return result | python | def leaf(self, parent, parts):
"""
Find the leaf.
@param parts: A list of path parts.
@type parts: [str,..]
@param parent: The leaf's parent.
@type parent: L{xsd.sxbase.SchemaObject}
@return: The leaf.
@rtype: L{xsd.sxbase.SchemaObject}
"""
name = splitPrefix(parts[-1])[1]
if name.startswith('@'):
result, path = parent.get_attribute(name[1:])
else:
result, ancestry = parent.get_child(name)
if result is None:
raise PathResolver.BadPath(name)
return result | [
"def",
"leaf",
"(",
"self",
",",
"parent",
",",
"parts",
")",
":",
"name",
"=",
"splitPrefix",
"(",
"parts",
"[",
"-",
"1",
"]",
")",
"[",
"1",
"]",
"if",
"name",
".",
"startswith",
"(",
"'@'",
")",
":",
"result",
",",
"path",
"=",
"parent",
".... | Find the leaf.
@param parts: A list of path parts.
@type parts: [str,..]
@param parent: The leaf's parent.
@type parent: L{xsd.sxbase.SchemaObject}
@return: The leaf.
@rtype: L{xsd.sxbase.SchemaObject} | [
"Find",
"the",
"leaf",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/resolver.py#L164-L181 | train | 202,205 |
cackharot/suds-py3 | suds/resolver.py | NodeResolver.findattr | def findattr(self, name, resolved=True):
"""
Find an attribute type definition.
@param name: An attribute name.
@type name: basestring
@param resolved: A flag indicating that the fully resolved type should
be returned.
@type resolved: boolean
@return: The found schema I{type}
@rtype: L{xsd.sxbase.SchemaObject}
"""
name = '@%s' % name
parent = self.top().resolved
if parent is None:
result, ancestry = self.query(name, node)
else:
result, ancestry = self.getchild(name, parent)
if result is None:
return result
if resolved:
result = result.resolve()
return result | python | def findattr(self, name, resolved=True):
"""
Find an attribute type definition.
@param name: An attribute name.
@type name: basestring
@param resolved: A flag indicating that the fully resolved type should
be returned.
@type resolved: boolean
@return: The found schema I{type}
@rtype: L{xsd.sxbase.SchemaObject}
"""
name = '@%s' % name
parent = self.top().resolved
if parent is None:
result, ancestry = self.query(name, node)
else:
result, ancestry = self.getchild(name, parent)
if result is None:
return result
if resolved:
result = result.resolve()
return result | [
"def",
"findattr",
"(",
"self",
",",
"name",
",",
"resolved",
"=",
"True",
")",
":",
"name",
"=",
"'@%s'",
"%",
"name",
"parent",
"=",
"self",
".",
"top",
"(",
")",
".",
"resolved",
"if",
"parent",
"is",
"None",
":",
"result",
",",
"ancestry",
"=",... | Find an attribute type definition.
@param name: An attribute name.
@type name: basestring
@param resolved: A flag indicating that the fully resolved type should
be returned.
@type resolved: boolean
@return: The found schema I{type}
@rtype: L{xsd.sxbase.SchemaObject} | [
"Find",
"an",
"attribute",
"type",
"definition",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/resolver.py#L350-L371 | train | 202,206 |
cackharot/suds-py3 | suds/resolver.py | NodeResolver.known | def known(self, node):
""" resolve type referenced by @xsi:type """
ref = node.get('type', Namespace.xsins)
if ref is None:
return None
qref = qualify(ref, node, node.namespace())
query = BlindQuery(qref)
return query.execute(self.schema) | python | def known(self, node):
""" resolve type referenced by @xsi:type """
ref = node.get('type', Namespace.xsins)
if ref is None:
return None
qref = qualify(ref, node, node.namespace())
query = BlindQuery(qref)
return query.execute(self.schema) | [
"def",
"known",
"(",
"self",
",",
"node",
")",
":",
"ref",
"=",
"node",
".",
"get",
"(",
"'type'",
",",
"Namespace",
".",
"xsins",
")",
"if",
"ref",
"is",
"None",
":",
"return",
"None",
"qref",
"=",
"qualify",
"(",
"ref",
",",
"node",
",",
"node"... | resolve type referenced by @xsi:type | [
"resolve",
"type",
"referenced",
"by"
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/resolver.py#L381-L388 | train | 202,207 |
cackharot/suds-py3 | suds/resolver.py | GraphResolver.known | def known(self, object):
""" get the type specified in the object's metadata """
try:
md = object.__metadata__
known = md.sxtype
return known
except:
pass | python | def known(self, object):
""" get the type specified in the object's metadata """
try:
md = object.__metadata__
known = md.sxtype
return known
except:
pass | [
"def",
"known",
"(",
"self",
",",
"object",
")",
":",
"try",
":",
"md",
"=",
"object",
".",
"__metadata__",
"known",
"=",
"md",
".",
"sxtype",
"return",
"known",
"except",
":",
"pass"
] | get the type specified in the object's metadata | [
"get",
"the",
"type",
"specified",
"in",
"the",
"object",
"s",
"metadata"
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/resolver.py#L462-L469 | train | 202,208 |
cackharot/suds-py3 | suds/servicedefinition.py | ServiceDefinition.pushprefixes | def pushprefixes(self):
"""
Add our prefixes to the wsdl so that when users invoke methods
and reference the prefixes, the will resolve properly.
"""
for ns in self.prefixes:
self.wsdl.root.addPrefix(ns[0], ns[1]) | python | def pushprefixes(self):
"""
Add our prefixes to the wsdl so that when users invoke methods
and reference the prefixes, the will resolve properly.
"""
for ns in self.prefixes:
self.wsdl.root.addPrefix(ns[0], ns[1]) | [
"def",
"pushprefixes",
"(",
"self",
")",
":",
"for",
"ns",
"in",
"self",
".",
"prefixes",
":",
"self",
".",
"wsdl",
".",
"root",
".",
"addPrefix",
"(",
"ns",
"[",
"0",
"]",
",",
"ns",
"[",
"1",
"]",
")"
] | Add our prefixes to the wsdl so that when users invoke methods
and reference the prefixes, the will resolve properly. | [
"Add",
"our",
"prefixes",
"to",
"the",
"wsdl",
"so",
"that",
"when",
"users",
"invoke",
"methods",
"and",
"reference",
"the",
"prefixes",
"the",
"will",
"resolve",
"properly",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/servicedefinition.py#L64-L70 | train | 202,209 |
cackharot/suds-py3 | suds/servicedefinition.py | ServiceDefinition.findport | def findport(self, port):
"""
Find and return a port tuple for the specified port.
Created and added when not found.
@param port: A port.
@type port: I{service.Port}
@return: A port tuple.
@rtype: (port, [method])
"""
for p in self.ports:
if p[0] == p:
return p
p = (port, [])
self.ports.append(p)
return p | python | def findport(self, port):
"""
Find and return a port tuple for the specified port.
Created and added when not found.
@param port: A port.
@type port: I{service.Port}
@return: A port tuple.
@rtype: (port, [method])
"""
for p in self.ports:
if p[0] == p:
return p
p = (port, [])
self.ports.append(p)
return p | [
"def",
"findport",
"(",
"self",
",",
"port",
")",
":",
"for",
"p",
"in",
"self",
".",
"ports",
":",
"if",
"p",
"[",
"0",
"]",
"==",
"p",
":",
"return",
"p",
"p",
"=",
"(",
"port",
",",
"[",
"]",
")",
"self",
".",
"ports",
".",
"append",
"("... | Find and return a port tuple for the specified port.
Created and added when not found.
@param port: A port.
@type port: I{service.Port}
@return: A port tuple.
@rtype: (port, [method]) | [
"Find",
"and",
"return",
"a",
"port",
"tuple",
"for",
"the",
"specified",
"port",
".",
"Created",
"and",
"added",
"when",
"not",
"found",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/servicedefinition.py#L92-L106 | train | 202,210 |
cackharot/suds-py3 | suds/servicedefinition.py | ServiceDefinition.paramtypes | def paramtypes(self):
""" get all parameter types """
for m in [p[1] for p in self.ports]:
for p in [p[1] for p in m]:
for pd in p:
if pd[1] in self.params:
continue
item = (pd[1], pd[1].resolve())
self.params.append(item) | python | def paramtypes(self):
""" get all parameter types """
for m in [p[1] for p in self.ports]:
for p in [p[1] for p in m]:
for pd in p:
if pd[1] in self.params:
continue
item = (pd[1], pd[1].resolve())
self.params.append(item) | [
"def",
"paramtypes",
"(",
"self",
")",
":",
"for",
"m",
"in",
"[",
"p",
"[",
"1",
"]",
"for",
"p",
"in",
"self",
".",
"ports",
"]",
":",
"for",
"p",
"in",
"[",
"p",
"[",
"1",
"]",
"for",
"p",
"in",
"m",
"]",
":",
"for",
"pd",
"in",
"p",
... | get all parameter types | [
"get",
"all",
"parameter",
"types"
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/servicedefinition.py#L137-L145 | train | 202,211 |
cackharot/suds-py3 | suds/transport/http.py | HttpTransport.u2handlers | def u2handlers(self):
"""
Get a collection of urllib handlers.
@return: A list of handlers to be installed in the opener.
@rtype: [Handler,...]
"""
handlers = []
handlers.append(u2.ProxyHandler(self.proxy))
return handlers | python | def u2handlers(self):
"""
Get a collection of urllib handlers.
@return: A list of handlers to be installed in the opener.
@rtype: [Handler,...]
"""
handlers = []
handlers.append(u2.ProxyHandler(self.proxy))
return handlers | [
"def",
"u2handlers",
"(",
"self",
")",
":",
"handlers",
"=",
"[",
"]",
"handlers",
".",
"append",
"(",
"u2",
".",
"ProxyHandler",
"(",
"self",
".",
"proxy",
")",
")",
"return",
"handlers"
] | Get a collection of urllib handlers.
@return: A list of handlers to be installed in the opener.
@rtype: [Handler,...] | [
"Get",
"a",
"collection",
"of",
"urllib",
"handlers",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/transport/http.py#L132-L140 | train | 202,212 |
cackharot/suds-py3 | suds/sax/element.py | Element.setPrefix | def setPrefix(self, p, u=None):
"""
Set the element namespace prefix.
@param p: A new prefix for the element.
@type p: basestring
@param u: A namespace URI to be mapped to the prefix.
@type u: basestring
@return: self
@rtype: L{Element}
"""
self.prefix = p
if p is not None and u is not None:
self.addPrefix(p, u)
return self | python | def setPrefix(self, p, u=None):
"""
Set the element namespace prefix.
@param p: A new prefix for the element.
@type p: basestring
@param u: A namespace URI to be mapped to the prefix.
@type u: basestring
@return: self
@rtype: L{Element}
"""
self.prefix = p
if p is not None and u is not None:
self.addPrefix(p, u)
return self | [
"def",
"setPrefix",
"(",
"self",
",",
"p",
",",
"u",
"=",
"None",
")",
":",
"self",
".",
"prefix",
"=",
"p",
"if",
"p",
"is",
"not",
"None",
"and",
"u",
"is",
"not",
"None",
":",
"self",
".",
"addPrefix",
"(",
"p",
",",
"u",
")",
"return",
"s... | Set the element namespace prefix.
@param p: A new prefix for the element.
@type p: basestring
@param u: A namespace URI to be mapped to the prefix.
@type u: basestring
@return: self
@rtype: L{Element} | [
"Set",
"the",
"element",
"namespace",
"prefix",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L119-L132 | train | 202,213 |
cackharot/suds-py3 | suds/sax/element.py | Element.detach | def detach(self):
"""
Detach from parent.
@return: This element removed from its parent's
child list and I{parent}=I{None}
@rtype: L{Element}
"""
if self.parent is not None:
if self in self.parent.children:
self.parent.children.remove(self)
self.parent = None
return self | python | def detach(self):
"""
Detach from parent.
@return: This element removed from its parent's
child list and I{parent}=I{None}
@rtype: L{Element}
"""
if self.parent is not None:
if self in self.parent.children:
self.parent.children.remove(self)
self.parent = None
return self | [
"def",
"detach",
"(",
"self",
")",
":",
"if",
"self",
".",
"parent",
"is",
"not",
"None",
":",
"if",
"self",
"in",
"self",
".",
"parent",
".",
"children",
":",
"self",
".",
"parent",
".",
"children",
".",
"remove",
"(",
"self",
")",
"self",
".",
... | Detach from parent.
@return: This element removed from its parent's
child list and I{parent}=I{None}
@rtype: L{Element} | [
"Detach",
"from",
"parent",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L173-L184 | train | 202,214 |
cackharot/suds-py3 | suds/sax/element.py | Element.set | def set(self, name, value):
"""
Set an attribute's value.
@param name: The name of the attribute.
@type name: basestring
@param value: The attribute value.
@type value: basestring
@see: __setitem__()
"""
attr = self.getAttribute(name)
if attr is None:
attr = Attribute(name, value)
self.append(attr)
else:
attr.setValue(value) | python | def set(self, name, value):
"""
Set an attribute's value.
@param name: The name of the attribute.
@type name: basestring
@param value: The attribute value.
@type value: basestring
@see: __setitem__()
"""
attr = self.getAttribute(name)
if attr is None:
attr = Attribute(name, value)
self.append(attr)
else:
attr.setValue(value) | [
"def",
"set",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"attr",
"=",
"self",
".",
"getAttribute",
"(",
"name",
")",
"if",
"attr",
"is",
"None",
":",
"attr",
"=",
"Attribute",
"(",
"name",
",",
"value",
")",
"self",
".",
"append",
"(",
"at... | Set an attribute's value.
@param name: The name of the attribute.
@type name: basestring
@param value: The attribute value.
@type value: basestring
@see: __setitem__() | [
"Set",
"an",
"attribute",
"s",
"value",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L186-L200 | train | 202,215 |
cackharot/suds-py3 | suds/sax/element.py | Element.trim | def trim(self):
"""
Trim leading and trailing whitespace.
@return: self
@rtype: L{Element}
"""
if self.hasText():
self.text = self.text.trim()
return self | python | def trim(self):
"""
Trim leading and trailing whitespace.
@return: self
@rtype: L{Element}
"""
if self.hasText():
self.text = self.text.trim()
return self | [
"def",
"trim",
"(",
"self",
")",
":",
"if",
"self",
".",
"hasText",
"(",
")",
":",
"self",
".",
"text",
"=",
"self",
".",
"text",
".",
"trim",
"(",
")",
"return",
"self"
] | Trim leading and trailing whitespace.
@return: self
@rtype: L{Element} | [
"Trim",
"leading",
"and",
"trailing",
"whitespace",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L264-L272 | train | 202,216 |
cackharot/suds-py3 | suds/sax/element.py | Element.remove | def remove(self, child):
"""
Remove the specified child element or attribute.
@param child: A child to remove.
@type child: L{Element}|L{Attribute}
@return: The detached I{child} when I{child} is an element, else None.
@rtype: L{Element}|None
"""
if isinstance(child, Element):
return child.detach()
if isinstance(child, Attribute):
self.attributes.remove(child)
return None | python | def remove(self, child):
"""
Remove the specified child element or attribute.
@param child: A child to remove.
@type child: L{Element}|L{Attribute}
@return: The detached I{child} when I{child} is an element, else None.
@rtype: L{Element}|None
"""
if isinstance(child, Element):
return child.detach()
if isinstance(child, Attribute):
self.attributes.remove(child)
return None | [
"def",
"remove",
"(",
"self",
",",
"child",
")",
":",
"if",
"isinstance",
"(",
"child",
",",
"Element",
")",
":",
"return",
"child",
".",
"detach",
"(",
")",
"if",
"isinstance",
"(",
"child",
",",
"Attribute",
")",
":",
"self",
".",
"attributes",
"."... | Remove the specified child element or attribute.
@param child: A child to remove.
@type child: L{Element}|L{Attribute}
@return: The detached I{child} when I{child} is an element, else None.
@rtype: L{Element}|None | [
"Remove",
"the",
"specified",
"child",
"element",
"or",
"attribute",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L355-L367 | train | 202,217 |
cackharot/suds-py3 | suds/sax/element.py | Element.detachChildren | def detachChildren(self):
"""
Detach and return this element's children.
@return: The element's children (detached).
@rtype: [L{Element},...]
"""
detached = self.children
self.children = []
for child in detached:
child.parent = None
return detached | python | def detachChildren(self):
"""
Detach and return this element's children.
@return: The element's children (detached).
@rtype: [L{Element},...]
"""
detached = self.children
self.children = []
for child in detached:
child.parent = None
return detached | [
"def",
"detachChildren",
"(",
"self",
")",
":",
"detached",
"=",
"self",
".",
"children",
"self",
".",
"children",
"=",
"[",
"]",
"for",
"child",
"in",
"detached",
":",
"child",
".",
"parent",
"=",
"None",
"return",
"detached"
] | Detach and return this element's children.
@return: The element's children (detached).
@rtype: [L{Element},...] | [
"Detach",
"and",
"return",
"this",
"element",
"s",
"children",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L493-L503 | train | 202,218 |
cackharot/suds-py3 | suds/sax/element.py | Element.clearPrefix | def clearPrefix(self, prefix):
"""
Clear the specified prefix from the prefix mappings.
@param prefix: A prefix to clear.
@type prefix: basestring
@return: self
@rtype: L{Element}
"""
if prefix in self.nsprefixes:
del self.nsprefixes[prefix]
return self | python | def clearPrefix(self, prefix):
"""
Clear the specified prefix from the prefix mappings.
@param prefix: A prefix to clear.
@type prefix: basestring
@return: self
@rtype: L{Element}
"""
if prefix in self.nsprefixes:
del self.nsprefixes[prefix]
return self | [
"def",
"clearPrefix",
"(",
"self",
",",
"prefix",
")",
":",
"if",
"prefix",
"in",
"self",
".",
"nsprefixes",
":",
"del",
"self",
".",
"nsprefixes",
"[",
"prefix",
"]",
"return",
"self"
] | Clear the specified prefix from the prefix mappings.
@param prefix: A prefix to clear.
@type prefix: basestring
@return: self
@rtype: L{Element} | [
"Clear",
"the",
"specified",
"prefix",
"from",
"the",
"prefix",
"mappings",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L558-L568 | train | 202,219 |
cackharot/suds-py3 | suds/sax/element.py | Element.findPrefix | def findPrefix(self, uri, default=None):
"""
Find the first prefix that has been mapped to a namespace URI.
The local mapping is searched, then it walks up the tree until
it reaches the top or finds a match.
@param uri: A namespace URI.
@type uri: basestring
@param default: A default prefix when not found.
@type default: basestring
@return: A mapped prefix.
@rtype: basestring
"""
for item in self.nsprefixes.items():
if item[1] == uri:
prefix = item[0]
return prefix
for item in self.specialprefixes.items():
if item[1] == uri:
prefix = item[0]
return prefix
if self.parent is not None:
return self.parent.findPrefix(uri, default)
else:
return default | python | def findPrefix(self, uri, default=None):
"""
Find the first prefix that has been mapped to a namespace URI.
The local mapping is searched, then it walks up the tree until
it reaches the top or finds a match.
@param uri: A namespace URI.
@type uri: basestring
@param default: A default prefix when not found.
@type default: basestring
@return: A mapped prefix.
@rtype: basestring
"""
for item in self.nsprefixes.items():
if item[1] == uri:
prefix = item[0]
return prefix
for item in self.specialprefixes.items():
if item[1] == uri:
prefix = item[0]
return prefix
if self.parent is not None:
return self.parent.findPrefix(uri, default)
else:
return default | [
"def",
"findPrefix",
"(",
"self",
",",
"uri",
",",
"default",
"=",
"None",
")",
":",
"for",
"item",
"in",
"self",
".",
"nsprefixes",
".",
"items",
"(",
")",
":",
"if",
"item",
"[",
"1",
"]",
"==",
"uri",
":",
"prefix",
"=",
"item",
"[",
"0",
"]... | Find the first prefix that has been mapped to a namespace URI.
The local mapping is searched, then it walks up the tree until
it reaches the top or finds a match.
@param uri: A namespace URI.
@type uri: basestring
@param default: A default prefix when not found.
@type default: basestring
@return: A mapped prefix.
@rtype: basestring | [
"Find",
"the",
"first",
"prefix",
"that",
"has",
"been",
"mapped",
"to",
"a",
"namespace",
"URI",
".",
"The",
"local",
"mapping",
"is",
"searched",
"then",
"it",
"walks",
"up",
"the",
"tree",
"until",
"it",
"reaches",
"the",
"top",
"or",
"finds",
"a",
... | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L570-L593 | train | 202,220 |
cackharot/suds-py3 | suds/sax/element.py | Element.findPrefixes | def findPrefixes(self, uri, match='eq'):
"""
Find all prefixes that has been mapped to a namespace URI.
The local mapping is searched, then it walks up the tree until
it reaches the top collecting all matches.
@param uri: A namespace URI.
@type uri: basestring
@param match: A matching function L{Element.matcher}.
@type match: basestring
@return: A list of mapped prefixes.
@rtype: [basestring,...]
"""
result = []
for item in self.nsprefixes.items():
if self.matcher[match](item[1], uri):
prefix = item[0]
result.append(prefix)
for item in self.specialprefixes.items():
if self.matcher[match](item[1], uri):
prefix = item[0]
result.append(prefix)
if self.parent is not None:
result += self.parent.findPrefixes(uri, match)
return result | python | def findPrefixes(self, uri, match='eq'):
"""
Find all prefixes that has been mapped to a namespace URI.
The local mapping is searched, then it walks up the tree until
it reaches the top collecting all matches.
@param uri: A namespace URI.
@type uri: basestring
@param match: A matching function L{Element.matcher}.
@type match: basestring
@return: A list of mapped prefixes.
@rtype: [basestring,...]
"""
result = []
for item in self.nsprefixes.items():
if self.matcher[match](item[1], uri):
prefix = item[0]
result.append(prefix)
for item in self.specialprefixes.items():
if self.matcher[match](item[1], uri):
prefix = item[0]
result.append(prefix)
if self.parent is not None:
result += self.parent.findPrefixes(uri, match)
return result | [
"def",
"findPrefixes",
"(",
"self",
",",
"uri",
",",
"match",
"=",
"'eq'",
")",
":",
"result",
"=",
"[",
"]",
"for",
"item",
"in",
"self",
".",
"nsprefixes",
".",
"items",
"(",
")",
":",
"if",
"self",
".",
"matcher",
"[",
"match",
"]",
"(",
"item... | Find all prefixes that has been mapped to a namespace URI.
The local mapping is searched, then it walks up the tree until
it reaches the top collecting all matches.
@param uri: A namespace URI.
@type uri: basestring
@param match: A matching function L{Element.matcher}.
@type match: basestring
@return: A list of mapped prefixes.
@rtype: [basestring,...] | [
"Find",
"all",
"prefixes",
"that",
"has",
"been",
"mapped",
"to",
"a",
"namespace",
"URI",
".",
"The",
"local",
"mapping",
"is",
"searched",
"then",
"it",
"walks",
"up",
"the",
"tree",
"until",
"it",
"reaches",
"the",
"top",
"collecting",
"all",
"matches",... | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L595-L618 | train | 202,221 |
cackharot/suds-py3 | suds/sax/element.py | Element.promotePrefixes | def promotePrefixes(self):
"""
Push prefix declarations up the tree as far as possible. Prefix
mapping are pushed to its parent unless the parent has the
prefix mapped to another URI or the parent has the prefix.
This is propagated up the tree until the top is reached.
@return: self
@rtype: L{Element}
"""
for c in self.children:
c.promotePrefixes()
if self.parent is None:
return
_pref = []
for p, u in self.nsprefixes.items():
if p in self.parent.nsprefixes:
pu = self.parent.nsprefixes[p]
if pu == u:
_pref.append(p)
continue
if p != self.parent.prefix:
self.parent.nsprefixes[p] = u
_pref.append(p)
for x in _pref:
del self.nsprefixes[x]
return self | python | def promotePrefixes(self):
"""
Push prefix declarations up the tree as far as possible. Prefix
mapping are pushed to its parent unless the parent has the
prefix mapped to another URI or the parent has the prefix.
This is propagated up the tree until the top is reached.
@return: self
@rtype: L{Element}
"""
for c in self.children:
c.promotePrefixes()
if self.parent is None:
return
_pref = []
for p, u in self.nsprefixes.items():
if p in self.parent.nsprefixes:
pu = self.parent.nsprefixes[p]
if pu == u:
_pref.append(p)
continue
if p != self.parent.prefix:
self.parent.nsprefixes[p] = u
_pref.append(p)
for x in _pref:
del self.nsprefixes[x]
return self | [
"def",
"promotePrefixes",
"(",
"self",
")",
":",
"for",
"c",
"in",
"self",
".",
"children",
":",
"c",
".",
"promotePrefixes",
"(",
")",
"if",
"self",
".",
"parent",
"is",
"None",
":",
"return",
"_pref",
"=",
"[",
"]",
"for",
"p",
",",
"u",
"in",
... | Push prefix declarations up the tree as far as possible. Prefix
mapping are pushed to its parent unless the parent has the
prefix mapped to another URI or the parent has the prefix.
This is propagated up the tree until the top is reached.
@return: self
@rtype: L{Element} | [
"Push",
"prefix",
"declarations",
"up",
"the",
"tree",
"as",
"far",
"as",
"possible",
".",
"Prefix",
"mapping",
"are",
"pushed",
"to",
"its",
"parent",
"unless",
"the",
"parent",
"has",
"the",
"prefix",
"mapped",
"to",
"another",
"URI",
"or",
"the",
"paren... | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L620-L647 | train | 202,222 |
cackharot/suds-py3 | suds/sax/element.py | Element.refitPrefixes | def refitPrefixes(self):
"""
Refit namespace qualification by replacing prefixes
with explicit namespaces. Also purges prefix mapping table.
@return: self
@rtype: L{Element}
"""
for c in self.children:
c.refitPrefixes()
if self.prefix is not None:
ns = self.resolvePrefix(self.prefix)
if ns[1] is not None:
self.expns = ns[1]
self.prefix = None
self.nsprefixes = {}
return self | python | def refitPrefixes(self):
"""
Refit namespace qualification by replacing prefixes
with explicit namespaces. Also purges prefix mapping table.
@return: self
@rtype: L{Element}
"""
for c in self.children:
c.refitPrefixes()
if self.prefix is not None:
ns = self.resolvePrefix(self.prefix)
if ns[1] is not None:
self.expns = ns[1]
self.prefix = None
self.nsprefixes = {}
return self | [
"def",
"refitPrefixes",
"(",
"self",
")",
":",
"for",
"c",
"in",
"self",
".",
"children",
":",
"c",
".",
"refitPrefixes",
"(",
")",
"if",
"self",
".",
"prefix",
"is",
"not",
"None",
":",
"ns",
"=",
"self",
".",
"resolvePrefix",
"(",
"self",
".",
"p... | Refit namespace qualification by replacing prefixes
with explicit namespaces. Also purges prefix mapping table.
@return: self
@rtype: L{Element} | [
"Refit",
"namespace",
"qualification",
"by",
"replacing",
"prefixes",
"with",
"explicit",
"namespaces",
".",
"Also",
"purges",
"prefix",
"mapping",
"table",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L649-L664 | train | 202,223 |
cackharot/suds-py3 | suds/sax/element.py | Element.branch | def branch(self):
"""
Get a flattened representation of the branch.
@return: A flat list of nodes.
@rtype: [L{Element},..]
"""
branch = [self]
for c in self.children:
branch += c.branch()
return branch | python | def branch(self):
"""
Get a flattened representation of the branch.
@return: A flat list of nodes.
@rtype: [L{Element},..]
"""
branch = [self]
for c in self.children:
branch += c.branch()
return branch | [
"def",
"branch",
"(",
"self",
")",
":",
"branch",
"=",
"[",
"self",
"]",
"for",
"c",
"in",
"self",
".",
"children",
":",
"branch",
"+=",
"c",
".",
"branch",
"(",
")",
"return",
"branch"
] | Get a flattened representation of the branch.
@return: A flat list of nodes.
@rtype: [L{Element},..] | [
"Get",
"a",
"flattened",
"representation",
"of",
"the",
"branch",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L841-L850 | train | 202,224 |
cackharot/suds-py3 | suds/sax/element.py | Element.ancestors | def ancestors(self):
"""
Get a list of ancestors.
@return: A list of ancestors.
@rtype: [L{Element},..]
"""
ancestors = []
p = self.parent
while p is not None:
ancestors.append(p)
p = p.parent
return ancestors | python | def ancestors(self):
"""
Get a list of ancestors.
@return: A list of ancestors.
@rtype: [L{Element},..]
"""
ancestors = []
p = self.parent
while p is not None:
ancestors.append(p)
p = p.parent
return ancestors | [
"def",
"ancestors",
"(",
"self",
")",
":",
"ancestors",
"=",
"[",
"]",
"p",
"=",
"self",
".",
"parent",
"while",
"p",
"is",
"not",
"None",
":",
"ancestors",
".",
"append",
"(",
"p",
")",
"p",
"=",
"p",
".",
"parent",
"return",
"ancestors"
] | Get a list of ancestors.
@return: A list of ancestors.
@rtype: [L{Element},..] | [
"Get",
"a",
"list",
"of",
"ancestors",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L852-L863 | train | 202,225 |
cackharot/suds-py3 | suds/sax/element.py | Element.walk | def walk(self, visitor):
"""
Walk the branch and call the visitor function
on each node.
@param visitor: A function.
@return: self
@rtype: L{Element}
"""
visitor(self)
for c in self.children:
c.walk(visitor)
return self | python | def walk(self, visitor):
"""
Walk the branch and call the visitor function
on each node.
@param visitor: A function.
@return: self
@rtype: L{Element}
"""
visitor(self)
for c in self.children:
c.walk(visitor)
return self | [
"def",
"walk",
"(",
"self",
",",
"visitor",
")",
":",
"visitor",
"(",
"self",
")",
"for",
"c",
"in",
"self",
".",
"children",
":",
"c",
".",
"walk",
"(",
"visitor",
")",
"return",
"self"
] | Walk the branch and call the visitor function
on each node.
@param visitor: A function.
@return: self
@rtype: L{Element} | [
"Walk",
"the",
"branch",
"and",
"call",
"the",
"visitor",
"function",
"on",
"each",
"node",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L865-L876 | train | 202,226 |
cackharot/suds-py3 | suds/sax/element.py | Element.prune | def prune(self):
"""
Prune the branch of empty nodes.
"""
pruned = []
for c in self.children:
c.prune()
if c.isempty(False):
pruned.append(c)
for p in pruned:
self.children.remove(p) | python | def prune(self):
"""
Prune the branch of empty nodes.
"""
pruned = []
for c in self.children:
c.prune()
if c.isempty(False):
pruned.append(c)
for p in pruned:
self.children.remove(p) | [
"def",
"prune",
"(",
"self",
")",
":",
"pruned",
"=",
"[",
"]",
"for",
"c",
"in",
"self",
".",
"children",
":",
"c",
".",
"prune",
"(",
")",
"if",
"c",
".",
"isempty",
"(",
"False",
")",
":",
"pruned",
".",
"append",
"(",
"c",
")",
"for",
"p"... | Prune the branch of empty nodes. | [
"Prune",
"the",
"branch",
"of",
"empty",
"nodes",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L878-L888 | train | 202,227 |
cackharot/suds-py3 | suds/sax/element.py | NodeIterator.next | def next(self):
"""
Get the next child.
@return: The next child.
@rtype: L{Element}
@raise StopIterator: At the end.
"""
try:
child = self.children[self.pos]
self.pos += 1
return child
except:
raise StopIteration() | python | def next(self):
"""
Get the next child.
@return: The next child.
@rtype: L{Element}
@raise StopIterator: At the end.
"""
try:
child = self.children[self.pos]
self.pos += 1
return child
except:
raise StopIteration() | [
"def",
"next",
"(",
"self",
")",
":",
"try",
":",
"child",
"=",
"self",
".",
"children",
"[",
"self",
".",
"pos",
"]",
"self",
".",
"pos",
"+=",
"1",
"return",
"child",
"except",
":",
"raise",
"StopIteration",
"(",
")"
] | Get the next child.
@return: The next child.
@rtype: L{Element}
@raise StopIterator: At the end. | [
"Get",
"the",
"next",
"child",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L973-L985 | train | 202,228 |
cackharot/suds-py3 | suds/sax/element.py | PrefixNormalizer.pset | def pset(self, n):
"""
Convert the nodes nsprefixes into a set.
@param n: A node.
@type n: L{Element}
@return: A set of namespaces.
@rtype: set
"""
s = set()
for ns in n.nsprefixes.items():
if self.permit(ns):
s.add(ns[1])
return s | python | def pset(self, n):
"""
Convert the nodes nsprefixes into a set.
@param n: A node.
@type n: L{Element}
@return: A set of namespaces.
@rtype: set
"""
s = set()
for ns in n.nsprefixes.items():
if self.permit(ns):
s.add(ns[1])
return s | [
"def",
"pset",
"(",
"self",
",",
"n",
")",
":",
"s",
"=",
"set",
"(",
")",
"for",
"ns",
"in",
"n",
".",
"nsprefixes",
".",
"items",
"(",
")",
":",
"if",
"self",
".",
"permit",
"(",
"ns",
")",
":",
"s",
".",
"add",
"(",
"ns",
"[",
"1",
"]"... | Convert the nodes nsprefixes into a set.
@param n: A node.
@type n: L{Element}
@return: A set of namespaces.
@rtype: set | [
"Convert",
"the",
"nodes",
"nsprefixes",
"into",
"a",
"set",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sax/element.py#L1036-L1048 | train | 202,229 |
cackharot/suds-py3 | suds/sudsobject.py | Printer.tostr | def tostr(self, object, indent=-2):
""" get s string representation of object """
history = []
return self.process(object, history, indent) | python | def tostr(self, object, indent=-2):
""" get s string representation of object """
history = []
return self.process(object, history, indent) | [
"def",
"tostr",
"(",
"self",
",",
"object",
",",
"indent",
"=",
"-",
"2",
")",
":",
"history",
"=",
"[",
"]",
"return",
"self",
".",
"process",
"(",
"object",
",",
"history",
",",
"indent",
")"
] | get s string representation of object | [
"get",
"s",
"string",
"representation",
"of",
"object"
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/sudsobject.py#L260-L263 | train | 202,230 |
cackharot/suds-py3 | suds/xsd/sxbase.py | SchemaObject.attributes | def attributes(self, filter=Filter()):
"""
Get only the attribute content.
@param filter: A filter to constrain the result.
@type filter: L{Filter}
@return: A list of tuples (attr, ancestry)
@rtype: [(L{SchemaObject}, [L{SchemaObject},..]),..]
"""
result = []
for child, ancestry in self:
if child.isattr() and child in filter:
result.append((child, ancestry))
return result | python | def attributes(self, filter=Filter()):
"""
Get only the attribute content.
@param filter: A filter to constrain the result.
@type filter: L{Filter}
@return: A list of tuples (attr, ancestry)
@rtype: [(L{SchemaObject}, [L{SchemaObject},..]),..]
"""
result = []
for child, ancestry in self:
if child.isattr() and child in filter:
result.append((child, ancestry))
return result | [
"def",
"attributes",
"(",
"self",
",",
"filter",
"=",
"Filter",
"(",
")",
")",
":",
"result",
"=",
"[",
"]",
"for",
"child",
",",
"ancestry",
"in",
"self",
":",
"if",
"child",
".",
"isattr",
"(",
")",
"and",
"child",
"in",
"filter",
":",
"result",
... | Get only the attribute content.
@param filter: A filter to constrain the result.
@type filter: L{Filter}
@return: A list of tuples (attr, ancestry)
@rtype: [(L{SchemaObject}, [L{SchemaObject},..]),..] | [
"Get",
"only",
"the",
"attribute",
"content",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/xsd/sxbase.py#L108-L120 | train | 202,231 |
cackharot/suds-py3 | suds/xsd/sxbase.py | SchemaObject.namespace | def namespace(self, prefix=None):
"""
Get this properties namespace
@param prefix: The default prefix.
@type prefix: str
@return: The schema's target namespace
@rtype: (I{prefix},I{URI})
"""
ns = self.schema.tns
if ns[0] is None:
ns = (prefix, ns[1])
return ns | python | def namespace(self, prefix=None):
"""
Get this properties namespace
@param prefix: The default prefix.
@type prefix: str
@return: The schema's target namespace
@rtype: (I{prefix},I{URI})
"""
ns = self.schema.tns
if ns[0] is None:
ns = (prefix, ns[1])
return ns | [
"def",
"namespace",
"(",
"self",
",",
"prefix",
"=",
"None",
")",
":",
"ns",
"=",
"self",
".",
"schema",
".",
"tns",
"if",
"ns",
"[",
"0",
"]",
"is",
"None",
":",
"ns",
"=",
"(",
"prefix",
",",
"ns",
"[",
"1",
"]",
")",
"return",
"ns"
] | Get this properties namespace
@param prefix: The default prefix.
@type prefix: str
@return: The schema's target namespace
@rtype: (I{prefix},I{URI}) | [
"Get",
"this",
"properties",
"namespace"
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/xsd/sxbase.py#L162-L173 | train | 202,232 |
cackharot/suds-py3 | suds/xsd/sxbase.py | SchemaObject.find | def find(self, qref, classes=()):
"""
Find a referenced type in self or children.
@param qref: A qualified reference.
@type qref: qref
@param classes: A list of classes used to qualify the match.
@type classes: [I{class},...]
@return: The referenced type.
@rtype: L{SchemaObject}
@see: L{qualify()}
"""
if not len(classes):
classes = (self.__class__,)
if self.qname == qref and self.__class__ in classes:
return self
for c in self.rawchildren:
p = c.find(qref, classes)
if p is not None:
return p
return None | python | def find(self, qref, classes=()):
"""
Find a referenced type in self or children.
@param qref: A qualified reference.
@type qref: qref
@param classes: A list of classes used to qualify the match.
@type classes: [I{class},...]
@return: The referenced type.
@rtype: L{SchemaObject}
@see: L{qualify()}
"""
if not len(classes):
classes = (self.__class__,)
if self.qname == qref and self.__class__ in classes:
return self
for c in self.rawchildren:
p = c.find(qref, classes)
if p is not None:
return p
return None | [
"def",
"find",
"(",
"self",
",",
"qref",
",",
"classes",
"=",
"(",
")",
")",
":",
"if",
"not",
"len",
"(",
"classes",
")",
":",
"classes",
"=",
"(",
"self",
".",
"__class__",
",",
")",
"if",
"self",
".",
"qname",
"==",
"qref",
"and",
"self",
".... | Find a referenced type in self or children.
@param qref: A qualified reference.
@type qref: qref
@param classes: A list of classes used to qualify the match.
@type classes: [I{class},...]
@return: The referenced type.
@rtype: L{SchemaObject}
@see: L{qualify()} | [
"Find",
"a",
"referenced",
"type",
"in",
"self",
"or",
"children",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/xsd/sxbase.py#L307-L326 | train | 202,233 |
cackharot/suds-py3 | suds/xsd/sxbase.py | SchemaObject.merge | def merge(self, other):
"""
Merge another object as needed.
"""
other.qualify()
for n in ('name',
'qname',
'min',
'max',
'default',
'type',
'nillable',
'form_qualified',):
if getattr(self, n) is not None:
continue
v = getattr(other, n)
if v is None:
continue
setattr(self, n, v) | python | def merge(self, other):
"""
Merge another object as needed.
"""
other.qualify()
for n in ('name',
'qname',
'min',
'max',
'default',
'type',
'nillable',
'form_qualified',):
if getattr(self, n) is not None:
continue
v = getattr(other, n)
if v is None:
continue
setattr(self, n, v) | [
"def",
"merge",
"(",
"self",
",",
"other",
")",
":",
"other",
".",
"qualify",
"(",
")",
"for",
"n",
"in",
"(",
"'name'",
",",
"'qname'",
",",
"'min'",
",",
"'max'",
",",
"'default'",
",",
"'type'",
",",
"'nillable'",
",",
"'form_qualified'",
",",
")"... | Merge another object as needed. | [
"Merge",
"another",
"object",
"as",
"needed",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/xsd/sxbase.py#L382-L400 | train | 202,234 |
cackharot/suds-py3 | suds/xsd/sxbase.py | SchemaObject.str | def str(self, indent=0, history=None):
"""
Get a string representation of this object.
@param indent: The indent.
@type indent: int
@return: A string.
@rtype: str
"""
if history is None:
history = []
if self in history:
return '%s ...' % Repr(self)
history.append(self)
tab = '%*s' % (indent * 3, '')
result = []
result.append('%s<%s' % (tab, self.id))
for n in self.description():
if not hasattr(self, n):
continue
v = getattr(self, n)
if v is None:
continue
result.append(' %s="%s"' % (n, v))
if len(self):
result.append('>')
for c in self.rawchildren:
result.append('\n')
result.append(c.str(indent+1, history[:]))
if c.isattr():
result.append('@')
result.append('\n%s' % tab)
result.append('</%s>' % self.__class__.__name__)
else:
result.append(' />')
return ''.join(result) | python | def str(self, indent=0, history=None):
"""
Get a string representation of this object.
@param indent: The indent.
@type indent: int
@return: A string.
@rtype: str
"""
if history is None:
history = []
if self in history:
return '%s ...' % Repr(self)
history.append(self)
tab = '%*s' % (indent * 3, '')
result = []
result.append('%s<%s' % (tab, self.id))
for n in self.description():
if not hasattr(self, n):
continue
v = getattr(self, n)
if v is None:
continue
result.append(' %s="%s"' % (n, v))
if len(self):
result.append('>')
for c in self.rawchildren:
result.append('\n')
result.append(c.str(indent+1, history[:]))
if c.isattr():
result.append('@')
result.append('\n%s' % tab)
result.append('</%s>' % self.__class__.__name__)
else:
result.append(' />')
return ''.join(result) | [
"def",
"str",
"(",
"self",
",",
"indent",
"=",
"0",
",",
"history",
"=",
"None",
")",
":",
"if",
"history",
"is",
"None",
":",
"history",
"=",
"[",
"]",
"if",
"self",
"in",
"history",
":",
"return",
"'%s ...'",
"%",
"Repr",
"(",
"self",
")",
"his... | Get a string representation of this object.
@param indent: The indent.
@type indent: int
@return: A string.
@rtype: str | [
"Get",
"a",
"string",
"representation",
"of",
"this",
"object",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/xsd/sxbase.py#L427-L461 | train | 202,235 |
cackharot/suds-py3 | suds/xsd/sxbase.py | NodeFinder.find | def find(self, node, list):
"""
Traverse the tree looking for matches.
@param node: A node to match on.
@type node: L{SchemaObject}
@param list: A list to fill.
@type list: list
"""
if self.matcher.match(node):
list.append(node)
self.limit -= 1
if self.limit == 0:
return
for c in node.rawchildren:
self.find(c, list)
return self | python | def find(self, node, list):
"""
Traverse the tree looking for matches.
@param node: A node to match on.
@type node: L{SchemaObject}
@param list: A list to fill.
@type list: list
"""
if self.matcher.match(node):
list.append(node)
self.limit -= 1
if self.limit == 0:
return
for c in node.rawchildren:
self.find(c, list)
return self | [
"def",
"find",
"(",
"self",
",",
"node",
",",
"list",
")",
":",
"if",
"self",
".",
"matcher",
".",
"match",
"(",
"node",
")",
":",
"list",
".",
"append",
"(",
"node",
")",
"self",
".",
"limit",
"-=",
"1",
"if",
"self",
".",
"limit",
"==",
"0",
... | Traverse the tree looking for matches.
@param node: A node to match on.
@type node: L{SchemaObject}
@param list: A list to fill.
@type list: list | [
"Traverse",
"the",
"tree",
"looking",
"for",
"matches",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/xsd/sxbase.py#L657-L672 | train | 202,236 |
cackharot/suds-py3 | suds/cache.py | FileCache.setduration | def setduration(self, **duration):
"""
Set the caching duration which defines how long the
file will be cached.
@param duration: The cached file duration which defines how
long the file will be cached. A duration=0 means forever.
The duration may be: (months|weeks|days|hours|minutes|seconds).
@type duration: {unit:value}
"""
if len(duration) == 1:
arg = [x[0] for x in duration.items()]
if not arg[0] in self.units:
raise Exception('must be: %s' % str(self.units))
self.duration = arg
return self | python | def setduration(self, **duration):
"""
Set the caching duration which defines how long the
file will be cached.
@param duration: The cached file duration which defines how
long the file will be cached. A duration=0 means forever.
The duration may be: (months|weeks|days|hours|minutes|seconds).
@type duration: {unit:value}
"""
if len(duration) == 1:
arg = [x[0] for x in duration.items()]
if not arg[0] in self.units:
raise Exception('must be: %s' % str(self.units))
self.duration = arg
return self | [
"def",
"setduration",
"(",
"self",
",",
"*",
"*",
"duration",
")",
":",
"if",
"len",
"(",
"duration",
")",
"==",
"1",
":",
"arg",
"=",
"[",
"x",
"[",
"0",
"]",
"for",
"x",
"in",
"duration",
".",
"items",
"(",
")",
"]",
"if",
"not",
"arg",
"["... | Set the caching duration which defines how long the
file will be cached.
@param duration: The cached file duration which defines how
long the file will be cached. A duration=0 means forever.
The duration may be: (months|weeks|days|hours|minutes|seconds).
@type duration: {unit:value} | [
"Set",
"the",
"caching",
"duration",
"which",
"defines",
"how",
"long",
"the",
"file",
"will",
"be",
"cached",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/cache.py#L153-L167 | train | 202,237 |
cackharot/suds-py3 | suds/mx/literal.py | Typed.sort | def sort(self, content):
"""
Sort suds object attributes based on ordering defined
in the XSD type information.
@param content: The content to sort.
@type content: L{Object}
@return: self
@rtype: L{Typed}
"""
v = content.value
if isinstance(v, Object):
md = v.__metadata__
md.ordering = self.ordering(content.real)
return self | python | def sort(self, content):
"""
Sort suds object attributes based on ordering defined
in the XSD type information.
@param content: The content to sort.
@type content: L{Object}
@return: self
@rtype: L{Typed}
"""
v = content.value
if isinstance(v, Object):
md = v.__metadata__
md.ordering = self.ordering(content.real)
return self | [
"def",
"sort",
"(",
"self",
",",
"content",
")",
":",
"v",
"=",
"content",
".",
"value",
"if",
"isinstance",
"(",
"v",
",",
"Object",
")",
":",
"md",
"=",
"v",
".",
"__metadata__",
"md",
".",
"ordering",
"=",
"self",
".",
"ordering",
"(",
"content"... | Sort suds object attributes based on ordering defined
in the XSD type information.
@param content: The content to sort.
@type content: L{Object}
@return: self
@rtype: L{Typed} | [
"Sort",
"suds",
"object",
"attributes",
"based",
"on",
"ordering",
"defined",
"in",
"the",
"XSD",
"type",
"information",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/mx/literal.py#L242-L255 | train | 202,238 |
cackharot/suds-py3 | suds/mx/literal.py | Typed.ordering | def ordering(self, type):
"""
Get the attribute ordering defined in the specified
XSD type information.
@param type: An XSD type object.
@type type: SchemaObject
@return: An ordered list of attribute names.
@rtype: list
"""
result = []
for child, ancestry in type.resolve():
name = child.name
if child.name is None:
continue
if child.isattr():
name = '_%s' % child.name
result.append(name)
return result | python | def ordering(self, type):
"""
Get the attribute ordering defined in the specified
XSD type information.
@param type: An XSD type object.
@type type: SchemaObject
@return: An ordered list of attribute names.
@rtype: list
"""
result = []
for child, ancestry in type.resolve():
name = child.name
if child.name is None:
continue
if child.isattr():
name = '_%s' % child.name
result.append(name)
return result | [
"def",
"ordering",
"(",
"self",
",",
"type",
")",
":",
"result",
"=",
"[",
"]",
"for",
"child",
",",
"ancestry",
"in",
"type",
".",
"resolve",
"(",
")",
":",
"name",
"=",
"child",
".",
"name",
"if",
"child",
".",
"name",
"is",
"None",
":",
"conti... | Get the attribute ordering defined in the specified
XSD type information.
@param type: An XSD type object.
@type type: SchemaObject
@return: An ordered list of attribute names.
@rtype: list | [
"Get",
"the",
"attribute",
"ordering",
"defined",
"in",
"the",
"specified",
"XSD",
"type",
"information",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/mx/literal.py#L257-L274 | train | 202,239 |
cackharot/suds-py3 | suds/builder.py | Builder.build | def build(self, name):
"build an object for the specified typename as defined in the schema"
if isinstance(name, basestring):
type = self.resolver.find(name)
if type is None:
raise TypeNotFound(name)
else:
type = name
cls = type.name
if type.mixed():
data = Factory.property(cls)
else:
data = Factory.object(cls)
resolved = type.resolve()
md = data.__metadata__
md.sxtype = resolved
md.ordering = self.ordering(resolved)
history = []
self.add_attributes(data, resolved)
for child, ancestry in type.children():
if self.skip_child(child, ancestry):
continue
self.process(data, child, history[:])
return data | python | def build(self, name):
"build an object for the specified typename as defined in the schema"
if isinstance(name, basestring):
type = self.resolver.find(name)
if type is None:
raise TypeNotFound(name)
else:
type = name
cls = type.name
if type.mixed():
data = Factory.property(cls)
else:
data = Factory.object(cls)
resolved = type.resolve()
md = data.__metadata__
md.sxtype = resolved
md.ordering = self.ordering(resolved)
history = []
self.add_attributes(data, resolved)
for child, ancestry in type.children():
if self.skip_child(child, ancestry):
continue
self.process(data, child, history[:])
return data | [
"def",
"build",
"(",
"self",
",",
"name",
")",
":",
"if",
"isinstance",
"(",
"name",
",",
"basestring",
")",
":",
"type",
"=",
"self",
".",
"resolver",
".",
"find",
"(",
"name",
")",
"if",
"type",
"is",
"None",
":",
"raise",
"TypeNotFound",
"(",
"n... | build an object for the specified typename as defined in the schema | [
"build",
"an",
"object",
"for",
"the",
"specified",
"typename",
"as",
"defined",
"in",
"the",
"schema"
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/builder.py#L39-L62 | train | 202,240 |
cackharot/suds-py3 | suds/builder.py | Builder.add_attributes | def add_attributes(self, data, type):
""" add required attributes """
for attr, ancestry in type.attributes():
name = '_%s' % attr.name
value = attr.get_default()
setattr(data, name, value) | python | def add_attributes(self, data, type):
""" add required attributes """
for attr, ancestry in type.attributes():
name = '_%s' % attr.name
value = attr.get_default()
setattr(data, name, value) | [
"def",
"add_attributes",
"(",
"self",
",",
"data",
",",
"type",
")",
":",
"for",
"attr",
",",
"ancestry",
"in",
"type",
".",
"attributes",
"(",
")",
":",
"name",
"=",
"'_%s'",
"%",
"attr",
".",
"name",
"value",
"=",
"attr",
".",
"get_default",
"(",
... | add required attributes | [
"add",
"required",
"attributes"
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/builder.py#L96-L101 | train | 202,241 |
cackharot/suds-py3 | suds/properties.py | Link.validate | def validate(self, pA, pB):
"""
Validate that the two properties may be linked.
@param pA: Endpoint (A) to link.
@type pA: L{Endpoint}
@param pB: Endpoint (B) to link.
@type pB: L{Endpoint}
@return: self
@rtype: L{Link}
"""
if pA in pB.links or \
pB in pA.links:
raise Exception('Already linked')
dA = pA.domains()
dB = pB.domains()
for d in dA:
if d in dB:
raise Exception('Duplicate domain "%s" found' % d)
for d in dB:
if d in dA:
raise Exception('Duplicate domain "%s" found' % d)
kA = pA.keys()
kB = pB.keys()
for k in kA:
if k in kB:
raise Exception('Duplicate key %s found' % k)
for k in kB:
if k in kA:
raise Exception('Duplicate key %s found' % k)
return self | python | def validate(self, pA, pB):
"""
Validate that the two properties may be linked.
@param pA: Endpoint (A) to link.
@type pA: L{Endpoint}
@param pB: Endpoint (B) to link.
@type pB: L{Endpoint}
@return: self
@rtype: L{Link}
"""
if pA in pB.links or \
pB in pA.links:
raise Exception('Already linked')
dA = pA.domains()
dB = pB.domains()
for d in dA:
if d in dB:
raise Exception('Duplicate domain "%s" found' % d)
for d in dB:
if d in dA:
raise Exception('Duplicate domain "%s" found' % d)
kA = pA.keys()
kB = pB.keys()
for k in kA:
if k in kB:
raise Exception('Duplicate key %s found' % k)
for k in kB:
if k in kA:
raise Exception('Duplicate key %s found' % k)
return self | [
"def",
"validate",
"(",
"self",
",",
"pA",
",",
"pB",
")",
":",
"if",
"pA",
"in",
"pB",
".",
"links",
"or",
"pB",
"in",
"pA",
".",
"links",
":",
"raise",
"Exception",
"(",
"'Already linked'",
")",
"dA",
"=",
"pA",
".",
"domains",
"(",
")",
"dB",
... | Validate that the two properties may be linked.
@param pA: Endpoint (A) to link.
@type pA: L{Endpoint}
@param pB: Endpoint (B) to link.
@type pB: L{Endpoint}
@return: self
@rtype: L{Link} | [
"Validate",
"that",
"the",
"two",
"properties",
"may",
"be",
"linked",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/properties.py#L63-L92 | train | 202,242 |
cackharot/suds-py3 | suds/properties.py | Properties.prime | def prime(self):
"""
Prime the stored values based on default values
found in property definitions.
@return: self
@rtype: L{Properties}
"""
for d in self.definitions.values():
self.defined[d.name] = d.default
return self | python | def prime(self):
"""
Prime the stored values based on default values
found in property definitions.
@return: self
@rtype: L{Properties}
"""
for d in self.definitions.values():
self.defined[d.name] = d.default
return self | [
"def",
"prime",
"(",
"self",
")",
":",
"for",
"d",
"in",
"self",
".",
"definitions",
".",
"values",
"(",
")",
":",
"self",
".",
"defined",
"[",
"d",
".",
"name",
"]",
"=",
"d",
".",
"default",
"return",
"self"
] | Prime the stored values based on default values
found in property definitions.
@return: self
@rtype: L{Properties} | [
"Prime",
"the",
"stored",
"values",
"based",
"on",
"default",
"values",
"found",
"in",
"property",
"definitions",
"."
] | 7387ec7806e9be29aad0a711bea5cb3c9396469c | https://github.com/cackharot/suds-py3/blob/7387ec7806e9be29aad0a711bea5cb3c9396469c/suds/properties.py#L407-L416 | train | 202,243 |
Grunny/zap-cli | zapcli/commands/scanners.py | list_scanners | def list_scanners(zap_helper, scanners):
"""Get a list of scanners and whether or not they are enabled."""
scanner_list = zap_helper.zap.ascan.scanners()
if scanners is not None and 'all' not in scanners:
scanner_list = filter_by_ids(scanner_list, scanners)
click.echo(tabulate([[s['id'], s['name'], s['policyId'], s['enabled'], s['attackStrength'], s['alertThreshold']]
for s in scanner_list],
headers=['ID', 'Name', 'Policy ID', 'Enabled', 'Strength', 'Threshold'],
tablefmt='grid')) | python | def list_scanners(zap_helper, scanners):
"""Get a list of scanners and whether or not they are enabled."""
scanner_list = zap_helper.zap.ascan.scanners()
if scanners is not None and 'all' not in scanners:
scanner_list = filter_by_ids(scanner_list, scanners)
click.echo(tabulate([[s['id'], s['name'], s['policyId'], s['enabled'], s['attackStrength'], s['alertThreshold']]
for s in scanner_list],
headers=['ID', 'Name', 'Policy ID', 'Enabled', 'Strength', 'Threshold'],
tablefmt='grid')) | [
"def",
"list_scanners",
"(",
"zap_helper",
",",
"scanners",
")",
":",
"scanner_list",
"=",
"zap_helper",
".",
"zap",
".",
"ascan",
".",
"scanners",
"(",
")",
"if",
"scanners",
"is",
"not",
"None",
"and",
"'all'",
"not",
"in",
"scanners",
":",
"scanner_list... | Get a list of scanners and whether or not they are enabled. | [
"Get",
"a",
"list",
"of",
"scanners",
"and",
"whether",
"or",
"not",
"they",
"are",
"enabled",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/scanners.py#L31-L41 | train | 202,244 |
Grunny/zap-cli | zapcli/commands/scanners.py | set_scanner_strength | def set_scanner_strength(zap_helper, scanners, strength):
"""Set the attack strength for scanners."""
if not scanners or 'all' in scanners:
scanners = _get_all_scanner_ids(zap_helper)
with zap_error_handler():
zap_helper.set_scanner_attack_strength(scanners, strength)
console.info('Set attack strength to {0}.'.format(strength)) | python | def set_scanner_strength(zap_helper, scanners, strength):
"""Set the attack strength for scanners."""
if not scanners or 'all' in scanners:
scanners = _get_all_scanner_ids(zap_helper)
with zap_error_handler():
zap_helper.set_scanner_attack_strength(scanners, strength)
console.info('Set attack strength to {0}.'.format(strength)) | [
"def",
"set_scanner_strength",
"(",
"zap_helper",
",",
"scanners",
",",
"strength",
")",
":",
"if",
"not",
"scanners",
"or",
"'all'",
"in",
"scanners",
":",
"scanners",
"=",
"_get_all_scanner_ids",
"(",
"zap_helper",
")",
"with",
"zap_error_handler",
"(",
")",
... | Set the attack strength for scanners. | [
"Set",
"the",
"attack",
"strength",
"for",
"scanners",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/scanners.py#L74-L82 | train | 202,245 |
Grunny/zap-cli | zapcli/commands/scanners.py | set_scanner_threshold | def set_scanner_threshold(zap_helper, scanners, threshold):
"""Set the alert threshold for scanners."""
if not scanners or 'all' in scanners:
scanners = _get_all_scanner_ids(zap_helper)
with zap_error_handler():
zap_helper.set_scanner_alert_threshold(scanners, threshold)
console.info('Set alert threshold to {0}.'.format(threshold)) | python | def set_scanner_threshold(zap_helper, scanners, threshold):
"""Set the alert threshold for scanners."""
if not scanners or 'all' in scanners:
scanners = _get_all_scanner_ids(zap_helper)
with zap_error_handler():
zap_helper.set_scanner_alert_threshold(scanners, threshold)
console.info('Set alert threshold to {0}.'.format(threshold)) | [
"def",
"set_scanner_threshold",
"(",
"zap_helper",
",",
"scanners",
",",
"threshold",
")",
":",
"if",
"not",
"scanners",
"or",
"'all'",
"in",
"scanners",
":",
"scanners",
"=",
"_get_all_scanner_ids",
"(",
"zap_helper",
")",
"with",
"zap_error_handler",
"(",
")",... | Set the alert threshold for scanners. | [
"Set",
"the",
"alert",
"threshold",
"for",
"scanners",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/scanners.py#L93-L101 | train | 202,246 |
Grunny/zap-cli | zapcli/commands/scanners.py | _get_all_scanner_ids | def _get_all_scanner_ids(zap_helper):
"""Get all scanner IDs."""
scanners = zap_helper.zap.ascan.scanners()
return [s['id'] for s in scanners] | python | def _get_all_scanner_ids(zap_helper):
"""Get all scanner IDs."""
scanners = zap_helper.zap.ascan.scanners()
return [s['id'] for s in scanners] | [
"def",
"_get_all_scanner_ids",
"(",
"zap_helper",
")",
":",
"scanners",
"=",
"zap_helper",
".",
"zap",
".",
"ascan",
".",
"scanners",
"(",
")",
"return",
"[",
"s",
"[",
"'id'",
"]",
"for",
"s",
"in",
"scanners",
"]"
] | Get all scanner IDs. | [
"Get",
"all",
"scanner",
"IDs",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/scanners.py#L104-L107 | train | 202,247 |
Grunny/zap-cli | zapcli/commands/policies.py | list_policies | def list_policies(zap_helper, policy_ids):
"""
Get a list of policies and whether or not they are enabled.
"""
policies = filter_by_ids(zap_helper.zap.ascan.policies(), policy_ids)
click.echo(tabulate([[p['id'], p['name'], p['enabled'], p['attackStrength'], p['alertThreshold']]
for p in policies],
headers=['ID', 'Name', 'Enabled', 'Strength', 'Threshold'],
tablefmt='grid')) | python | def list_policies(zap_helper, policy_ids):
"""
Get a list of policies and whether or not they are enabled.
"""
policies = filter_by_ids(zap_helper.zap.ascan.policies(), policy_ids)
click.echo(tabulate([[p['id'], p['name'], p['enabled'], p['attackStrength'], p['alertThreshold']]
for p in policies],
headers=['ID', 'Name', 'Enabled', 'Strength', 'Threshold'],
tablefmt='grid')) | [
"def",
"list_policies",
"(",
"zap_helper",
",",
"policy_ids",
")",
":",
"policies",
"=",
"filter_by_ids",
"(",
"zap_helper",
".",
"zap",
".",
"ascan",
".",
"policies",
"(",
")",
",",
"policy_ids",
")",
"click",
".",
"echo",
"(",
"tabulate",
"(",
"[",
"["... | Get a list of policies and whether or not they are enabled. | [
"Get",
"a",
"list",
"of",
"policies",
"and",
"whether",
"or",
"not",
"they",
"are",
"enabled",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/policies.py#L29-L38 | train | 202,248 |
Grunny/zap-cli | zapcli/commands/policies.py | enable_policies | def enable_policies(zap_helper, policy_ids):
"""
Set the enabled policies to use in a scan.
When you enable a selection of policies, all other policies are
disabled.
"""
if not policy_ids:
policy_ids = _get_all_policy_ids(zap_helper)
with zap_error_handler():
zap_helper.enable_policies_by_ids(policy_ids) | python | def enable_policies(zap_helper, policy_ids):
"""
Set the enabled policies to use in a scan.
When you enable a selection of policies, all other policies are
disabled.
"""
if not policy_ids:
policy_ids = _get_all_policy_ids(zap_helper)
with zap_error_handler():
zap_helper.enable_policies_by_ids(policy_ids) | [
"def",
"enable_policies",
"(",
"zap_helper",
",",
"policy_ids",
")",
":",
"if",
"not",
"policy_ids",
":",
"policy_ids",
"=",
"_get_all_policy_ids",
"(",
"zap_helper",
")",
"with",
"zap_error_handler",
"(",
")",
":",
"zap_helper",
".",
"enable_policies_by_ids",
"("... | Set the enabled policies to use in a scan.
When you enable a selection of policies, all other policies are
disabled. | [
"Set",
"the",
"enabled",
"policies",
"to",
"use",
"in",
"a",
"scan",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/policies.py#L46-L57 | train | 202,249 |
Grunny/zap-cli | zapcli/commands/policies.py | set_policy_strength | def set_policy_strength(zap_helper, policy_ids, strength):
"""Set the attack strength for policies."""
if not policy_ids:
policy_ids = _get_all_policy_ids(zap_helper)
with zap_error_handler():
zap_helper.set_policy_attack_strength(policy_ids, strength)
console.info('Set attack strength to {0}.'.format(strength)) | python | def set_policy_strength(zap_helper, policy_ids, strength):
"""Set the attack strength for policies."""
if not policy_ids:
policy_ids = _get_all_policy_ids(zap_helper)
with zap_error_handler():
zap_helper.set_policy_attack_strength(policy_ids, strength)
console.info('Set attack strength to {0}.'.format(strength)) | [
"def",
"set_policy_strength",
"(",
"zap_helper",
",",
"policy_ids",
",",
"strength",
")",
":",
"if",
"not",
"policy_ids",
":",
"policy_ids",
"=",
"_get_all_policy_ids",
"(",
"zap_helper",
")",
"with",
"zap_error_handler",
"(",
")",
":",
"zap_helper",
".",
"set_p... | Set the attack strength for policies. | [
"Set",
"the",
"attack",
"strength",
"for",
"policies",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/policies.py#L67-L75 | train | 202,250 |
Grunny/zap-cli | zapcli/commands/policies.py | set_policy_threshold | def set_policy_threshold(zap_helper, policy_ids, threshold):
"""Set the alert threshold for policies."""
if not policy_ids:
policy_ids = _get_all_policy_ids(zap_helper)
with zap_error_handler():
zap_helper.set_policy_alert_threshold(policy_ids, threshold)
console.info('Set alert threshold to {0}.'.format(threshold)) | python | def set_policy_threshold(zap_helper, policy_ids, threshold):
"""Set the alert threshold for policies."""
if not policy_ids:
policy_ids = _get_all_policy_ids(zap_helper)
with zap_error_handler():
zap_helper.set_policy_alert_threshold(policy_ids, threshold)
console.info('Set alert threshold to {0}.'.format(threshold)) | [
"def",
"set_policy_threshold",
"(",
"zap_helper",
",",
"policy_ids",
",",
"threshold",
")",
":",
"if",
"not",
"policy_ids",
":",
"policy_ids",
"=",
"_get_all_policy_ids",
"(",
"zap_helper",
")",
"with",
"zap_error_handler",
"(",
")",
":",
"zap_helper",
".",
"set... | Set the alert threshold for policies. | [
"Set",
"the",
"alert",
"threshold",
"for",
"policies",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/policies.py#L85-L93 | train | 202,251 |
Grunny/zap-cli | zapcli/commands/policies.py | _get_all_policy_ids | def _get_all_policy_ids(zap_helper):
"""Get all policy IDs."""
policies = zap_helper.zap.ascan.policies()
return [p['id'] for p in policies] | python | def _get_all_policy_ids(zap_helper):
"""Get all policy IDs."""
policies = zap_helper.zap.ascan.policies()
return [p['id'] for p in policies] | [
"def",
"_get_all_policy_ids",
"(",
"zap_helper",
")",
":",
"policies",
"=",
"zap_helper",
".",
"zap",
".",
"ascan",
".",
"policies",
"(",
")",
"return",
"[",
"p",
"[",
"'id'",
"]",
"for",
"p",
"in",
"policies",
"]"
] | Get all policy IDs. | [
"Get",
"all",
"policy",
"IDs",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/policies.py#L96-L99 | train | 202,252 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.start | def start(self, options=None):
"""Start the ZAP Daemon."""
if self.is_running():
self.logger.warn('ZAP is already running on port {0}'.format(self.port))
return
if platform.system() == 'Windows' or platform.system().startswith('CYGWIN'):
executable = 'zap.bat'
else:
executable = 'zap.sh'
executable_path = os.path.join(self.zap_path, executable)
if not os.path.isfile(executable_path):
raise ZAPError(('ZAP was not found in the path "{0}". You can set the path to where ZAP is ' +
'installed on your system using the --zap-path command line parameter or by ' +
'default using the ZAP_PATH environment variable.').format(self.zap_path))
zap_command = [executable_path, '-daemon', '-port', str(self.port)]
if options:
extra_options = shlex.split(options)
zap_command += extra_options
if self.log_path is None:
log_path = os.path.join(self.zap_path, 'zap.log')
else:
log_path = os.path.join(self.log_path, 'zap.log')
self.logger.debug('Starting ZAP process with command: {0}.'.format(' '.join(zap_command)))
self.logger.debug('Logging to {0}'.format(log_path))
with open(log_path, 'w+') as log_file:
subprocess.Popen(
zap_command, cwd=self.zap_path, stdout=log_file,
stderr=subprocess.STDOUT)
self.wait_for_zap(self.timeout)
self.logger.debug('ZAP started successfully.') | python | def start(self, options=None):
"""Start the ZAP Daemon."""
if self.is_running():
self.logger.warn('ZAP is already running on port {0}'.format(self.port))
return
if platform.system() == 'Windows' or platform.system().startswith('CYGWIN'):
executable = 'zap.bat'
else:
executable = 'zap.sh'
executable_path = os.path.join(self.zap_path, executable)
if not os.path.isfile(executable_path):
raise ZAPError(('ZAP was not found in the path "{0}". You can set the path to where ZAP is ' +
'installed on your system using the --zap-path command line parameter or by ' +
'default using the ZAP_PATH environment variable.').format(self.zap_path))
zap_command = [executable_path, '-daemon', '-port', str(self.port)]
if options:
extra_options = shlex.split(options)
zap_command += extra_options
if self.log_path is None:
log_path = os.path.join(self.zap_path, 'zap.log')
else:
log_path = os.path.join(self.log_path, 'zap.log')
self.logger.debug('Starting ZAP process with command: {0}.'.format(' '.join(zap_command)))
self.logger.debug('Logging to {0}'.format(log_path))
with open(log_path, 'w+') as log_file:
subprocess.Popen(
zap_command, cwd=self.zap_path, stdout=log_file,
stderr=subprocess.STDOUT)
self.wait_for_zap(self.timeout)
self.logger.debug('ZAP started successfully.') | [
"def",
"start",
"(",
"self",
",",
"options",
"=",
"None",
")",
":",
"if",
"self",
".",
"is_running",
"(",
")",
":",
"self",
".",
"logger",
".",
"warn",
"(",
"'ZAP is already running on port {0}'",
".",
"format",
"(",
"self",
".",
"port",
")",
")",
"ret... | Start the ZAP Daemon. | [
"Start",
"the",
"ZAP",
"Daemon",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L59-L95 | train | 202,253 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.shutdown | def shutdown(self):
"""Shutdown ZAP."""
if not self.is_running():
self.logger.warn('ZAP is not running.')
return
self.logger.debug('Shutting down ZAP.')
self.zap.core.shutdown()
timeout_time = time.time() + self.timeout
while self.is_running():
if time.time() > timeout_time:
raise ZAPError('Timed out waiting for ZAP to shutdown.')
time.sleep(2)
self.logger.debug('ZAP shutdown successfully.') | python | def shutdown(self):
"""Shutdown ZAP."""
if not self.is_running():
self.logger.warn('ZAP is not running.')
return
self.logger.debug('Shutting down ZAP.')
self.zap.core.shutdown()
timeout_time = time.time() + self.timeout
while self.is_running():
if time.time() > timeout_time:
raise ZAPError('Timed out waiting for ZAP to shutdown.')
time.sleep(2)
self.logger.debug('ZAP shutdown successfully.') | [
"def",
"shutdown",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_running",
"(",
")",
":",
"self",
".",
"logger",
".",
"warn",
"(",
"'ZAP is not running.'",
")",
"return",
"self",
".",
"logger",
".",
"debug",
"(",
"'Shutting down ZAP.'",
")",
"self... | Shutdown ZAP. | [
"Shutdown",
"ZAP",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L97-L112 | train | 202,254 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.wait_for_zap | def wait_for_zap(self, timeout):
"""Wait for ZAP to be ready to receive API calls."""
timeout_time = time.time() + timeout
while not self.is_running():
if time.time() > timeout_time:
raise ZAPError('Timed out waiting for ZAP to start.')
time.sleep(2) | python | def wait_for_zap(self, timeout):
"""Wait for ZAP to be ready to receive API calls."""
timeout_time = time.time() + timeout
while not self.is_running():
if time.time() > timeout_time:
raise ZAPError('Timed out waiting for ZAP to start.')
time.sleep(2) | [
"def",
"wait_for_zap",
"(",
"self",
",",
"timeout",
")",
":",
"timeout_time",
"=",
"time",
".",
"time",
"(",
")",
"+",
"timeout",
"while",
"not",
"self",
".",
"is_running",
"(",
")",
":",
"if",
"time",
".",
"time",
"(",
")",
">",
"timeout_time",
":",... | Wait for ZAP to be ready to receive API calls. | [
"Wait",
"for",
"ZAP",
"to",
"be",
"ready",
"to",
"receive",
"API",
"calls",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L114-L120 | train | 202,255 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.is_running | def is_running(self):
"""Check if ZAP is running."""
try:
result = requests.get(self.proxy_url)
except RequestException:
return False
if 'ZAP-Header' in result.headers.get('Access-Control-Allow-Headers', []):
return True
raise ZAPError('Another process is listening on {0}'.format(self.proxy_url)) | python | def is_running(self):
"""Check if ZAP is running."""
try:
result = requests.get(self.proxy_url)
except RequestException:
return False
if 'ZAP-Header' in result.headers.get('Access-Control-Allow-Headers', []):
return True
raise ZAPError('Another process is listening on {0}'.format(self.proxy_url)) | [
"def",
"is_running",
"(",
"self",
")",
":",
"try",
":",
"result",
"=",
"requests",
".",
"get",
"(",
"self",
".",
"proxy_url",
")",
"except",
"RequestException",
":",
"return",
"False",
"if",
"'ZAP-Header'",
"in",
"result",
".",
"headers",
".",
"get",
"("... | Check if ZAP is running. | [
"Check",
"if",
"ZAP",
"is",
"running",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L122-L132 | train | 202,256 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.open_url | def open_url(self, url, sleep_after_open=2):
"""Access a URL through ZAP."""
self.zap.urlopen(url)
# Give the sites tree a chance to get updated
time.sleep(sleep_after_open) | python | def open_url(self, url, sleep_after_open=2):
"""Access a URL through ZAP."""
self.zap.urlopen(url)
# Give the sites tree a chance to get updated
time.sleep(sleep_after_open) | [
"def",
"open_url",
"(",
"self",
",",
"url",
",",
"sleep_after_open",
"=",
"2",
")",
":",
"self",
".",
"zap",
".",
"urlopen",
"(",
"url",
")",
"# Give the sites tree a chance to get updated",
"time",
".",
"sleep",
"(",
"sleep_after_open",
")"
] | Access a URL through ZAP. | [
"Access",
"a",
"URL",
"through",
"ZAP",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L134-L138 | train | 202,257 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.run_spider | def run_spider(self, target_url, context_name=None, user_name=None):
"""Run spider against a URL."""
self.logger.debug('Spidering target {0}...'.format(target_url))
context_id, user_id = self._get_context_and_user_ids(context_name, user_name)
if user_id:
self.logger.debug('Running spider in context {0} as user {1}'.format(context_id, user_id))
scan_id = self.zap.spider.scan_as_user(context_id, user_id, target_url)
else:
scan_id = self.zap.spider.scan(target_url)
if not scan_id:
raise ZAPError('Error running spider.')
elif not scan_id.isdigit():
raise ZAPError('Error running spider: "{0}"'.format(scan_id))
self.logger.debug('Started spider with ID {0}...'.format(scan_id))
while int(self.zap.spider.status()) < 100:
self.logger.debug('Spider progress %: {0}'.format(self.zap.spider.status()))
time.sleep(self._status_check_sleep)
self.logger.debug('Spider #{0} completed'.format(scan_id)) | python | def run_spider(self, target_url, context_name=None, user_name=None):
"""Run spider against a URL."""
self.logger.debug('Spidering target {0}...'.format(target_url))
context_id, user_id = self._get_context_and_user_ids(context_name, user_name)
if user_id:
self.logger.debug('Running spider in context {0} as user {1}'.format(context_id, user_id))
scan_id = self.zap.spider.scan_as_user(context_id, user_id, target_url)
else:
scan_id = self.zap.spider.scan(target_url)
if not scan_id:
raise ZAPError('Error running spider.')
elif not scan_id.isdigit():
raise ZAPError('Error running spider: "{0}"'.format(scan_id))
self.logger.debug('Started spider with ID {0}...'.format(scan_id))
while int(self.zap.spider.status()) < 100:
self.logger.debug('Spider progress %: {0}'.format(self.zap.spider.status()))
time.sleep(self._status_check_sleep)
self.logger.debug('Spider #{0} completed'.format(scan_id)) | [
"def",
"run_spider",
"(",
"self",
",",
"target_url",
",",
"context_name",
"=",
"None",
",",
"user_name",
"=",
"None",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'Spidering target {0}...'",
".",
"format",
"(",
"target_url",
")",
")",
"context_id",
... | Run spider against a URL. | [
"Run",
"spider",
"against",
"a",
"URL",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L140-L163 | train | 202,258 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.run_active_scan | def run_active_scan(self, target_url, recursive=False, context_name=None, user_name=None):
"""Run an active scan against a URL."""
self.logger.debug('Scanning target {0}...'.format(target_url))
context_id, user_id = self._get_context_and_user_ids(context_name, user_name)
if user_id:
self.logger.debug('Scanning in context {0} as user {1}'.format(context_id, user_id))
scan_id = self.zap.ascan.scan_as_user(target_url, context_id, user_id, recursive)
else:
scan_id = self.zap.ascan.scan(target_url, recurse=recursive)
if not scan_id:
raise ZAPError('Error running active scan.')
elif not scan_id.isdigit():
raise ZAPError(('Error running active scan: "{0}". Make sure the URL is in the site ' +
'tree by using the open-url or scanner commands before running an active ' +
'scan.').format(scan_id))
self.logger.debug('Started scan with ID {0}...'.format(scan_id))
while int(self.zap.ascan.status()) < 100:
self.logger.debug('Scan progress %: {0}'.format(self.zap.ascan.status()))
time.sleep(self._status_check_sleep)
self.logger.debug('Scan #{0} completed'.format(scan_id)) | python | def run_active_scan(self, target_url, recursive=False, context_name=None, user_name=None):
"""Run an active scan against a URL."""
self.logger.debug('Scanning target {0}...'.format(target_url))
context_id, user_id = self._get_context_and_user_ids(context_name, user_name)
if user_id:
self.logger.debug('Scanning in context {0} as user {1}'.format(context_id, user_id))
scan_id = self.zap.ascan.scan_as_user(target_url, context_id, user_id, recursive)
else:
scan_id = self.zap.ascan.scan(target_url, recurse=recursive)
if not scan_id:
raise ZAPError('Error running active scan.')
elif not scan_id.isdigit():
raise ZAPError(('Error running active scan: "{0}". Make sure the URL is in the site ' +
'tree by using the open-url or scanner commands before running an active ' +
'scan.').format(scan_id))
self.logger.debug('Started scan with ID {0}...'.format(scan_id))
while int(self.zap.ascan.status()) < 100:
self.logger.debug('Scan progress %: {0}'.format(self.zap.ascan.status()))
time.sleep(self._status_check_sleep)
self.logger.debug('Scan #{0} completed'.format(scan_id)) | [
"def",
"run_active_scan",
"(",
"self",
",",
"target_url",
",",
"recursive",
"=",
"False",
",",
"context_name",
"=",
"None",
",",
"user_name",
"=",
"None",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'Scanning target {0}...'",
".",
"format",
"(",
"... | Run an active scan against a URL. | [
"Run",
"an",
"active",
"scan",
"against",
"a",
"URL",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L165-L190 | train | 202,259 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.run_ajax_spider | def run_ajax_spider(self, target_url):
"""Run AJAX Spider against a URL."""
self.logger.debug('AJAX Spidering target {0}...'.format(target_url))
self.zap.ajaxSpider.scan(target_url)
while self.zap.ajaxSpider.status == 'running':
self.logger.debug('AJAX Spider: {0}'.format(self.zap.ajaxSpider.status))
time.sleep(self._status_check_sleep)
self.logger.debug('AJAX Spider completed') | python | def run_ajax_spider(self, target_url):
"""Run AJAX Spider against a URL."""
self.logger.debug('AJAX Spidering target {0}...'.format(target_url))
self.zap.ajaxSpider.scan(target_url)
while self.zap.ajaxSpider.status == 'running':
self.logger.debug('AJAX Spider: {0}'.format(self.zap.ajaxSpider.status))
time.sleep(self._status_check_sleep)
self.logger.debug('AJAX Spider completed') | [
"def",
"run_ajax_spider",
"(",
"self",
",",
"target_url",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'AJAX Spidering target {0}...'",
".",
"format",
"(",
"target_url",
")",
")",
"self",
".",
"zap",
".",
"ajaxSpider",
".",
"scan",
"(",
"target_url",... | Run AJAX Spider against a URL. | [
"Run",
"AJAX",
"Spider",
"against",
"a",
"URL",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L192-L202 | train | 202,260 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.alerts | def alerts(self, alert_level='High'):
"""Get a filtered list of alerts at the given alert level, and sorted by alert level."""
alerts = self.zap.core.alerts()
alert_level_value = self.alert_levels[alert_level]
alerts = sorted((a for a in alerts if self.alert_levels[a['risk']] >= alert_level_value),
key=lambda k: self.alert_levels[k['risk']], reverse=True)
return alerts | python | def alerts(self, alert_level='High'):
"""Get a filtered list of alerts at the given alert level, and sorted by alert level."""
alerts = self.zap.core.alerts()
alert_level_value = self.alert_levels[alert_level]
alerts = sorted((a for a in alerts if self.alert_levels[a['risk']] >= alert_level_value),
key=lambda k: self.alert_levels[k['risk']], reverse=True)
return alerts | [
"def",
"alerts",
"(",
"self",
",",
"alert_level",
"=",
"'High'",
")",
":",
"alerts",
"=",
"self",
".",
"zap",
".",
"core",
".",
"alerts",
"(",
")",
"alert_level_value",
"=",
"self",
".",
"alert_levels",
"[",
"alert_level",
"]",
"alerts",
"=",
"sorted",
... | Get a filtered list of alerts at the given alert level, and sorted by alert level. | [
"Get",
"a",
"filtered",
"list",
"of",
"alerts",
"at",
"the",
"given",
"alert",
"level",
"and",
"sorted",
"by",
"alert",
"level",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L204-L212 | train | 202,261 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.enabled_scanner_ids | def enabled_scanner_ids(self):
"""Retrieves a list of currently enabled scanners."""
enabled_scanners = []
scanners = self.zap.ascan.scanners()
for scanner in scanners:
if scanner['enabled'] == 'true':
enabled_scanners.append(scanner['id'])
return enabled_scanners | python | def enabled_scanner_ids(self):
"""Retrieves a list of currently enabled scanners."""
enabled_scanners = []
scanners = self.zap.ascan.scanners()
for scanner in scanners:
if scanner['enabled'] == 'true':
enabled_scanners.append(scanner['id'])
return enabled_scanners | [
"def",
"enabled_scanner_ids",
"(",
"self",
")",
":",
"enabled_scanners",
"=",
"[",
"]",
"scanners",
"=",
"self",
".",
"zap",
".",
"ascan",
".",
"scanners",
"(",
")",
"for",
"scanner",
"in",
"scanners",
":",
"if",
"scanner",
"[",
"'enabled'",
"]",
"==",
... | Retrieves a list of currently enabled scanners. | [
"Retrieves",
"a",
"list",
"of",
"currently",
"enabled",
"scanners",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L214-L223 | train | 202,262 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.enable_scanners_by_ids | def enable_scanners_by_ids(self, scanner_ids):
"""Enable a list of scanner IDs."""
scanner_ids = ','.join(scanner_ids)
self.logger.debug('Enabling scanners with IDs {0}'.format(scanner_ids))
return self.zap.ascan.enable_scanners(scanner_ids) | python | def enable_scanners_by_ids(self, scanner_ids):
"""Enable a list of scanner IDs."""
scanner_ids = ','.join(scanner_ids)
self.logger.debug('Enabling scanners with IDs {0}'.format(scanner_ids))
return self.zap.ascan.enable_scanners(scanner_ids) | [
"def",
"enable_scanners_by_ids",
"(",
"self",
",",
"scanner_ids",
")",
":",
"scanner_ids",
"=",
"','",
".",
"join",
"(",
"scanner_ids",
")",
"self",
".",
"logger",
".",
"debug",
"(",
"'Enabling scanners with IDs {0}'",
".",
"format",
"(",
"scanner_ids",
")",
"... | Enable a list of scanner IDs. | [
"Enable",
"a",
"list",
"of",
"scanner",
"IDs",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L225-L229 | train | 202,263 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.disable_scanners_by_ids | def disable_scanners_by_ids(self, scanner_ids):
"""Disable a list of scanner IDs."""
scanner_ids = ','.join(scanner_ids)
self.logger.debug('Disabling scanners with IDs {0}'.format(scanner_ids))
return self.zap.ascan.disable_scanners(scanner_ids) | python | def disable_scanners_by_ids(self, scanner_ids):
"""Disable a list of scanner IDs."""
scanner_ids = ','.join(scanner_ids)
self.logger.debug('Disabling scanners with IDs {0}'.format(scanner_ids))
return self.zap.ascan.disable_scanners(scanner_ids) | [
"def",
"disable_scanners_by_ids",
"(",
"self",
",",
"scanner_ids",
")",
":",
"scanner_ids",
"=",
"','",
".",
"join",
"(",
"scanner_ids",
")",
"self",
".",
"logger",
".",
"debug",
"(",
"'Disabling scanners with IDs {0}'",
".",
"format",
"(",
"scanner_ids",
")",
... | Disable a list of scanner IDs. | [
"Disable",
"a",
"list",
"of",
"scanner",
"IDs",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L231-L235 | train | 202,264 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.enable_scanners_by_group | def enable_scanners_by_group(self, group):
"""
Enables the scanners in the group if it matches one in the scanner_group_map.
"""
if group == 'all':
self.logger.debug('Enabling all scanners')
return self.zap.ascan.enable_all_scanners()
try:
scanner_list = self.scanner_group_map[group]
except KeyError:
raise ZAPError(
'Invalid group "{0}" provided. Valid groups are: {1}'.format(
group, ', '.join(self.scanner_groups)
)
)
self.logger.debug('Enabling scanner group {0}'.format(group))
return self.enable_scanners_by_ids(scanner_list) | python | def enable_scanners_by_group(self, group):
"""
Enables the scanners in the group if it matches one in the scanner_group_map.
"""
if group == 'all':
self.logger.debug('Enabling all scanners')
return self.zap.ascan.enable_all_scanners()
try:
scanner_list = self.scanner_group_map[group]
except KeyError:
raise ZAPError(
'Invalid group "{0}" provided. Valid groups are: {1}'.format(
group, ', '.join(self.scanner_groups)
)
)
self.logger.debug('Enabling scanner group {0}'.format(group))
return self.enable_scanners_by_ids(scanner_list) | [
"def",
"enable_scanners_by_group",
"(",
"self",
",",
"group",
")",
":",
"if",
"group",
"==",
"'all'",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'Enabling all scanners'",
")",
"return",
"self",
".",
"zap",
".",
"ascan",
".",
"enable_all_scanners",
"(",
... | Enables the scanners in the group if it matches one in the scanner_group_map. | [
"Enables",
"the",
"scanners",
"in",
"the",
"group",
"if",
"it",
"matches",
"one",
"in",
"the",
"scanner_group_map",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L237-L255 | train | 202,265 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.disable_scanners_by_group | def disable_scanners_by_group(self, group):
"""
Disables the scanners in the group if it matches one in the scanner_group_map.
"""
if group == 'all':
self.logger.debug('Disabling all scanners')
return self.zap.ascan.disable_all_scanners()
try:
scanner_list = self.scanner_group_map[group]
except KeyError:
raise ZAPError(
'Invalid group "{0}" provided. Valid groups are: {1}'.format(
group, ', '.join(self.scanner_groups)
)
)
self.logger.debug('Disabling scanner group {0}'.format(group))
return self.disable_scanners_by_ids(scanner_list) | python | def disable_scanners_by_group(self, group):
"""
Disables the scanners in the group if it matches one in the scanner_group_map.
"""
if group == 'all':
self.logger.debug('Disabling all scanners')
return self.zap.ascan.disable_all_scanners()
try:
scanner_list = self.scanner_group_map[group]
except KeyError:
raise ZAPError(
'Invalid group "{0}" provided. Valid groups are: {1}'.format(
group, ', '.join(self.scanner_groups)
)
)
self.logger.debug('Disabling scanner group {0}'.format(group))
return self.disable_scanners_by_ids(scanner_list) | [
"def",
"disable_scanners_by_group",
"(",
"self",
",",
"group",
")",
":",
"if",
"group",
"==",
"'all'",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'Disabling all scanners'",
")",
"return",
"self",
".",
"zap",
".",
"ascan",
".",
"disable_all_scanners",
"(... | Disables the scanners in the group if it matches one in the scanner_group_map. | [
"Disables",
"the",
"scanners",
"in",
"the",
"group",
"if",
"it",
"matches",
"one",
"in",
"the",
"scanner_group_map",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L257-L275 | train | 202,266 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.set_scanner_attack_strength | def set_scanner_attack_strength(self, scanner_ids, attack_strength):
"""Set the attack strength for the given scanners."""
for scanner_id in scanner_ids:
self.logger.debug('Setting strength for scanner {0} to {1}'.format(scanner_id, attack_strength))
result = self.zap.ascan.set_scanner_attack_strength(scanner_id, attack_strength)
if result != 'OK':
raise ZAPError('Error setting strength for scanner with ID {0}: {1}'.format(scanner_id, result)) | python | def set_scanner_attack_strength(self, scanner_ids, attack_strength):
"""Set the attack strength for the given scanners."""
for scanner_id in scanner_ids:
self.logger.debug('Setting strength for scanner {0} to {1}'.format(scanner_id, attack_strength))
result = self.zap.ascan.set_scanner_attack_strength(scanner_id, attack_strength)
if result != 'OK':
raise ZAPError('Error setting strength for scanner with ID {0}: {1}'.format(scanner_id, result)) | [
"def",
"set_scanner_attack_strength",
"(",
"self",
",",
"scanner_ids",
",",
"attack_strength",
")",
":",
"for",
"scanner_id",
"in",
"scanner_ids",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'Setting strength for scanner {0} to {1}'",
".",
"format",
"(",
"scanne... | Set the attack strength for the given scanners. | [
"Set",
"the",
"attack",
"strength",
"for",
"the",
"given",
"scanners",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L317-L323 | train | 202,267 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.enable_policies_by_ids | def enable_policies_by_ids(self, policy_ids):
"""Set enabled policy from a list of IDs."""
policy_ids = ','.join(policy_ids)
self.logger.debug('Setting enabled policies to IDs {0}'.format(policy_ids))
self.zap.ascan.set_enabled_policies(policy_ids) | python | def enable_policies_by_ids(self, policy_ids):
"""Set enabled policy from a list of IDs."""
policy_ids = ','.join(policy_ids)
self.logger.debug('Setting enabled policies to IDs {0}'.format(policy_ids))
self.zap.ascan.set_enabled_policies(policy_ids) | [
"def",
"enable_policies_by_ids",
"(",
"self",
",",
"policy_ids",
")",
":",
"policy_ids",
"=",
"','",
".",
"join",
"(",
"policy_ids",
")",
"self",
".",
"logger",
".",
"debug",
"(",
"'Setting enabled policies to IDs {0}'",
".",
"format",
"(",
"policy_ids",
")",
... | Set enabled policy from a list of IDs. | [
"Set",
"enabled",
"policy",
"from",
"a",
"list",
"of",
"IDs",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L333-L337 | train | 202,268 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.set_policy_attack_strength | def set_policy_attack_strength(self, policy_ids, attack_strength):
"""Set the attack strength for the given policies."""
for policy_id in policy_ids:
self.logger.debug('Setting strength for policy {0} to {1}'.format(policy_id, attack_strength))
result = self.zap.ascan.set_policy_attack_strength(policy_id, attack_strength)
if result != 'OK':
raise ZAPError('Error setting strength for policy with ID {0}: {1}'.format(policy_id, result)) | python | def set_policy_attack_strength(self, policy_ids, attack_strength):
"""Set the attack strength for the given policies."""
for policy_id in policy_ids:
self.logger.debug('Setting strength for policy {0} to {1}'.format(policy_id, attack_strength))
result = self.zap.ascan.set_policy_attack_strength(policy_id, attack_strength)
if result != 'OK':
raise ZAPError('Error setting strength for policy with ID {0}: {1}'.format(policy_id, result)) | [
"def",
"set_policy_attack_strength",
"(",
"self",
",",
"policy_ids",
",",
"attack_strength",
")",
":",
"for",
"policy_id",
"in",
"policy_ids",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'Setting strength for policy {0} to {1}'",
".",
"format",
"(",
"policy_id",... | Set the attack strength for the given policies. | [
"Set",
"the",
"attack",
"strength",
"for",
"the",
"given",
"policies",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L339-L345 | train | 202,269 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.exclude_from_all | def exclude_from_all(self, exclude_regex):
"""Exclude a pattern from proxy, spider and active scanner."""
try:
re.compile(exclude_regex)
except re.error:
raise ZAPError('Invalid regex "{0}" provided'.format(exclude_regex))
self.logger.debug('Excluding {0} from proxy, spider and active scanner.'.format(exclude_regex))
self.zap.core.exclude_from_proxy(exclude_regex)
self.zap.spider.exclude_from_scan(exclude_regex)
self.zap.ascan.exclude_from_scan(exclude_regex) | python | def exclude_from_all(self, exclude_regex):
"""Exclude a pattern from proxy, spider and active scanner."""
try:
re.compile(exclude_regex)
except re.error:
raise ZAPError('Invalid regex "{0}" provided'.format(exclude_regex))
self.logger.debug('Excluding {0} from proxy, spider and active scanner.'.format(exclude_regex))
self.zap.core.exclude_from_proxy(exclude_regex)
self.zap.spider.exclude_from_scan(exclude_regex)
self.zap.ascan.exclude_from_scan(exclude_regex) | [
"def",
"exclude_from_all",
"(",
"self",
",",
"exclude_regex",
")",
":",
"try",
":",
"re",
".",
"compile",
"(",
"exclude_regex",
")",
"except",
"re",
".",
"error",
":",
"raise",
"ZAPError",
"(",
"'Invalid regex \"{0}\" provided'",
".",
"format",
"(",
"exclude_r... | Exclude a pattern from proxy, spider and active scanner. | [
"Exclude",
"a",
"pattern",
"from",
"proxy",
"spider",
"and",
"active",
"scanner",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L355-L366 | train | 202,270 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.xml_report | def xml_report(self, file_path):
"""Generate and save XML report"""
self.logger.debug('Generating XML report')
report = self.zap.core.xmlreport()
self._write_report(report, file_path) | python | def xml_report(self, file_path):
"""Generate and save XML report"""
self.logger.debug('Generating XML report')
report = self.zap.core.xmlreport()
self._write_report(report, file_path) | [
"def",
"xml_report",
"(",
"self",
",",
"file_path",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'Generating XML report'",
")",
"report",
"=",
"self",
".",
"zap",
".",
"core",
".",
"xmlreport",
"(",
")",
"self",
".",
"_write_report",
"(",
"report... | Generate and save XML report | [
"Generate",
"and",
"save",
"XML",
"report"
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L368-L372 | train | 202,271 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.md_report | def md_report(self, file_path):
"""Generate and save MD report"""
self.logger.debug('Generating MD report')
report = self.zap.core.mdreport()
self._write_report(report, file_path) | python | def md_report(self, file_path):
"""Generate and save MD report"""
self.logger.debug('Generating MD report')
report = self.zap.core.mdreport()
self._write_report(report, file_path) | [
"def",
"md_report",
"(",
"self",
",",
"file_path",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'Generating MD report'",
")",
"report",
"=",
"self",
".",
"zap",
".",
"core",
".",
"mdreport",
"(",
")",
"self",
".",
"_write_report",
"(",
"report",
... | Generate and save MD report | [
"Generate",
"and",
"save",
"MD",
"report"
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L374-L378 | train | 202,272 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.html_report | def html_report(self, file_path):
"""Generate and save HTML report."""
self.logger.debug('Generating HTML report')
report = self.zap.core.htmlreport()
self._write_report(report, file_path) | python | def html_report(self, file_path):
"""Generate and save HTML report."""
self.logger.debug('Generating HTML report')
report = self.zap.core.htmlreport()
self._write_report(report, file_path) | [
"def",
"html_report",
"(",
"self",
",",
"file_path",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'Generating HTML report'",
")",
"report",
"=",
"self",
".",
"zap",
".",
"core",
".",
"htmlreport",
"(",
")",
"self",
".",
"_write_report",
"(",
"rep... | Generate and save HTML report. | [
"Generate",
"and",
"save",
"HTML",
"report",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L380-L384 | train | 202,273 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper._write_report | def _write_report(report, file_path):
"""Write report to the given file path."""
with open(file_path, mode='wb') as f:
if not isinstance(report, binary_type):
report = report.encode('utf-8')
f.write(report) | python | def _write_report(report, file_path):
"""Write report to the given file path."""
with open(file_path, mode='wb') as f:
if not isinstance(report, binary_type):
report = report.encode('utf-8')
f.write(report) | [
"def",
"_write_report",
"(",
"report",
",",
"file_path",
")",
":",
"with",
"open",
"(",
"file_path",
",",
"mode",
"=",
"'wb'",
")",
"as",
"f",
":",
"if",
"not",
"isinstance",
"(",
"report",
",",
"binary_type",
")",
":",
"report",
"=",
"report",
".",
... | Write report to the given file path. | [
"Write",
"report",
"to",
"the",
"given",
"file",
"path",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L387-L392 | train | 202,274 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper.get_context_info | def get_context_info(self, context_name):
"""Get the context ID for a given context name."""
context_info = self.zap.context.context(context_name)
if not isinstance(context_info, dict):
raise ZAPError('Context with name "{0}" wasn\'t found'.format(context_name))
return context_info | python | def get_context_info(self, context_name):
"""Get the context ID for a given context name."""
context_info = self.zap.context.context(context_name)
if not isinstance(context_info, dict):
raise ZAPError('Context with name "{0}" wasn\'t found'.format(context_name))
return context_info | [
"def",
"get_context_info",
"(",
"self",
",",
"context_name",
")",
":",
"context_info",
"=",
"self",
".",
"zap",
".",
"context",
".",
"context",
"(",
"context_name",
")",
"if",
"not",
"isinstance",
"(",
"context_info",
",",
"dict",
")",
":",
"raise",
"ZAPEr... | Get the context ID for a given context name. | [
"Get",
"the",
"context",
"ID",
"for",
"a",
"given",
"context",
"name",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L394-L400 | train | 202,275 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper._get_context_and_user_ids | def _get_context_and_user_ids(self, context_name, user_name):
"""Helper to get the context ID and user ID from the given names."""
if context_name is None:
return None, None
context_id = self.get_context_info(context_name)['id']
user_id = None
if user_name:
user_id = self._get_user_id_from_name(context_id, user_name)
return context_id, user_id | python | def _get_context_and_user_ids(self, context_name, user_name):
"""Helper to get the context ID and user ID from the given names."""
if context_name is None:
return None, None
context_id = self.get_context_info(context_name)['id']
user_id = None
if user_name:
user_id = self._get_user_id_from_name(context_id, user_name)
return context_id, user_id | [
"def",
"_get_context_and_user_ids",
"(",
"self",
",",
"context_name",
",",
"user_name",
")",
":",
"if",
"context_name",
"is",
"None",
":",
"return",
"None",
",",
"None",
"context_id",
"=",
"self",
".",
"get_context_info",
"(",
"context_name",
")",
"[",
"'id'",... | Helper to get the context ID and user ID from the given names. | [
"Helper",
"to",
"get",
"the",
"context",
"ID",
"and",
"user",
"ID",
"from",
"the",
"given",
"names",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L402-L412 | train | 202,276 |
Grunny/zap-cli | zapcli/zap_helper.py | ZAPHelper._get_user_id_from_name | def _get_user_id_from_name(self, context_id, user_name):
"""Get a user ID from the user name."""
users = self.zap.users.users_list(context_id)
for user in users:
if user['name'] == user_name:
return user['id']
raise ZAPError('No user with the name "{0}"" was found for context {1}'.format(user_name, context_id)) | python | def _get_user_id_from_name(self, context_id, user_name):
"""Get a user ID from the user name."""
users = self.zap.users.users_list(context_id)
for user in users:
if user['name'] == user_name:
return user['id']
raise ZAPError('No user with the name "{0}"" was found for context {1}'.format(user_name, context_id)) | [
"def",
"_get_user_id_from_name",
"(",
"self",
",",
"context_id",
",",
"user_name",
")",
":",
"users",
"=",
"self",
".",
"zap",
".",
"users",
".",
"users_list",
"(",
"context_id",
")",
"for",
"user",
"in",
"users",
":",
"if",
"user",
"[",
"'name'",
"]",
... | Get a user ID from the user name. | [
"Get",
"a",
"user",
"ID",
"from",
"the",
"user",
"name",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/zap_helper.py#L414-L421 | train | 202,277 |
Grunny/zap-cli | zapcli/commands/scripts.py | list_scripts | def list_scripts(zap_helper):
"""List scripts currently loaded into ZAP."""
scripts = zap_helper.zap.script.list_scripts
output = []
for s in scripts:
if 'enabled' not in s:
s['enabled'] = 'N/A'
output.append([s['name'], s['type'], s['engine'], s['enabled']])
click.echo(tabulate(output, headers=['Name', 'Type', 'Engine', 'Enabled'], tablefmt='grid')) | python | def list_scripts(zap_helper):
"""List scripts currently loaded into ZAP."""
scripts = zap_helper.zap.script.list_scripts
output = []
for s in scripts:
if 'enabled' not in s:
s['enabled'] = 'N/A'
output.append([s['name'], s['type'], s['engine'], s['enabled']])
click.echo(tabulate(output, headers=['Name', 'Type', 'Engine', 'Enabled'], tablefmt='grid')) | [
"def",
"list_scripts",
"(",
"zap_helper",
")",
":",
"scripts",
"=",
"zap_helper",
".",
"zap",
".",
"script",
".",
"list_scripts",
"output",
"=",
"[",
"]",
"for",
"s",
"in",
"scripts",
":",
"if",
"'enabled'",
"not",
"in",
"s",
":",
"s",
"[",
"'enabled'"... | List scripts currently loaded into ZAP. | [
"List",
"scripts",
"currently",
"loaded",
"into",
"ZAP",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/scripts.py#L29-L39 | train | 202,278 |
Grunny/zap-cli | zapcli/commands/scripts.py | list_engines | def list_engines(zap_helper):
"""List engines that can be used to run scripts."""
engines = zap_helper.zap.script.list_engines
console.info('Available engines: {}'.format(', '.join(engines))) | python | def list_engines(zap_helper):
"""List engines that can be used to run scripts."""
engines = zap_helper.zap.script.list_engines
console.info('Available engines: {}'.format(', '.join(engines))) | [
"def",
"list_engines",
"(",
"zap_helper",
")",
":",
"engines",
"=",
"zap_helper",
".",
"zap",
".",
"script",
".",
"list_engines",
"console",
".",
"info",
"(",
"'Available engines: {}'",
".",
"format",
"(",
"', '",
".",
"join",
"(",
"engines",
")",
")",
")"... | List engines that can be used to run scripts. | [
"List",
"engines",
"that",
"can",
"be",
"used",
"to",
"run",
"scripts",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/scripts.py#L44-L47 | train | 202,279 |
Grunny/zap-cli | zapcli/commands/scripts.py | enable_script | def enable_script(zap_helper, script_name):
"""Enable a script."""
with zap_error_handler():
console.debug('Enabling script "{0}"'.format(script_name))
result = zap_helper.zap.script.enable(script_name)
if result != 'OK':
raise ZAPError('Error enabling script: {0}'.format(result))
console.info('Script "{0}" enabled'.format(script_name)) | python | def enable_script(zap_helper, script_name):
"""Enable a script."""
with zap_error_handler():
console.debug('Enabling script "{0}"'.format(script_name))
result = zap_helper.zap.script.enable(script_name)
if result != 'OK':
raise ZAPError('Error enabling script: {0}'.format(result))
console.info('Script "{0}" enabled'.format(script_name)) | [
"def",
"enable_script",
"(",
"zap_helper",
",",
"script_name",
")",
":",
"with",
"zap_error_handler",
"(",
")",
":",
"console",
".",
"debug",
"(",
"'Enabling script \"{0}\"'",
".",
"format",
"(",
"script_name",
")",
")",
"result",
"=",
"zap_helper",
".",
"zap"... | Enable a script. | [
"Enable",
"a",
"script",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/scripts.py#L53-L62 | train | 202,280 |
Grunny/zap-cli | zapcli/commands/scripts.py | disable_script | def disable_script(zap_helper, script_name):
"""Disable a script."""
with zap_error_handler():
console.debug('Disabling script "{0}"'.format(script_name))
result = zap_helper.zap.script.disable(script_name)
if result != 'OK':
raise ZAPError('Error disabling script: {0}'.format(result))
console.info('Script "{0}" disabled'.format(script_name)) | python | def disable_script(zap_helper, script_name):
"""Disable a script."""
with zap_error_handler():
console.debug('Disabling script "{0}"'.format(script_name))
result = zap_helper.zap.script.disable(script_name)
if result != 'OK':
raise ZAPError('Error disabling script: {0}'.format(result))
console.info('Script "{0}" disabled'.format(script_name)) | [
"def",
"disable_script",
"(",
"zap_helper",
",",
"script_name",
")",
":",
"with",
"zap_error_handler",
"(",
")",
":",
"console",
".",
"debug",
"(",
"'Disabling script \"{0}\"'",
".",
"format",
"(",
"script_name",
")",
")",
"result",
"=",
"zap_helper",
".",
"za... | Disable a script. | [
"Disable",
"a",
"script",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/scripts.py#L68-L77 | train | 202,281 |
Grunny/zap-cli | zapcli/commands/scripts.py | remove_script | def remove_script(zap_helper, script_name):
"""Remove a script."""
with zap_error_handler():
console.debug('Removing script "{0}"'.format(script_name))
result = zap_helper.zap.script.remove(script_name)
if result != 'OK':
raise ZAPError('Error removing script: {0}'.format(result))
console.info('Script "{0}" removed'.format(script_name)) | python | def remove_script(zap_helper, script_name):
"""Remove a script."""
with zap_error_handler():
console.debug('Removing script "{0}"'.format(script_name))
result = zap_helper.zap.script.remove(script_name)
if result != 'OK':
raise ZAPError('Error removing script: {0}'.format(result))
console.info('Script "{0}" removed'.format(script_name)) | [
"def",
"remove_script",
"(",
"zap_helper",
",",
"script_name",
")",
":",
"with",
"zap_error_handler",
"(",
")",
":",
"console",
".",
"debug",
"(",
"'Removing script \"{0}\"'",
".",
"format",
"(",
"script_name",
")",
")",
"result",
"=",
"zap_helper",
".",
"zap"... | Remove a script. | [
"Remove",
"a",
"script",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/scripts.py#L83-L92 | train | 202,282 |
Grunny/zap-cli | zapcli/commands/scripts.py | load_script | def load_script(zap_helper, **options):
"""Load a script from a file."""
with zap_error_handler():
if not os.path.isfile(options['file_path']):
raise ZAPError('No file found at "{0}", cannot load script.'.format(options['file_path']))
if not _is_valid_script_engine(zap_helper.zap, options['engine']):
engines = zap_helper.zap.script.list_engines
raise ZAPError('Invalid script engine provided. Valid engines are: {0}'.format(', '.join(engines)))
console.debug('Loading script "{0}" from "{1}"'.format(options['name'], options['file_path']))
result = zap_helper.zap.script.load(options['name'], options['script_type'], options['engine'],
options['file_path'], scriptdescription=options['description'])
if result != 'OK':
raise ZAPError('Error loading script: {0}'.format(result))
console.info('Script "{0}" loaded'.format(options['name'])) | python | def load_script(zap_helper, **options):
"""Load a script from a file."""
with zap_error_handler():
if not os.path.isfile(options['file_path']):
raise ZAPError('No file found at "{0}", cannot load script.'.format(options['file_path']))
if not _is_valid_script_engine(zap_helper.zap, options['engine']):
engines = zap_helper.zap.script.list_engines
raise ZAPError('Invalid script engine provided. Valid engines are: {0}'.format(', '.join(engines)))
console.debug('Loading script "{0}" from "{1}"'.format(options['name'], options['file_path']))
result = zap_helper.zap.script.load(options['name'], options['script_type'], options['engine'],
options['file_path'], scriptdescription=options['description'])
if result != 'OK':
raise ZAPError('Error loading script: {0}'.format(result))
console.info('Script "{0}" loaded'.format(options['name'])) | [
"def",
"load_script",
"(",
"zap_helper",
",",
"*",
"*",
"options",
")",
":",
"with",
"zap_error_handler",
"(",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"options",
"[",
"'file_path'",
"]",
")",
":",
"raise",
"ZAPError",
"(",
"'No fi... | Load a script from a file. | [
"Load",
"a",
"script",
"from",
"a",
"file",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/scripts.py#L102-L119 | train | 202,283 |
Grunny/zap-cli | zapcli/commands/scripts.py | _is_valid_script_engine | def _is_valid_script_engine(zap, engine):
"""Check if given script engine is valid."""
engine_names = zap.script.list_engines
short_names = [e.split(' : ')[1] for e in engine_names]
return engine in engine_names or engine in short_names | python | def _is_valid_script_engine(zap, engine):
"""Check if given script engine is valid."""
engine_names = zap.script.list_engines
short_names = [e.split(' : ')[1] for e in engine_names]
return engine in engine_names or engine in short_names | [
"def",
"_is_valid_script_engine",
"(",
"zap",
",",
"engine",
")",
":",
"engine_names",
"=",
"zap",
".",
"script",
".",
"list_engines",
"short_names",
"=",
"[",
"e",
".",
"split",
"(",
"' : '",
")",
"[",
"1",
"]",
"for",
"e",
"in",
"engine_names",
"]",
... | Check if given script engine is valid. | [
"Check",
"if",
"given",
"script",
"engine",
"is",
"valid",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/scripts.py#L122-L127 | train | 202,284 |
Grunny/zap-cli | zapcli/cli.py | start_zap_daemon | def start_zap_daemon(zap_helper, start_options):
"""Helper to start the daemon using the current config."""
console.info('Starting ZAP daemon')
with helpers.zap_error_handler():
zap_helper.start(options=start_options) | python | def start_zap_daemon(zap_helper, start_options):
"""Helper to start the daemon using the current config."""
console.info('Starting ZAP daemon')
with helpers.zap_error_handler():
zap_helper.start(options=start_options) | [
"def",
"start_zap_daemon",
"(",
"zap_helper",
",",
"start_options",
")",
":",
"console",
".",
"info",
"(",
"'Starting ZAP daemon'",
")",
"with",
"helpers",
".",
"zap_error_handler",
"(",
")",
":",
"zap_helper",
".",
"start",
"(",
"options",
"=",
"start_options",... | Helper to start the daemon using the current config. | [
"Helper",
"to",
"start",
"the",
"daemon",
"using",
"the",
"current",
"config",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/cli.py#L54-L58 | train | 202,285 |
Grunny/zap-cli | zapcli/cli.py | check_status | def check_status(zap_helper, timeout):
"""
Check if ZAP is running and able to receive API calls.
You can provide a timeout option which is the amount of time in seconds
the command should wait for ZAP to start if it is not currently running.
This is useful to run before calling other commands if ZAP was started
outside of zap-cli. For example:
zap-cli status -t 60 && zap-cli open-url "http://127.0.0.1/"
Exits with code 1 if ZAP is either not running or the command timed out
waiting for ZAP to start.
"""
with helpers.zap_error_handler():
if zap_helper.is_running():
console.info('ZAP is running')
elif timeout is not None:
zap_helper.wait_for_zap(timeout)
console.info('ZAP is running')
else:
console.error('ZAP is not running')
sys.exit(2) | python | def check_status(zap_helper, timeout):
"""
Check if ZAP is running and able to receive API calls.
You can provide a timeout option which is the amount of time in seconds
the command should wait for ZAP to start if it is not currently running.
This is useful to run before calling other commands if ZAP was started
outside of zap-cli. For example:
zap-cli status -t 60 && zap-cli open-url "http://127.0.0.1/"
Exits with code 1 if ZAP is either not running or the command timed out
waiting for ZAP to start.
"""
with helpers.zap_error_handler():
if zap_helper.is_running():
console.info('ZAP is running')
elif timeout is not None:
zap_helper.wait_for_zap(timeout)
console.info('ZAP is running')
else:
console.error('ZAP is not running')
sys.exit(2) | [
"def",
"check_status",
"(",
"zap_helper",
",",
"timeout",
")",
":",
"with",
"helpers",
".",
"zap_error_handler",
"(",
")",
":",
"if",
"zap_helper",
".",
"is_running",
"(",
")",
":",
"console",
".",
"info",
"(",
"'ZAP is running'",
")",
"elif",
"timeout",
"... | Check if ZAP is running and able to receive API calls.
You can provide a timeout option which is the amount of time in seconds
the command should wait for ZAP to start if it is not currently running.
This is useful to run before calling other commands if ZAP was started
outside of zap-cli. For example:
zap-cli status -t 60 && zap-cli open-url "http://127.0.0.1/"
Exits with code 1 if ZAP is either not running or the command timed out
waiting for ZAP to start. | [
"Check",
"if",
"ZAP",
"is",
"running",
"and",
"able",
"to",
"receive",
"API",
"calls",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/cli.py#L74-L96 | train | 202,286 |
Grunny/zap-cli | zapcli/cli.py | open_url | def open_url(zap_helper, url):
"""Open a URL using the ZAP proxy."""
console.info('Accessing URL {0}'.format(url))
zap_helper.open_url(url) | python | def open_url(zap_helper, url):
"""Open a URL using the ZAP proxy."""
console.info('Accessing URL {0}'.format(url))
zap_helper.open_url(url) | [
"def",
"open_url",
"(",
"zap_helper",
",",
"url",
")",
":",
"console",
".",
"info",
"(",
"'Accessing URL {0}'",
".",
"format",
"(",
"url",
")",
")",
"zap_helper",
".",
"open_url",
"(",
"url",
")"
] | Open a URL using the ZAP proxy. | [
"Open",
"a",
"URL",
"using",
"the",
"ZAP",
"proxy",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/cli.py#L102-L105 | train | 202,287 |
Grunny/zap-cli | zapcli/cli.py | spider_url | def spider_url(zap_helper, url, context_name, user_name):
"""Run the spider against a URL."""
console.info('Running spider...')
with helpers.zap_error_handler():
zap_helper.run_spider(url, context_name, user_name) | python | def spider_url(zap_helper, url, context_name, user_name):
"""Run the spider against a URL."""
console.info('Running spider...')
with helpers.zap_error_handler():
zap_helper.run_spider(url, context_name, user_name) | [
"def",
"spider_url",
"(",
"zap_helper",
",",
"url",
",",
"context_name",
",",
"user_name",
")",
":",
"console",
".",
"info",
"(",
"'Running spider...'",
")",
"with",
"helpers",
".",
"zap_error_handler",
"(",
")",
":",
"zap_helper",
".",
"run_spider",
"(",
"u... | Run the spider against a URL. | [
"Run",
"the",
"spider",
"against",
"a",
"URL",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/cli.py#L115-L119 | train | 202,288 |
Grunny/zap-cli | zapcli/cli.py | active_scan | def active_scan(zap_helper, url, scanners, recursive, context_name, user_name):
"""
Run an Active Scan against a URL.
The URL to be scanned must be in ZAP's site tree, i.e. it should have already
been opened using the open-url command or found by running the spider command.
"""
console.info('Running an active scan...')
with helpers.zap_error_handler():
if scanners:
zap_helper.set_enabled_scanners(scanners)
zap_helper.run_active_scan(url, recursive, context_name, user_name) | python | def active_scan(zap_helper, url, scanners, recursive, context_name, user_name):
"""
Run an Active Scan against a URL.
The URL to be scanned must be in ZAP's site tree, i.e. it should have already
been opened using the open-url command or found by running the spider command.
"""
console.info('Running an active scan...')
with helpers.zap_error_handler():
if scanners:
zap_helper.set_enabled_scanners(scanners)
zap_helper.run_active_scan(url, recursive, context_name, user_name) | [
"def",
"active_scan",
"(",
"zap_helper",
",",
"url",
",",
"scanners",
",",
"recursive",
",",
"context_name",
",",
"user_name",
")",
":",
"console",
".",
"info",
"(",
"'Running an active scan...'",
")",
"with",
"helpers",
".",
"zap_error_handler",
"(",
")",
":"... | Run an Active Scan against a URL.
The URL to be scanned must be in ZAP's site tree, i.e. it should have already
been opened using the open-url command or found by running the spider command. | [
"Run",
"an",
"Active",
"Scan",
"against",
"a",
"URL",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/cli.py#L143-L156 | train | 202,289 |
Grunny/zap-cli | zapcli/cli.py | show_alerts | def show_alerts(zap_helper, alert_level, output_format, exit_code):
"""Show alerts at the given alert level."""
alerts = zap_helper.alerts(alert_level)
helpers.report_alerts(alerts, output_format)
if exit_code:
code = 1 if len(alerts) > 0 else 0
sys.exit(code) | python | def show_alerts(zap_helper, alert_level, output_format, exit_code):
"""Show alerts at the given alert level."""
alerts = zap_helper.alerts(alert_level)
helpers.report_alerts(alerts, output_format)
if exit_code:
code = 1 if len(alerts) > 0 else 0
sys.exit(code) | [
"def",
"show_alerts",
"(",
"zap_helper",
",",
"alert_level",
",",
"output_format",
",",
"exit_code",
")",
":",
"alerts",
"=",
"zap_helper",
".",
"alerts",
"(",
"alert_level",
")",
"helpers",
".",
"report_alerts",
"(",
"alerts",
",",
"output_format",
")",
"if",... | Show alerts at the given alert level. | [
"Show",
"alerts",
"at",
"the",
"given",
"alert",
"level",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/cli.py#L168-L176 | train | 202,290 |
Grunny/zap-cli | zapcli/cli.py | quick_scan | def quick_scan(zap_helper, url, **options):
"""
Run a quick scan of a site by opening a URL, optionally spidering the URL,
running an Active Scan, and reporting any issues found.
This command contains most scan options as parameters, so you can do
everything in one go.
If any alerts are found for the given alert level, this command will exit
with a status code of 1.
"""
if options['self_contained']:
console.info('Starting ZAP daemon')
with helpers.zap_error_handler():
zap_helper.start(options['start_options'])
console.info('Running a quick scan for {0}'.format(url))
with helpers.zap_error_handler():
if options['scanners']:
zap_helper.set_enabled_scanners(options['scanners'])
if options['exclude']:
zap_helper.exclude_from_all(options['exclude'])
zap_helper.open_url(url)
if options['spider']:
zap_helper.run_spider(url, options['context_name'], options['user_name'])
if options['ajax_spider']:
zap_helper.run_ajax_spider(url)
zap_helper.run_active_scan(url, options['recursive'], options['context_name'], options['user_name'])
alerts = zap_helper.alerts(options['alert_level'])
helpers.report_alerts(alerts, options['output_format'])
if options['self_contained']:
console.info('Shutting down ZAP daemon')
with helpers.zap_error_handler():
zap_helper.shutdown()
exit_code = 1 if len(alerts) > 0 else 0
sys.exit(exit_code) | python | def quick_scan(zap_helper, url, **options):
"""
Run a quick scan of a site by opening a URL, optionally spidering the URL,
running an Active Scan, and reporting any issues found.
This command contains most scan options as parameters, so you can do
everything in one go.
If any alerts are found for the given alert level, this command will exit
with a status code of 1.
"""
if options['self_contained']:
console.info('Starting ZAP daemon')
with helpers.zap_error_handler():
zap_helper.start(options['start_options'])
console.info('Running a quick scan for {0}'.format(url))
with helpers.zap_error_handler():
if options['scanners']:
zap_helper.set_enabled_scanners(options['scanners'])
if options['exclude']:
zap_helper.exclude_from_all(options['exclude'])
zap_helper.open_url(url)
if options['spider']:
zap_helper.run_spider(url, options['context_name'], options['user_name'])
if options['ajax_spider']:
zap_helper.run_ajax_spider(url)
zap_helper.run_active_scan(url, options['recursive'], options['context_name'], options['user_name'])
alerts = zap_helper.alerts(options['alert_level'])
helpers.report_alerts(alerts, options['output_format'])
if options['self_contained']:
console.info('Shutting down ZAP daemon')
with helpers.zap_error_handler():
zap_helper.shutdown()
exit_code = 1 if len(alerts) > 0 else 0
sys.exit(exit_code) | [
"def",
"quick_scan",
"(",
"zap_helper",
",",
"url",
",",
"*",
"*",
"options",
")",
":",
"if",
"options",
"[",
"'self_contained'",
"]",
":",
"console",
".",
"info",
"(",
"'Starting ZAP daemon'",
")",
"with",
"helpers",
".",
"zap_error_handler",
"(",
")",
":... | Run a quick scan of a site by opening a URL, optionally spidering the URL,
running an Active Scan, and reporting any issues found.
This command contains most scan options as parameters, so you can do
everything in one go.
If any alerts are found for the given alert level, this command will exit
with a status code of 1. | [
"Run",
"a",
"quick",
"scan",
"of",
"a",
"site",
"by",
"opening",
"a",
"URL",
"optionally",
"spidering",
"the",
"URL",
"running",
"an",
"Active",
"Scan",
"and",
"reporting",
"any",
"issues",
"found",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/cli.py#L205-L250 | train | 202,291 |
Grunny/zap-cli | zapcli/cli.py | report | def report(zap_helper, output, output_format):
"""Generate XML, MD or HTML report."""
if output_format == 'html':
zap_helper.html_report(output)
elif output_format == 'md':
zap_helper.md_report(output)
else:
zap_helper.xml_report(output)
console.info('Report saved to "{0}"'.format(output)) | python | def report(zap_helper, output, output_format):
"""Generate XML, MD or HTML report."""
if output_format == 'html':
zap_helper.html_report(output)
elif output_format == 'md':
zap_helper.md_report(output)
else:
zap_helper.xml_report(output)
console.info('Report saved to "{0}"'.format(output)) | [
"def",
"report",
"(",
"zap_helper",
",",
"output",
",",
"output_format",
")",
":",
"if",
"output_format",
"==",
"'html'",
":",
"zap_helper",
".",
"html_report",
"(",
"output",
")",
"elif",
"output_format",
"==",
"'md'",
":",
"zap_helper",
".",
"md_report",
"... | Generate XML, MD or HTML report. | [
"Generate",
"XML",
"MD",
"or",
"HTML",
"report",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/cli.py#L267-L276 | train | 202,292 |
Grunny/zap-cli | zapcli/helpers.py | validate_ids | def validate_ids(ctx, param, value):
"""Validate a list of IDs and convert them to a list."""
if not value:
return None
ids = [x.strip() for x in value.split(',')]
for id_item in ids:
if not id_item.isdigit():
raise click.BadParameter('Non-numeric value "{0}" provided for an ID.'.format(id_item))
return ids | python | def validate_ids(ctx, param, value):
"""Validate a list of IDs and convert them to a list."""
if not value:
return None
ids = [x.strip() for x in value.split(',')]
for id_item in ids:
if not id_item.isdigit():
raise click.BadParameter('Non-numeric value "{0}" provided for an ID.'.format(id_item))
return ids | [
"def",
"validate_ids",
"(",
"ctx",
",",
"param",
",",
"value",
")",
":",
"if",
"not",
"value",
":",
"return",
"None",
"ids",
"=",
"[",
"x",
".",
"strip",
"(",
")",
"for",
"x",
"in",
"value",
".",
"split",
"(",
"','",
")",
"]",
"for",
"id_item",
... | Validate a list of IDs and convert them to a list. | [
"Validate",
"a",
"list",
"of",
"IDs",
"and",
"convert",
"them",
"to",
"a",
"list",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/helpers.py#L19-L29 | train | 202,293 |
Grunny/zap-cli | zapcli/helpers.py | validate_scanner_list | def validate_scanner_list(ctx, param, value):
"""
Validate a comma-separated list of scanners and extract it into a list of groups and IDs.
"""
if not value:
return None
valid_groups = ctx.obj.scanner_groups
scanners = [x.strip() for x in value.split(',')]
if 'all' in scanners:
return ['all']
scanner_ids = []
for scanner in scanners:
if scanner.isdigit():
scanner_ids.append(scanner)
elif scanner in valid_groups:
scanner_ids += ctx.obj.scanner_group_map[scanner]
else:
raise click.BadParameter('Invalid scanner "{0}" provided. Must be a valid group or numeric ID.'
.format(scanner))
return scanner_ids | python | def validate_scanner_list(ctx, param, value):
"""
Validate a comma-separated list of scanners and extract it into a list of groups and IDs.
"""
if not value:
return None
valid_groups = ctx.obj.scanner_groups
scanners = [x.strip() for x in value.split(',')]
if 'all' in scanners:
return ['all']
scanner_ids = []
for scanner in scanners:
if scanner.isdigit():
scanner_ids.append(scanner)
elif scanner in valid_groups:
scanner_ids += ctx.obj.scanner_group_map[scanner]
else:
raise click.BadParameter('Invalid scanner "{0}" provided. Must be a valid group or numeric ID.'
.format(scanner))
return scanner_ids | [
"def",
"validate_scanner_list",
"(",
"ctx",
",",
"param",
",",
"value",
")",
":",
"if",
"not",
"value",
":",
"return",
"None",
"valid_groups",
"=",
"ctx",
".",
"obj",
".",
"scanner_groups",
"scanners",
"=",
"[",
"x",
".",
"strip",
"(",
")",
"for",
"x",... | Validate a comma-separated list of scanners and extract it into a list of groups and IDs. | [
"Validate",
"a",
"comma",
"-",
"separated",
"list",
"of",
"scanners",
"and",
"extract",
"it",
"into",
"a",
"list",
"of",
"groups",
"and",
"IDs",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/helpers.py#L32-L55 | train | 202,294 |
Grunny/zap-cli | zapcli/helpers.py | validate_regex | def validate_regex(ctx, param, value):
"""
Validate that a provided regex compiles.
"""
if not value:
return None
try:
re.compile(value)
except re.error:
raise click.BadParameter('Invalid regex "{0}" provided'.format(value))
return value | python | def validate_regex(ctx, param, value):
"""
Validate that a provided regex compiles.
"""
if not value:
return None
try:
re.compile(value)
except re.error:
raise click.BadParameter('Invalid regex "{0}" provided'.format(value))
return value | [
"def",
"validate_regex",
"(",
"ctx",
",",
"param",
",",
"value",
")",
":",
"if",
"not",
"value",
":",
"return",
"None",
"try",
":",
"re",
".",
"compile",
"(",
"value",
")",
"except",
"re",
".",
"error",
":",
"raise",
"click",
".",
"BadParameter",
"("... | Validate that a provided regex compiles. | [
"Validate",
"that",
"a",
"provided",
"regex",
"compiles",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/helpers.py#L58-L70 | train | 202,295 |
Grunny/zap-cli | zapcli/helpers.py | report_alerts | def report_alerts(alerts, output_format='table'):
"""
Print our alerts in the given format.
"""
num_alerts = len(alerts)
if output_format == 'json':
click.echo(json.dumps(alerts, indent=4))
else:
console.info('Issues found: {0}'.format(num_alerts))
if num_alerts > 0:
click.echo(tabulate([[a['alert'], a['risk'], a['cweid'], a['url']] for a in alerts],
headers=['Alert', 'Risk', 'CWE ID', 'URL'], tablefmt='grid')) | python | def report_alerts(alerts, output_format='table'):
"""
Print our alerts in the given format.
"""
num_alerts = len(alerts)
if output_format == 'json':
click.echo(json.dumps(alerts, indent=4))
else:
console.info('Issues found: {0}'.format(num_alerts))
if num_alerts > 0:
click.echo(tabulate([[a['alert'], a['risk'], a['cweid'], a['url']] for a in alerts],
headers=['Alert', 'Risk', 'CWE ID', 'URL'], tablefmt='grid')) | [
"def",
"report_alerts",
"(",
"alerts",
",",
"output_format",
"=",
"'table'",
")",
":",
"num_alerts",
"=",
"len",
"(",
"alerts",
")",
"if",
"output_format",
"==",
"'json'",
":",
"click",
".",
"echo",
"(",
"json",
".",
"dumps",
"(",
"alerts",
",",
"indent"... | Print our alerts in the given format. | [
"Print",
"our",
"alerts",
"in",
"the",
"given",
"format",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/helpers.py#L83-L95 | train | 202,296 |
Grunny/zap-cli | zapcli/helpers.py | filter_by_ids | def filter_by_ids(original_list, ids_to_filter):
"""Filter a list of dicts by IDs using an id key on each dict."""
if not ids_to_filter:
return original_list
return [i for i in original_list if i['id'] in ids_to_filter] | python | def filter_by_ids(original_list, ids_to_filter):
"""Filter a list of dicts by IDs using an id key on each dict."""
if not ids_to_filter:
return original_list
return [i for i in original_list if i['id'] in ids_to_filter] | [
"def",
"filter_by_ids",
"(",
"original_list",
",",
"ids_to_filter",
")",
":",
"if",
"not",
"ids_to_filter",
":",
"return",
"original_list",
"return",
"[",
"i",
"for",
"i",
"in",
"original_list",
"if",
"i",
"[",
"'id'",
"]",
"in",
"ids_to_filter",
"]"
] | Filter a list of dicts by IDs using an id key on each dict. | [
"Filter",
"a",
"list",
"of",
"dicts",
"by",
"IDs",
"using",
"an",
"id",
"key",
"on",
"each",
"dict",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/helpers.py#L98-L103 | train | 202,297 |
Grunny/zap-cli | zapcli/commands/session.py | save_session | def save_session(zap_helper, file_path):
"""Save the session."""
console.debug('Saving the session to "{0}"'.format(file_path))
zap_helper.zap.core.save_session(file_path, overwrite='true') | python | def save_session(zap_helper, file_path):
"""Save the session."""
console.debug('Saving the session to "{0}"'.format(file_path))
zap_helper.zap.core.save_session(file_path, overwrite='true') | [
"def",
"save_session",
"(",
"zap_helper",
",",
"file_path",
")",
":",
"console",
".",
"debug",
"(",
"'Saving the session to \"{0}\"'",
".",
"format",
"(",
"file_path",
")",
")",
"zap_helper",
".",
"zap",
".",
"core",
".",
"save_session",
"(",
"file_path",
",",... | Save the session. | [
"Save",
"the",
"session",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/session.py#L34-L37 | train | 202,298 |
Grunny/zap-cli | zapcli/commands/session.py | load_session | def load_session(zap_helper, file_path):
"""Load a given session."""
with zap_error_handler():
if not os.path.isfile(file_path):
raise ZAPError('No file found at "{0}", cannot load session.'.format(file_path))
console.debug('Loading session from "{0}"'.format(file_path))
zap_helper.zap.core.load_session(file_path) | python | def load_session(zap_helper, file_path):
"""Load a given session."""
with zap_error_handler():
if not os.path.isfile(file_path):
raise ZAPError('No file found at "{0}", cannot load session.'.format(file_path))
console.debug('Loading session from "{0}"'.format(file_path))
zap_helper.zap.core.load_session(file_path) | [
"def",
"load_session",
"(",
"zap_helper",
",",
"file_path",
")",
":",
"with",
"zap_error_handler",
"(",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"file_path",
")",
":",
"raise",
"ZAPError",
"(",
"'No file found at \"{0}\", cannot load session... | Load a given session. | [
"Load",
"a",
"given",
"session",
"."
] | d58d4850ecfc5467badfac5e5bcc841d064bd419 | https://github.com/Grunny/zap-cli/blob/d58d4850ecfc5467badfac5e5bcc841d064bd419/zapcli/commands/session.py#L43-L49 | train | 202,299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.