Best Python code snippet using slash
wsman.py
Source:wsman.py
...194 """Payload generation for WSMan requests."""195 def build(self):196 request = self._create_envelope()197 self._add_header(request)198 self._add_body(request)199 return ElementTree.tostring(request)200 def _create_envelope(self):201 return ElementTree.Element('{%s}Envelope' % NS_SOAP_ENV, nsmap=NS_MAP)202 def _add_header(self, envelope):203 header = ElementTree.SubElement(envelope, '{%s}Header' % NS_SOAP_ENV)204 qn_must_understand = ElementTree.QName(NS_SOAP_ENV, 'mustUnderstand')205 to_elem = ElementTree.SubElement(header, '{%s}To' % NS_WS_ADDR)206 to_elem.set(qn_must_understand, 'true')207 to_elem.text = self.endpoint208 resource_elem = ElementTree.SubElement(header,209 '{%s}ResourceURI' % NS_WSMAN)210 resource_elem.set(qn_must_understand, 'true')211 resource_elem.text = self.resource_uri212 msg_id_elem = ElementTree.SubElement(header,213 '{%s}MessageID' % NS_WS_ADDR)214 msg_id_elem.set(qn_must_understand, 'true')215 msg_id_elem.text = 'uuid:%s' % uuid.uuid4()216 reply_to_elem = ElementTree.SubElement(header,217 '{%s}ReplyTo' % NS_WS_ADDR)218 reply_to_addr_elem = ElementTree.SubElement(reply_to_elem,219 '{%s}Address' % NS_WS_ADDR)220 reply_to_addr_elem.text = NS_WS_ADDR_ANONYM_ROLE221 return header222 def _add_body(self, envelope):223 return ElementTree.SubElement(envelope, '{%s}Body' % NS_SOAP_ENV)224class _EnumeratePayload(_Payload):225 """Payload generation for WSMan enumerate operation."""226 def __init__(self, endpoint, resource_uri, optimization=True,227 max_elems=100, filter_query=None, filter_dialect=None):228 self.endpoint = endpoint229 self.resource_uri = resource_uri230 self.filter_dialect = None231 self.filter_query = None232 self.optimization = optimization233 self.max_elems = max_elems234 if filter_query is not None:235 try:236 self.filter_dialect = FILTER_DIALECT_MAP[filter_dialect]237 except KeyError:238 valid_opts = ', '.join(FILTER_DIALECT_MAP)239 raise exceptions.WSManInvalidFilterDialect(240 invalid_filter=filter_dialect, supported=valid_opts)241 self.filter_query = filter_query242 def _add_header(self, envelope):243 header = super(_EnumeratePayload, self)._add_header(envelope)244 action_elem = ElementTree.SubElement(header, '{%s}Action' % NS_WS_ADDR)245 action_elem.set('{%s}mustUnderstand' % NS_SOAP_ENV, 'true')246 action_elem.text = NS_WSMAN_ENUM + '/Enumerate'247 return header248 def _add_body(self, envelope):249 body = super(_EnumeratePayload, self)._add_body(envelope)250 enum_elem = ElementTree.SubElement(body,251 '{%s}Enumerate' % NS_WSMAN_ENUM,252 nsmap={'wsen': NS_WSMAN_ENUM})253 if self.filter_query is not None:254 self._add_filter(enum_elem)255 if self.optimization:256 self._add_enum_optimization(enum_elem)257 return body258 def _add_enum_optimization(self, enum_elem):259 ElementTree.SubElement(enum_elem,260 '{%s}OptimizeEnumeration' % NS_WSMAN)261 max_elem_elem = ElementTree.SubElement(enum_elem,262 '{%s}MaxElements' % NS_WSMAN)263 max_elem_elem.text = str(self.max_elems)264 def _add_filter(self, enum_elem):265 filter_elem = ElementTree.SubElement(enum_elem,266 '{%s}Filter' % NS_WSMAN)267 filter_elem.set('Dialect', self.filter_dialect)268 filter_elem.text = self.filter_query269class _PullPayload(_Payload):270 """Payload generation for WSMan pull operation."""271 def __init__(self, endpoint, resource_uri, context, max_elems=100):272 self.endpoint = endpoint273 self.resource_uri = resource_uri274 self.context = context275 self.max_elems = max_elems276 def _add_header(self, envelope):277 header = super(_PullPayload, self)._add_header(envelope)278 action_elem = ElementTree.SubElement(header, '{%s}Action' % NS_WS_ADDR)279 action_elem.set('{%s}mustUnderstand' % NS_SOAP_ENV, 'true')280 action_elem.text = NS_WSMAN_ENUM + '/Pull'281 return header282 def _add_body(self, envelope):283 body = super(_PullPayload, self)._add_body(envelope)284 pull_elem = ElementTree.SubElement(body,285 '{%s}Pull' % NS_WSMAN_ENUM,286 nsmap={'wsen': NS_WSMAN_ENUM})287 enum_context_elem = ElementTree.SubElement(288 pull_elem, '{%s}EnumerationContext' % NS_WSMAN_ENUM)289 enum_context_elem.text = self.context290 self._add_enum_optimization(pull_elem)291 return body292 def _add_enum_optimization(self, pull_elem):293 max_elem_elem = ElementTree.SubElement(pull_elem,294 '{%s}MaxElements' % NS_WSMAN)295 max_elem_elem.text = str(self.max_elems)296class _InvokePayload(_Payload):297 """Payload generation for WSMan invoke operation."""298 def __init__(self, endpoint, resource_uri, method, selectors=None,299 properties=None):300 self.endpoint = endpoint301 self.resource_uri = resource_uri302 self.method = method303 self.selectors = selectors304 self.properties = properties305 def _add_header(self, envelope):306 header = super(_InvokePayload, self)._add_header(envelope)307 action_elem = ElementTree.SubElement(header, '{%s}Action' % NS_WS_ADDR)308 action_elem.set('{%s}mustUnderstand' % NS_SOAP_ENV, 'true')309 action_elem.text = ('%(resource_uri)s/%(method)s' %310 {'resource_uri': self.resource_uri,311 'method': self.method})312 self._add_selectors(header)313 return header314 def _add_body(self, envelope):315 body = super(_InvokePayload, self)._add_body(envelope)316 self._add_properties(body)317 return body318 def _add_selectors(self, header):319 selector_set_elem = ElementTree.SubElement(320 header, '{%s}SelectorSet' % NS_WSMAN)321 for (name, value) in self.selectors.items():322 selector_elem = ElementTree.SubElement(selector_set_elem,323 '{%s}Selector' % NS_WSMAN)324 selector_elem.set('Name', name)325 selector_elem.text = value326 def _add_properties(self, body):327 method_elem = ElementTree.SubElement(328 body,329 ('{%(resource_uri)s}%(method)s_INPUT' %...
code_element.py
Source:code_element.py
...14 self._body.insert(0, line)15 def write(self, code_formatter):16 with self._body_context(code_formatter):17 self._write_body(code_formatter)18 def _add_body(self, code_element, prepend):19 """An easier way to write multiline injected code:20 @code_element.append_body21 def __code__():22 some_code_line()23 for i in range(20):24 some_other_code()25 """26 lines = get_code_lines(code_element)27 if prepend:28 self._body[:0] = lines29 else:30 self._body.extend(lines)31 def append_body(self, code_element):32 self._add_body(code_element, prepend=False)33 include = append_body34 def prepend_body(self, code_element):35 self._add_body(code_element, prepend=True)36 @contextmanager # pylint: disable=unused-argument37 def _body_context(self, code_formatter): # pylint: disable=unused-argument38 yield39 def _write_body(self, code_formatter):40 for line in self._body:41 code_formatter.writeln(line)42 @property43 def source(self):44 buff = StringIO()45 f = CodeFormatter(buff)46 self.write(f)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!