Best Python code snippet using autotest_python
LauncherProfile.py
Source:LauncherProfile.py  
...70    s1 = s1.replace('<', '<')71    s1 = s1.replace('>', '>')72    return s17374def quote_attrib(inStr):75    s1 = (isinstance(inStr, basestring) and inStr or76          '%s' % inStr)77    s1 = s1.replace('&', '&')78    s1 = s1.replace('<', '<')79    s1 = s1.replace('>', '>')80    if '"' in s1:81        if "'" in s1:82            s1 = '"%s"' % s1.replace('"', """)83        else:84            s1 = "'%s'" % s185    else:86        s1 = '"%s"' % s187    return s18889def quote_python(inStr):90    s1 = inStr91    if s1.find("'") == -1:92        if s1.find('\n') == -1:93            return "'%s'" % s194        else:95            return "'''%s'''" % s196    else:97        if s1.find('"') != -1:98            s1 = s1.replace('"', '\\"')99        if s1.find('\n') == -1:100            return '"%s"' % s1101        else:102            return '"""%s"""' % s1103104105class MixedContainer:106    # Constants for category:107    CategoryNone = 0108    CategoryText = 1109    CategorySimple = 2110    CategoryComplex = 3111    # Constants for content_type:112    TypeNone = 0113    TypeText = 1114    TypeString = 2115    TypeInteger = 3116    TypeFloat = 4117    TypeDecimal = 5118    TypeDouble = 6119    TypeBoolean = 7120    def __init__(self, category, content_type, name, value):121        self.category = category122        self.content_type = content_type123        self.name = name124        self.value = value125    def getCategory(self):126        return self.category127    def getContenttype(self, content_type):128        return self.content_type129    def getValue(self):130        return self.value131    def getName(self):132        return self.name133    def export(self, outfile, level, name, namespace):134        if self.category == MixedContainer.CategoryText:135            outfile.write(self.value)136        elif self.category == MixedContainer.CategorySimple:137            self.exportSimple(outfile, level, name)138        else:    # category == MixedContainer.CategoryComplex139            self.value.export(outfile, level, namespace,name)140    def exportSimple(self, outfile, level, name):141        if self.content_type == MixedContainer.TypeString:142            outfile.write('<%s>%s</%s>' % (self.name, self.value, self.name))143        elif self.content_type == MixedContainer.TypeInteger or \144                self.content_type == MixedContainer.TypeBoolean:145            outfile.write('<%s>%d</%s>' % (self.name, self.value, self.name))146        elif self.content_type == MixedContainer.TypeFloat or \147                self.content_type == MixedContainer.TypeDecimal:148            outfile.write('<%s>%f</%s>' % (self.name, self.value, self.name))149        elif self.content_type == MixedContainer.TypeDouble:150            outfile.write('<%s>%g</%s>' % (self.name, self.value, self.name))151    def exportLiteral(self, outfile, level, name):152        if self.category == MixedContainer.CategoryText:153            showIndent(outfile, level)154            outfile.write('MixedContainer(%d, %d, "%s", "%s"),\n' % \155                (self.category, self.content_type, self.name, self.value))156        elif self.category == MixedContainer.CategorySimple:157            showIndent(outfile, level)158            outfile.write('MixedContainer(%d, %d, "%s", "%s"),\n' % \159                (self.category, self.content_type, self.name, self.value))160        else:    # category == MixedContainer.CategoryComplex161            showIndent(outfile, level)162            outfile.write('MixedContainer(%d, %d, "%s",\n' % \163                (self.category, self.content_type, self.name,))164            self.value.exportLiteral(outfile, level + 1)165            showIndent(outfile, level)166            outfile.write(')\n')167168169class MemberSpec_(object):170    def __init__(self, name='', data_type='', container=0):171        self.name = name172        self.data_type = data_type173        self.container = container174    def set_name(self, name): self.name = name175    def get_name(self): return self.name176    def set_data_type(self, data_type): self.data_type = data_type177    def get_data_type_chain(self): return self.data_type178    def get_data_type(self):179        if isinstance(self.data_type, list):180            if len(self.data_type) > 0:181                return self.data_type[-1]182            else:183                return 'xs:string'184        else:185            return self.data_type186    def set_container(self, container): self.container = container187    def get_container(self): return self.container188189def _cast(typ, value):190    if typ is None or value is None:191        return value192    return typ(value)193194#195# Data representation classes.196#197198class LaunchConfigs(GeneratedsSuper):199    subclass = None200    superclass = None201    def __init__(self, version=None, Config=None):202        self.version = _cast(None, version)203        if Config is None:204            self.Config = []205        else:206            self.Config = Config207    def factory(*args_, **kwargs_):208        if LaunchConfigs.subclass:209            return LaunchConfigs.subclass(*args_, **kwargs_)210        else:211            return LaunchConfigs(*args_, **kwargs_)212    factory = staticmethod(factory)213    def get_Config(self): return self.Config214    def set_Config(self, Config): self.Config = Config215    def add_Config(self, value): self.Config.append(value)216    def insert_Config(self, index, value): self.Config[index] = value217    def get_version(self): return self.version218    def set_version(self, version): self.version = version219    def validate_VersionType(self, value):220        # Validate type VersionType, a restriction on xs:token.221        pass222    def export(self, outfile, level, namespace_='', name_='LaunchConfigs', namespacedef_=''):223        showIndent(outfile, level)224        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))225        self.exportAttributes(outfile, level, namespace_, name_='LaunchConfigs')226        if self.hasContent_():227            outfile.write('>\n')228            self.exportChildren(outfile, level + 1, namespace_, name_)229            showIndent(outfile, level)230            outfile.write('</%s%s>\n' % (namespace_, name_))231        else:232            outfile.write('/>\n')233    def exportAttributes(self, outfile, level, namespace_='', name_='LaunchConfigs'):234        outfile.write(' version=%s' % (quote_attrib(self.version), ))235    def exportChildren(self, outfile, level, namespace_='', name_='LaunchConfigs'):236        for Config_ in self.Config:237            Config_.export(outfile, level, namespace_, name_='Config')238    def hasContent_(self):239        if (240            self.Config241            ):242            return True243        else:244            return False245    def exportLiteral(self, outfile, level, name_='LaunchConfigs'):246        level += 1247        self.exportLiteralAttributes(outfile, level, name_)248        if self.hasContent_():249            self.exportLiteralChildren(outfile, level, name_)250    def exportLiteralAttributes(self, outfile, level, name_):251        if self.version is not None:252            showIndent(outfile, level)253            outfile.write('version = "%s",\n' % (self.version,))254    def exportLiteralChildren(self, outfile, level, name_):255        showIndent(outfile, level)256        outfile.write('Config=[\n')257        level += 1258        for Config in self.Config:259            showIndent(outfile, level)260            outfile.write('model_.Config(\n')261            Config.exportLiteral(outfile, level, name_='Config')262            showIndent(outfile, level)263            outfile.write('),\n')264        level -= 1265        showIndent(outfile, level)266        outfile.write('],\n')267    def build(self, node_):268        attrs = node_.attributes269        self.buildAttributes(attrs)270        for child_ in node_.childNodes:271            nodeName_ = child_.nodeName.split(':')[-1]272            self.buildChildren(child_, nodeName_)273    def buildAttributes(self, attrs):274        if attrs.get('version'):275            self.version = attrs.get('version').value276            self.validate_VersionType(self.version)    # validate type VersionType277    def buildChildren(self, child_, nodeName_):278        if child_.nodeType == Node.ELEMENT_NODE and \279            nodeName_ == 'Config':280            obj_ = ConfigType.factory()281            obj_.build(child_)282            self.Config.append(obj_)283# end class LaunchConfigs284285286class ConfigType(GeneratedsSuper):287    subclass = None288    superclass = None289    def __init__(self, TaskbarName=None, XmsUnits=None, VMLoc=None, Name=None, EclipseArgs=None, ShowSplash=None, Refresh=None, Xms=None, EclipseLoc=None, Xmx=None, Clean=None, VMArgs=None, WorkspaceLoc=None, XmxUnits=None, Description=None, valueOf_=''):290        self.TaskbarName = _cast(None, TaskbarName)291        self.XmsUnits = _cast(None, XmsUnits)292        self.VMLoc = _cast(None, VMLoc)293        self.Name = _cast(None, Name)294        self.EclipseArgs = _cast(None, EclipseArgs)295        self.ShowSplash = _cast(bool, ShowSplash)296        self.Refresh = _cast(bool, Refresh)297        self.Xms = _cast(None, Xms)298        self.EclipseLoc = _cast(None, EclipseLoc)299        self.Xmx = _cast(None, Xmx)300        self.Clean = _cast(bool, Clean)301        self.VMArgs = _cast(None, VMArgs)302        self.WorkspaceLoc = _cast(None, WorkspaceLoc)303        self.XmxUnits = _cast(None, XmxUnits)304        self.Description = _cast(None, Description)305        self.valueOf_ = valueOf_306    def factory(*args_, **kwargs_):307        if ConfigType.subclass:308            return ConfigType.subclass(*args_, **kwargs_)309        else:310            return ConfigType(*args_, **kwargs_)311    factory = staticmethod(factory)312    def get_TaskbarName(self): return self.TaskbarName313    def set_TaskbarName(self, TaskbarName): self.TaskbarName = TaskbarName314    def validate_NameType(self, value):315        # Validate type NameType, a restriction on xs:string.316        pass317    def get_XmsUnits(self): return self.XmsUnits318    def set_XmsUnits(self, XmsUnits): self.XmsUnits = XmsUnits319    def validate_UnitsType(self, value):320        # Validate type UnitsType, a restriction on xs:string.321        pass322    def get_VMLoc(self): return self.VMLoc323    def set_VMLoc(self, VMLoc): self.VMLoc = VMLoc324    def validate_PathnameType(self, value):325        # Validate type PathnameType, a restriction on xs:token.326        pass327    def get_Name(self): return self.Name328    def set_Name(self, Name): self.Name = Name329    def get_EclipseArgs(self): return self.EclipseArgs330    def set_EclipseArgs(self, EclipseArgs): self.EclipseArgs = EclipseArgs331    def validate_ArgsType(self, value):332        # Validate type ArgsType, a restriction on xs:string.333        pass334    def get_ShowSplash(self): return self.ShowSplash335    def set_ShowSplash(self, ShowSplash): self.ShowSplash = ShowSplash336    def get_Refresh(self): return self.Refresh337    def set_Refresh(self, Refresh): self.Refresh = Refresh338    def get_Xms(self): return self.Xms339    def set_Xms(self, Xms): self.Xms = Xms340    def validate_XmsType(self, value):341        # Validate type XmsType, a restriction on xs:unsignedInt.342        pass343    def get_EclipseLoc(self): return self.EclipseLoc344    def set_EclipseLoc(self, EclipseLoc): self.EclipseLoc = EclipseLoc345    def get_Xmx(self): return self.Xmx346    def set_Xmx(self, Xmx): self.Xmx = Xmx347    def validate_XmxType(self, value):348        # Validate type XmxType, a restriction on xs:unsignedInt.349        pass350    def get_Clean(self): return self.Clean351    def set_Clean(self, Clean): self.Clean = Clean352    def get_VMArgs(self): return self.VMArgs353    def set_VMArgs(self, VMArgs): self.VMArgs = VMArgs354    def get_WorkspaceLoc(self): return self.WorkspaceLoc355    def set_WorkspaceLoc(self, WorkspaceLoc): self.WorkspaceLoc = WorkspaceLoc356    def get_XmxUnits(self): return self.XmxUnits357    def set_XmxUnits(self, XmxUnits): self.XmxUnits = XmxUnits358    def get_Description(self): return self.Description359    def set_Description(self, Description): self.Description = Description360    def validate_DescType(self, value):361        # Validate type DescType, a restriction on xs:string.362        pass363    def getValueOf_(self): return self.valueOf_364    def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_365    def export(self, outfile, level, namespace_='', name_='ConfigType', namespacedef_=''):366        showIndent(outfile, level)367        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))368        self.exportAttributes(outfile, level, namespace_, name_='ConfigType')369        if self.hasContent_():370            outfile.write('>')371            self.exportChildren(outfile, level + 1, namespace_, name_)372            outfile.write('</%s%s>\n' % (namespace_, name_))373        else:374            outfile.write('/>\n')375    def exportAttributes(self, outfile, level, namespace_='', name_='ConfigType'):376        if self.TaskbarName is not None:377            outfile.write(' TaskbarName=%s' % (quote_attrib(self.TaskbarName), ))378        if self.XmsUnits is not None:379            outfile.write(' XmsUnits=%s' % (quote_attrib(self.XmsUnits), ))380        if self.VMLoc is not None:381            outfile.write(' VMLoc=%s' % (quote_attrib(self.VMLoc), ))382        outfile.write(' Name=%s' % (quote_attrib(self.Name), ))383        if self.EclipseArgs is not None:384            outfile.write(' EclipseArgs=%s' % (quote_attrib(self.EclipseArgs), ))385        if self.ShowSplash is not None:386            outfile.write(' ShowSplash="%s"' % self.format_boolean(str_lower(str(self.ShowSplash)), input_name='ShowSplash'))387        if self.Refresh is not None:388            outfile.write(' Refresh="%s"' % self.format_boolean(str_lower(str(self.Refresh)), input_name='Refresh'))389        if self.Xms is not None:390            outfile.write(' Xms=%s' % (quote_attrib(self.Xms), ))391        outfile.write(' EclipseLoc=%s' % (quote_attrib(self.EclipseLoc), ))392        if self.Xmx is not None:393            outfile.write(' Xmx=%s' % (quote_attrib(self.Xmx), ))394        if self.Clean is not None:395            outfile.write(' Clean="%s"' % self.format_boolean(str_lower(str(self.Clean)), input_name='Clean'))396        if self.VMArgs is not None:397            outfile.write(' VMArgs=%s' % (quote_attrib(self.VMArgs), ))398        outfile.write(' WorkspaceLoc=%s' % (quote_attrib(self.WorkspaceLoc), ))399        if self.XmxUnits is not None:400            outfile.write(' XmxUnits=%s' % (quote_attrib(self.XmxUnits), ))401        if self.Description is not None:402            outfile.write(' Description=%s' % (quote_attrib(self.Description), ))403    def exportChildren(self, outfile, level, namespace_='', name_='ConfigType'):404        if self.valueOf_.find('![CDATA') > -1:405            value=quote_xml('%s' % self.valueOf_)406            value=value.replace('![CDATA','<![CDATA')407            value=value.replace(']]',']]>')408            outfile.write(value)409        else:410            outfile.write(quote_xml('%s' % self.valueOf_))411    def hasContent_(self):412        if (413            self.valueOf_414            ):415            return True416        else:
...encoding_test.py
Source:encoding_test.py  
...60        self.assertEqual(av_class.classification_name, av_class2.classification_name)61    def test_quote_xml(self):62        s = bindings.quote_xml(UNICODE_STR)63        self.assertEqual(s, UNICODE_STR)64    def test_quote_attrib(self):65        """Tests that the maec.bindings.quote_attrib method works properly66        on unicode inputs.67        Note:68            The quote_attrib method (more specifically, saxutils.quoteattr())69            adds quotation marks around the input data, so we need to strip70            the leading and trailing chars to test effectively71        """72        s = bindings.quote_attrib(UNICODE_STR)73        s = s[1:-1]74        self.assertEqual(s, UNICODE_STR)75    def test_quote_attrib_int(self):76        i = 6553677        s = bindings.quote_attrib(i)78        self.assertEqual(u'"65536"', s)79    def test_quote_attrib_bool(self):80        b = True81        s = bindings.quote_attrib(b)82        self.assertEqual(u'"True"', s)83    def test_quote_xml_int(self):84        i = 6553685        s = bindings.quote_xml(i)86        self.assertEqual(unicode(i), s)87    def test_quote_xml_bool(self):88        b = True89        s = bindings.quote_xml(b)90        self.assertEqual(unicode(b), s)91    def test_quote_xml_encoded(self):92        encoding = bindings.ExternalEncoding93        encoded = UNICODE_STR.encode(encoding)94        quoted = bindings.quote_xml(encoded)95        self.assertEqual(UNICODE_STR, quoted)96    def test_quote_attrib_encoded(self):97        encoding = bindings.ExternalEncoding98        encoded = UNICODE_STR.encode(encoding)99        quoted = bindings.quote_attrib(encoded)[1:-1]100        self.assertEqual(UNICODE_STR, quoted)101    def test_quote_xml_zero(self):102        i = 0103        s = bindings.quote_xml(i)104        self.assertEqual(unicode(i), s)105    def test_quote_attrib_zero(self):106        i = 0107        s = bindings.quote_attrib(i)108        self.assertEqual(u'"0"', s)109    def test_quote_xml_none(self):110        i = None111        s = bindings.quote_xml(i)112        self.assertEqual(u'', s)113    def test_quote_attrib_none(self):114        i = None115        s = bindings.quote_attrib(i)116        self.assertEqual(u'""', s)117    def test_quote_attrib_empty(self):118        i = ''119        s = bindings.quote_attrib(i)120        self.assertEqual(u'""', s)121    def test_quote_xml_empty(self):122        i = ''123        s = bindings.quote_xml(i)124        self.assertEqual(u'', s)125    def test_to_xml_utf16_encoded(self):126        encoding = 'utf-16'127        b = Behavior()128        b.description = UNICODE_STR129        xml = b.to_xml(encoding=encoding)130        self.assertTrue(UNICODE_STR in xml.decode(encoding))131    def test_to_xml_default_encoded(self):132        b = Behavior()133        b.description = UNICODE_STR...OutputField_exportAttributes.py
Source:OutputField_exportAttributes.py  
1        if self.name is not None and 'name' not in already_processed:2            already_processed.add('name')3            outfile.write(' name=%s' % (supermod.quote_attrib(self.name), ))4        if self.displayName is not None and 'displayName' not in already_processed:5            already_processed.add('displayName')6            outfile.write(' displayName=%s' % (self.gds_encode(self.gds_format_string(supermod.quote_attrib(self.displayName), input_name='displayName')), ))7        if self.optype is not None and 'optype' not in already_processed:8            already_processed.add('optype')9            outfile.write(' optype=%s' % (supermod.quote_attrib(self.optype), ))10        if self.dataType is not None and 'dataType' not in already_processed:11            already_processed.add('dataType')12            outfile.write(' dataType=%s' % (supermod.quote_attrib(self.dataType), ))13        if self.targetField is not None and 'targetField' not in already_processed:14            already_processed.add('targetField')15            outfile.write(' targetField=%s' % (supermod.quote_attrib(self.targetField), ))16        if self.feature is not None and 'feature' not in already_processed:17            already_processed.add('feature')18            outfile.write(' feature=%s' % (supermod.quote_attrib(self.feature), ))19        if self.value is not None and 'value' not in already_processed:20            already_processed.add('value')21            outfile.write(' value=%s' % (self.gds_encode(self.gds_format_string(supermod.quote_attrib(self.value), input_name='value')), ))22        if self.ruleFeature != "consequent" and 'ruleFeature' not in already_processed:23            already_processed.add('ruleFeature')24            outfile.write(' ruleFeature=%s' % (supermod.quote_attrib(self.ruleFeature), ))25        if self.algorithm != "exclusiveRecommendation" and 'algorithm' not in already_processed:26            already_processed.add('algorithm')27            outfile.write(' algorithm=%s' % (self.gds_encode(self.gds_format_string(supermod.quote_attrib(self.algorithm), input_name='algorithm')), ))28        # if self.rank is not None and 'rank' not in already_processed:29            # already_processed.add('rank')30            # outfile.write(' rank=%s' % (supermod.quote_attrib(self.rank), ))31        if self.rankBasis != "confidence" and 'rankBasis' not in already_processed:32            already_processed.add('rankBasis')33            outfile.write(' rankBasis=%s' % (self.gds_encode(self.gds_format_string(supermod.quote_attrib(self.rankBasis), input_name='rankBasis')), ))34        if self.rankOrder != "descending" and 'rankOrder' not in already_processed:35            already_processed.add('rankOrder')36            outfile.write(' rankOrder=%s' % (self.gds_encode(self.gds_format_string(supermod.quote_attrib(self.rankOrder), input_name='rankOrder')), ))37        if self.isMultiValued != "0" and 'isMultiValued' not in already_processed:38            already_processed.add('isMultiValued')39            outfile.write(' isMultiValued=%s' % (self.gds_encode(self.gds_format_string(supermod.quote_attrib(self.isMultiValued), input_name='isMultiValued')), ))40        if self.segmentId is not None and 'segmentId' not in already_processed:41            already_processed.add('segmentId')42            outfile.write(' segmentId=%s' % (self.gds_encode(self.gds_format_string(supermod.quote_attrib(self.segmentId), input_name='segmentId')), ))43        if not self.isFinalResult and 'isFinalResult' not in already_processed:44            already_processed.add('isFinalResult')...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!!
