Best Python code snippet using avocado_python
requested_attributes.py
Source:requested_attributes.py
1#!/usr/bin/env python2#3# Generated Tue Jul 18 14:58:29 2017 by parse_xsd.py version 0.5.4#5import saml26from saml2 import SamlBase7from saml2 import saml8NAMESPACE = 'http://eidas.europa.eu/saml-extensions'9class RequestedAttributeType_(SamlBase):10 """The http://eidas.europa.eu/saml-extensions:RequestedAttributeType element """11 c_tag = 'RequestedAttributeType'12 c_namespace = NAMESPACE13 c_children = SamlBase.c_children.copy()14 c_attributes = SamlBase.c_attributes.copy()15 c_child_order = SamlBase.c_child_order[:]16 c_cardinality = SamlBase.c_cardinality.copy()17 c_children['{urn:oasis:names:tc:SAML:2.0:assertion}AttributeValue'] = ('attribute_value', [saml.AttributeValue])18 c_cardinality['attribute_value'] = {"min":0}19 c_attributes['Name'] = ('name', 'None', True)20 c_attributes['NameFormat'] = ('name_format', 'None', True)21 c_attributes['FriendlyName'] = ('friendly_name', 'None', False)22 c_attributes['isRequired'] = ('is_required', 'None', False)23 c_child_order.extend(['attribute_value'])24 def __init__(self,25 attribute_value=None,26 name=None,27 name_format=None,28 friendly_name=None,29 is_required=None,30 text=None,31 extension_elements=None,32 extension_attributes=None,33 ):34 SamlBase.__init__(self,35 text=text,36 extension_elements=extension_elements,37 extension_attributes=extension_attributes,38 )39 self.attribute_value=attribute_value or []40 self.name=name41 self.name_format=name_format42 self.friendly_name=friendly_name43 self.is_required=is_required44def requested_attribute_type__from_string(xml_string):45 return saml2.create_class_from_xml_string(RequestedAttributeType_, xml_string)46class RequestedAttribute(RequestedAttributeType_):47 """The http://eidas.europa.eu/saml-extensions:RequestedAttribute element """48 c_tag = 'RequestedAttribute'49 c_namespace = NAMESPACE50 c_children = RequestedAttributeType_.c_children.copy()51 c_attributes = RequestedAttributeType_.c_attributes.copy()52 c_child_order = RequestedAttributeType_.c_child_order[:]53 c_cardinality = RequestedAttributeType_.c_cardinality.copy()54def requested_attribute_from_string(xml_string):55 return saml2.create_class_from_xml_string(RequestedAttribute, xml_string)56class RequestedAttributesType_(SamlBase):57 """The http://eidas.europa.eu/saml-extensions:RequestedAttributesType element """58 c_tag = 'RequestedAttributesType'59 c_namespace = NAMESPACE60 c_children = SamlBase.c_children.copy()61 c_attributes = SamlBase.c_attributes.copy()62 c_child_order = SamlBase.c_child_order[:]63 c_cardinality = SamlBase.c_cardinality.copy()64 c_children['{http://eidas.europa.eu/saml-extensions}RequestedAttribute'] = ('requested_attribute', [RequestedAttribute])65 c_cardinality['requested_attribute'] = {"min":0}66 c_child_order.extend(['requested_attribute'])67 def __init__(self,68 requested_attribute=None,69 text=None,70 extension_elements=None,71 extension_attributes=None,72 ):73 SamlBase.__init__(self,74 text=text,75 extension_elements=extension_elements,76 extension_attributes=extension_attributes,77 )78 self.requested_attribute=requested_attribute or []79def requested_attributes_type__from_string(xml_string):80 return saml2.create_class_from_xml_string(RequestedAttributesType_, xml_string)81class RequestedAttributes(RequestedAttributesType_):82 """The http://eidas.europa.eu/saml-extensions:RequestedAttributes element """83 c_tag = 'RequestedAttributes'84 c_namespace = NAMESPACE85 c_children = RequestedAttributesType_.c_children.copy()86 c_attributes = RequestedAttributesType_.c_attributes.copy()87 c_child_order = RequestedAttributesType_.c_child_order[:]88 c_cardinality = RequestedAttributesType_.c_cardinality.copy()89def requested_attributes_from_string(xml_string):90 return saml2.create_class_from_xml_string(RequestedAttributes, xml_string)91ELEMENT_FROM_STRING = {92 RequestedAttributes.c_tag: requested_attributes_from_string,93 RequestedAttributesType_.c_tag: requested_attributes_type__from_string,94 RequestedAttribute.c_tag: requested_attribute_from_string,95 RequestedAttributeType_.c_tag: requested_attribute_type__from_string,96}97ELEMENT_BY_TAG = {98 'RequestedAttributes': RequestedAttributes,99 'RequestedAttributesType': RequestedAttributesType_,100 'RequestedAttribute': RequestedAttribute,101 'RequestedAttributeType': RequestedAttributeType_,102}103def factory(tag, **kwargs):...
pokemon_api.py
Source:pokemon_api.py
1import requests2import os3from sys import platform4# Function for clearing the console5def clear() -> None:6 """7 Clearing the console8 """9 # clearing console10 if platform == 'win32':11 os.system('cls')12 elif platform == 'linux' or platform == 'linux2':13 os.system('clear')14# loop for repetition15while True:16 print("Welcome to the pokemon name search data base.")17 pokemon_name = input("Which pokemon do you want to learn about (name) or\18 'q' to quit? ")19 if pokemon_name.lower() == 'q': # to exit the search20 break21 clear() # clear the console22 pokemon_name = pokemon_name.strip()23 # making an API request24 req = requests.get(25 f"https://pokeapi.co/api/v2/pokemon/{pokemon_name.lower()}"26 )27 if req.status_code == 200: # successful api request28 requested_pokemon = req.json()29 # processing the data 30 requested_pokemon_name = requested_pokemon['name'] if \31 requested_pokemon['name'] else 'NoName'# string32 requested_pokemon_abilities = [] # list of strings33 for ability in requested_pokemon['abilities']:34 requested_pokemon_abilities.append(ability['ability']['name'])35 if not requested_pokemon_abilities:36 requested_pokemon_abilities.append("NoAbilities")37 requested_pokemon_species = requested_pokemon['species']['name'] if \38 requested_pokemon['species']['name'] else 'NoName'39 requested_pokemon_weight = requested_pokemon['weight'] if \40 requested_pokemon['weight'] else 'NoWeight'41 requested_pokemon_moves = []42 for move in requested_pokemon['moves']:43 requested_pokemon_moves.append(move['move']['name'])44 if not requested_pokemon_moves:45 requested_pokemon_moves.append("NoMoves")46 pokemon_info_dashboard = """47 You were searching for : {pk_name}48 !! Database found a match with the folowing data !!49 Name: {api_pk_name}50 Has following abilities: {api_pk_abilities}51 Species: {api_species}52 Has folowing moves: {api_moves}53 Weight: {api_weight}54 """.format(pk_name=pokemon_name, api_pk_name=requested_pokemon_name, \55 api_pk_abilities = ', '.join(requested_pokemon_abilities), \56 api_species = requested_pokemon_species, \57 api_weight = requested_pokemon_weight, \58 api_moves = ', '.join(requested_pokemon_moves))59 print(pokemon_info_dashboard)60 else: # API request failed61 print("Name: {} dosen't exists in our database".format(pokemon_name))62 print("Server responded with an Error: {}".format(req.status_code))...
5.3&5.4if_condition.py
Source:5.3&5.4if_condition.py
1#5.3 ,5.42#if,if-else,if-elif-else,å©ç¨ifè¯å¥å¤çå表3#æ¡ä»¶éè¿æä¸ä¸ªæµè¯å就跳è¿ä½ä¸æµè¯4age=655if age<=4:6 print("your admission cost is $0")7elif age<=10 or age>=70:8 print("your admission cost is $5")9elif age<=18 or age>=60:10 print("your admission cost is $10")11else:12 print("your admission cost is $15")1314#å¦æéè¦å¯¹å¤ä¸ªå¯è½ç»æåè¿è¡ç¸åºæä½ï¼åå¤æ¬¡ä½¿ç¨ifï¼èä¸è½ä½¿ç¨elifï¼elseï¼å¦åä¼è·³è¿ä½ä¸æµè¯æ¥éª¤1516#以ä¸å¤çå表17requested_toppings = ['mushroom','green peppers','extra cheese']18message1 = "sorry,we are out of this right now!"19message2 = "finished making your pizza!"20for requested_topping in requested_toppings:21 if requested_topping == 'mushroom':22 print(message1.title())23 else:24 print('Adding '+requested_topping+'.')25print('\n'+message2)2627#ç¡®å®å表é空28requested_toppings = []29if requested_toppings: #è¿è¡é空æ£æ¥30 for requested_topping in requested_toppings:31 print('Adding '+requested_topping+'.')32else:33 print("your choice can't be plain") #对空å表è¿è¡åé¦3435#对å¤ä¸ªå表è¿è¡æä½ï¼æ ¸å¯¹è®¢åæ¯å¦æåè´§ï¼36available_toppings = ['mushroom','olives','green peppers','pepperoni',37 'pineapple','extra cheese']38requested_toppings = ['mushroom','french fries','extra cheese']39for requested_topping in requested_toppings:40 if requested_topping in available_toppings:41 print('Adding '+requested_topping+'.')42 else:43 print(message1.title())44print(message2.title())4546#ç¡®å®å表é空çæ
åµä¸ç¡®è®¤è®¢å47available_toppings = ['mushroom','olives','green peppers','pepperoni',48 'pineapple','extra cheese']49requested_toppings = ['mushroom','french fries','extra cheese']50if requested_toppings:51 for requested_topping in requested_toppings:52 if requested_topping in available_toppings:53 print('Adding '+requested_topping+'.')54 else:55 print('Sorry,We are out of '+requested_topping+' right now!')56 print('\nFinished making your pizza!')57else:
...
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!!