1# Copyright (c) 2017, The MITRE Corporation. All rights reserved. 2# See LICENSE.txt for complete terms. 3 4import sys 5 6from mixbox.binding_utils import * 7from . import cybox_common 8 9 10class SharedResourceType(cybox_common.BaseObjectPropertyType): 11 """SharedResourceType specifies Windows shared resource types via a 12 union of the SharedResourceTypeEnum type and the atomic 13 xs:string type. Its base type is the CybOX Core 14 cybox_common.BaseObjectPropertyType, for permitting complex (i.e. regular- 15 expression based) specifications.This attribute is optional and 16 specifies the expected type for the value of the specified 17 property.""" 18 19 subclass = None 20 superclass = cybox_common.BaseObjectPropertyType 21 def __init__(self, obfuscation_algorithm_ref=None, refanging_transform_type=None, has_changed=None, delimiter='##comma##', pattern_type=None, datatype='string', refanging_transform=None, is_case_sensitive=True, bit_mask=None, appears_random=None, observed_encoding=None, defanging_algorithm_ref=None, is_obfuscated=None, regex_syntax=None, apply_condition='ANY', trend=None, idref=None, is_defanged=None, id=None, condition=None, valueOf_=None): 22 super(SharedResourceType, self).__init__(obfuscation_algorithm_ref, refanging_transform_type, has_changed, delimiter, pattern_type, datatype, refanging_transform, is_case_sensitive, bit_mask, appears_random, observed_encoding, defanging_algorithm_ref, is_obfuscated, regex_syntax, apply_condition, trend, idref, is_defanged, id, condition, valueOf_) 23 self.datatype = _cast(None, datatype) 24 self.valueOf_ = valueOf_ 25 def factory(*args_, **kwargs_): 26 if SharedResourceType.subclass: 27 return SharedResourceType.subclass(*args_, **kwargs_) 28 else: 29 return SharedResourceType(*args_, **kwargs_) 30 factory = staticmethod(factory) 31 def get_datatype(self): return self.datatype 32 def set_datatype(self, datatype): self.datatype = datatype 33 def get_valueOf_(self): return self.valueOf_ 34 def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_ 35 def hasContent_(self): 36 if ( 37 self.valueOf_ or 38 super(SharedResourceType, self).hasContent_() 39 ): 40 return True 41 else: 42 return False 43 def export(self, lwrite, level, namespace_='WinNetworkShareObj:', name_='SharedResourceType', namespacedef_='', pretty_print=True): 44 if pretty_print: 45 eol_ = '\n' 46 else: 47 eol_ = '' 48 showIndent(lwrite, level, pretty_print) 49 lwrite('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 50 already_processed = set() 51 self.exportAttributes(lwrite, level, already_processed, namespace_, name_='SharedResourceType') 52 if self.hasContent_(): 53 lwrite('>') 54 lwrite(quote_xml(self.valueOf_)) 55 self.exportChildren(lwrite, level + 1, namespace_, name_, pretty_print=pretty_print) 56 lwrite('</%s%s>%s' % (namespace_, name_, eol_)) 57 else: 58 lwrite('/>%s' % (eol_, )) 59 def exportAttributes(self, lwrite, level, already_processed, namespace_='WinNetworkShareObj:', name_='SharedResourceType'): 60 super(SharedResourceType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='SharedResourceType') 61 if self.datatype is not None: 62 63 lwrite(' datatype=%s' % (quote_attrib(self.datatype), )) 64 def exportChildren(self, lwrite, level, namespace_='WinNetworkShareObj:', name_='SharedResourceType', fromsubclass_=False, pretty_print=True): 65 super(SharedResourceType, self).exportChildren(lwrite, level, 'WinNetworkShareObj:', name_, True, pretty_print=pretty_print) 66 pass 67 def build(self, node): 68 self.__sourcenode__ = node 69 already_processed = set() 70 self.buildAttributes(node, node.attrib, already_processed) 71 self.valueOf_ = get_all_text_(node) 72 for child in node: 73 nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 74 self.buildChildren(child, node, nodeName_) 75 def buildAttributes(self, node, attrs, already_processed): 76 value = find_attr_value_('datatype', node) 77 if value is not None: 78 79 self.datatype = value 80 super(SharedResourceType, self).buildAttributes(node, attrs, already_processed) 81 def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 82 pass 83# end class SharedResourceType 84 85class WindowsNetworkShareObjectType(cybox_common.ObjectPropertiesType): 86 """he WindowsNetworkShareObjectType type is intended to characterize 87 Windows network shares.""" 88 89 subclass = None 90 superclass = cybox_common.ObjectPropertiesType 91 def __init__(self, object_reference=None, Custom_Properties=None, xsi_type=None, ACCESS_PERM=None, ACCESS_ATRIB=None, ACCESS_ALL=None, ACCESS_READ=None, ACCESS_DELETE=None, ACCESS_WRITE=None, ACCESS_CREATE=None, ACCESS_EXEC=None, Current_Uses=None, Local_Path=None, Max_Uses=None, Netname=None, Type=None): 92 super(WindowsNetworkShareObjectType, self).__init__(object_reference, Custom_Properties, xsi_type ) 93 self.ACCESS_PERM = _cast(bool, ACCESS_PERM) 94 self.ACCESS_ATRIB = _cast(bool, ACCESS_ATRIB) 95 self.ACCESS_ALL = _cast(bool, ACCESS_ALL) 96 self.ACCESS_READ = _cast(bool, ACCESS_READ) 97 self.ACCESS_DELETE = _cast(bool, ACCESS_DELETE) 98 self.ACCESS_WRITE = _cast(bool, ACCESS_WRITE) 99 self.ACCESS_CREATE = _cast(bool, ACCESS_CREATE) 100 self.ACCESS_EXEC = _cast(bool, ACCESS_EXEC) 101 self.Current_Uses = Current_Uses 102 self.Local_Path = Local_Path 103 self.Max_Uses = Max_Uses 104 self.Netname = Netname 105 self.Type = Type 106 def factory(*args_, **kwargs_): 107 if WindowsNetworkShareObjectType.subclass: 108 return WindowsNetworkShareObjectType.subclass(*args_, **kwargs_) 109 else: 110 return WindowsNetworkShareObjectType(*args_, **kwargs_) 111 factory = staticmethod(factory) 112 def get_Current_Uses(self): return self.Current_Uses 113 def set_Current_Uses(self, Current_Uses): self.Current_Uses = Current_Uses 114 def validate_NonNegativeIntegerObjectPropertyType(self, value): 115 # Validate type cybox_common.NonNegativeIntegerObjectPropertyType, a restriction on None. 116 pass 117 def get_Local_Path(self): return self.Local_Path 118 def set_Local_Path(self, Local_Path): self.Local_Path = Local_Path 119 def validate_StringObjectPropertyType(self, value): 120 # Validate type cybox_common.StringObjectPropertyType, a restriction on None. 121 pass 122 def get_Max_Uses(self): return self.Max_Uses 123 def set_Max_Uses(self, Max_Uses): self.Max_Uses = Max_Uses 124 def get_Netname(self): return self.Netname 125 def set_Netname(self, Netname): self.Netname = Netname 126 def get_Type(self): return self.Type 127 def set_Type(self, Type): self.Type = Type 128 def validate_SharedResourceType(self, value): 129 # Validate type SharedResourceType, a restriction on None. 130 pass 131 def get_ACCESS_PERM(self): return self.ACCESS_PERM 132 def set_ACCESS_PERM(self, ACCESS_PERM): self.ACCESS_PERM = ACCESS_PERM 133 def get_ACCESS_ATRIB(self): return self.ACCESS_ATRIB 134 def set_ACCESS_ATRIB(self, ACCESS_ATRIB): self.ACCESS_ATRIB = ACCESS_ATRIB 135 def get_ACCESS_ALL(self): return self.ACCESS_ALL 136 def set_ACCESS_ALL(self, ACCESS_ALL): self.ACCESS_ALL = ACCESS_ALL 137 def get_ACCESS_READ(self): return self.ACCESS_READ 138 def set_ACCESS_READ(self, ACCESS_READ): self.ACCESS_READ = ACCESS_READ 139 def get_ACCESS_DELETE(self): return self.ACCESS_DELETE 140 def set_ACCESS_DELETE(self, ACCESS_DELETE): self.ACCESS_DELETE = ACCESS_DELETE 141 def get_ACCESS_WRITE(self): return self.ACCESS_WRITE 142 def set_ACCESS_WRITE(self, ACCESS_WRITE): self.ACCESS_WRITE = ACCESS_WRITE 143 def get_ACCESS_CREATE(self): return self.ACCESS_CREATE 144 def set_ACCESS_CREATE(self, ACCESS_CREATE): self.ACCESS_CREATE = ACCESS_CREATE 145 def get_ACCESS_EXEC(self): return self.ACCESS_EXEC 146 def set_ACCESS_EXEC(self, ACCESS_EXEC): self.ACCESS_EXEC = ACCESS_EXEC 147 def hasContent_(self): 148 if ( 149 self.Current_Uses is not None or 150 self.Local_Path is not None or 151 self.Max_Uses is not None or 152 self.Netname is not None or 153 self.Type is not None or 154 super(WindowsNetworkShareObjectType, self).hasContent_() 155 ): 156 return True 157 else: 158 return False 159 def export(self, lwrite, level, namespace_='WinNetworkShareObj:', name_='WindowsNetworkShareObjectType', namespacedef_='', pretty_print=True): 160 if pretty_print: 161 eol_ = '\n' 162 else: 163 eol_ = '' 164 showIndent(lwrite, level, pretty_print) 165 lwrite('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 166 already_processed = set() 167 self.exportAttributes(lwrite, level, already_processed, namespace_, name_='WindowsNetworkShareObjectType') 168 if self.hasContent_(): 169 lwrite('>%s' % (eol_, )) 170 self.exportChildren(lwrite, level + 1, namespace_, name_, pretty_print=pretty_print) 171 showIndent(lwrite, level, pretty_print) 172 lwrite('</%s%s>%s' % (namespace_, name_, eol_)) 173 else: 174 lwrite('/>%s' % (eol_, )) 175 def exportAttributes(self, lwrite, level, already_processed, namespace_='WinNetworkShareObj:', name_='WindowsNetworkShareObjectType'): 176 super(WindowsNetworkShareObjectType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='WindowsNetworkShareObjectType') 177 if self.ACCESS_PERM is not None: 178 179 lwrite(' ACCESS_PERM="%s"' % self.gds_format_boolean(self.ACCESS_PERM, input_name='ACCESS_PERM')) 180 if self.ACCESS_ATRIB is not None: 181 182 lwrite(' ACCESS_ATRIB="%s"' % self.gds_format_boolean(self.ACCESS_ATRIB, input_name='ACCESS_ATRIB')) 183 if self.ACCESS_ALL is not None: 184 185 lwrite(' ACCESS_ALL="%s"' % self.gds_format_boolean(self.ACCESS_ALL, input_name='ACCESS_ALL')) 186 if self.ACCESS_READ is not None: 187 188 lwrite(' ACCESS_READ="%s"' % self.gds_format_boolean(self.ACCESS_READ, input_name='ACCESS_READ')) 189 if self.ACCESS_DELETE is not None: 190 191 lwrite(' ACCESS_DELETE="%s"' % self.gds_format_boolean(self.ACCESS_DELETE, input_name='ACCESS_DELETE')) 192 if self.ACCESS_WRITE is not None: 193 194 lwrite(' ACCESS_WRITE="%s"' % self.gds_format_boolean(self.ACCESS_WRITE, input_name='ACCESS_WRITE')) 195 if self.ACCESS_CREATE is not None: 196 197 lwrite(' ACCESS_CREATE="%s"' % self.gds_format_boolean(self.ACCESS_CREATE, input_name='ACCESS_CREATE')) 198 if self.ACCESS_EXEC is not None: 199 200 lwrite(' ACCESS_EXEC="%s"' % self.gds_format_boolean(self.ACCESS_EXEC, input_name='ACCESS_EXEC')) 201 def exportChildren(self, lwrite, level, namespace_='WinNetworkShareObj:', name_='WindowsNetworkShareObjectType', fromsubclass_=False, pretty_print=True): 202 super(WindowsNetworkShareObjectType, self).exportChildren(lwrite, level, 'WinNetworkShareObj:', name_, True, pretty_print=pretty_print) 203 if pretty_print: 204 eol_ = '\n' 205 else: 206 eol_ = '' 207 if self.Current_Uses is not None: 208 self.Current_Uses.export(lwrite, level, 'WinNetworkShareObj:', name_='Current_Uses', pretty_print=pretty_print) 209 if self.Local_Path is not None: 210 self.Local_Path.export(lwrite, level, 'WinNetworkShareObj:', name_='Local_Path', pretty_print=pretty_print) 211 if self.Max_Uses is not None: 212 self.Max_Uses.export(lwrite, level, 'WinNetworkShareObj:', name_='Max_Uses', pretty_print=pretty_print) 213 if self.Netname is not None: 214 self.Netname.export(lwrite, level, 'WinNetworkShareObj:', name_='Netname', pretty_print=pretty_print) 215 if self.Type is not None: 216 self.Type.export(lwrite, level, 'WinNetworkShareObj:', name_='Type', pretty_print=pretty_print) 217 def build(self, node): 218 self.__sourcenode__ = node 219 already_processed = set() 220 self.buildAttributes(node, node.attrib, already_processed) 221 for child in node: 222 nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 223 self.buildChildren(child, node, nodeName_) 224 def buildAttributes(self, node, attrs, already_processed): 225 value = find_attr_value_('ACCESS_PERM', node) 226 if value is not None: 227 228 if value in ('true', '1'): 229 self.ACCESS_PERM = True 230 elif value in ('false', '0'): 231 self.ACCESS_PERM = False 232 else: 233 raise_parse_error(node, 'Bad boolean attribute') 234 value = find_attr_value_('ACCESS_ATRIB', node) 235 if value is not None: 236 237 if value in ('true', '1'): 238 self.ACCESS_ATRIB = True 239 elif value in ('false', '0'): 240 self.ACCESS_ATRIB = False 241 else: 242 raise_parse_error(node, 'Bad boolean attribute') 243 value = find_attr_value_('ACCESS_ALL', node) 244 if value is not None: 245 246 if value in ('true', '1'): 247 self.ACCESS_ALL = True 248 elif value in ('false', '0'): 249 self.ACCESS_ALL = False 250 else: 251 raise_parse_error(node, 'Bad boolean attribute') 252 value = find_attr_value_('ACCESS_READ', node) 253 if value is not None: 254 255 if value in ('true', '1'): 256 self.ACCESS_READ = True 257 elif value in ('false', '0'): 258 self.ACCESS_READ = False 259 else: 260 raise_parse_error(node, 'Bad boolean attribute') 261 value = find_attr_value_('ACCESS_DELETE', node) 262 if value is not None: 263 264 if value in ('true', '1'): 265 self.ACCESS_DELETE = True 266 elif value in ('false', '0'): 267 self.ACCESS_DELETE = False 268 else: 269 raise_parse_error(node, 'Bad boolean attribute') 270 value = find_attr_value_('ACCESS_WRITE', node) 271 if value is not None: 272 273 if value in ('true', '1'): 274 self.ACCESS_WRITE = True 275 elif value in ('false', '0'): 276 self.ACCESS_WRITE = False 277 else: 278 raise_parse_error(node, 'Bad boolean attribute') 279 value = find_attr_value_('ACCESS_CREATE', node) 280 if value is not None: 281 282 if value in ('true', '1'): 283 self.ACCESS_CREATE = True 284 elif value in ('false', '0'): 285 self.ACCESS_CREATE = False 286 else: 287 raise_parse_error(node, 'Bad boolean attribute') 288 value = find_attr_value_('ACCESS_EXEC', node) 289 if value is not None: 290 291 if value in ('true', '1'): 292 self.ACCESS_EXEC = True 293 elif value in ('false', '0'): 294 self.ACCESS_EXEC = False 295 else: 296 raise_parse_error(node, 'Bad boolean attribute') 297 super(WindowsNetworkShareObjectType, self).buildAttributes(node, attrs, already_processed) 298 def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 299 if nodeName_ == 'Current_Uses': 300 obj_ = cybox_common.NonNegativeIntegerObjectPropertyType.factory() 301 obj_.build(child_) 302 self.set_Current_Uses(obj_) 303 elif nodeName_ == 'Local_Path': 304 obj_ = cybox_common.StringObjectPropertyType.factory() 305 obj_.build(child_) 306 self.set_Local_Path(obj_) 307 elif nodeName_ == 'Max_Uses': 308 obj_ = cybox_common.NonNegativeIntegerObjectPropertyType.factory() 309 obj_.build(child_) 310 self.set_Max_Uses(obj_) 311 elif nodeName_ == 'Netname': 312 obj_ = cybox_common.StringObjectPropertyType.factory() 313 obj_.build(child_) 314 self.set_Netname(obj_) 315 elif nodeName_ == 'Type': 316 obj_ = SharedResourceType.factory() 317 obj_.build(child_) 318 self.set_Type(obj_) 319 super(WindowsNetworkShareObjectType, self).buildChildren(child_, node, nodeName_, True) 320# end class WindowsNetworkShareObjectType 321 322GDSClassesMapping = { 323 'Build_Utility': cybox_common.BuildUtilityType, 324 'Errors': cybox_common.ErrorsType, 325 'Time': cybox_common.TimeType, 326 'Certificate_Issuer': cybox_common.StringObjectPropertyType, 327 'Metadata': cybox_common.MetadataType, 328 'Hash': cybox_common.HashType, 329 'Information_Source_Type': cybox_common.ControlledVocabularyStringType, 330 'Block_Hash_Value': cybox_common.HashValueType, 331 'Fuzzy_Hash_Structure': cybox_common.FuzzyHashStructureType, 332 'SubDatum': cybox_common.MetadataType, 333 'Segment_Hash': cybox_common.HashValueType, 334 'Digital_Signature': cybox_common.DigitalSignatureInfoType, 335 'Code_Snippets': cybox_common.CodeSnippetsType, 336 'Value': cybox_common.StringObjectPropertyType, 337 'Length': cybox_common.IntegerObjectPropertyType, 338 'Encoding': cybox_common.ControlledVocabularyStringType, 339 'Internationalization_Settings': cybox_common.InternationalizationSettingsType, 340 'Tool_Configuration': cybox_common.ToolConfigurationType, 341 'English_Translation': cybox_common.StringObjectPropertyType, 342 'Functions': cybox_common.FunctionsType, 343 'String_Value': cybox_common.StringObjectPropertyType, 344 'Build_Utility_Platform_Specification': cybox_common.PlatformSpecificationType, 345 'Compiler_Informal_Description': cybox_common.CompilerInformalDescriptionType, 346 'System': cybox_common.ObjectPropertiesType, 347 'Platform': cybox_common.PlatformSpecificationType, 348 'Usage_Context_Assumptions': cybox_common.UsageContextAssumptionsType, 349 'Type': cybox_common.ControlledVocabularyStringType, 350 'Compilers': cybox_common.CompilersType, 351 'Tool_Type': cybox_common.ControlledVocabularyStringType, 352 'String': cybox_common.ExtractedStringType, 353 'Tool': cybox_common.ToolInformationType, 354 'Build_Information': cybox_common.BuildInformationType, 355 'Tool_Hashes': cybox_common.HashListType, 356 'Max_Uses': cybox_common.NonNegativeIntegerObjectPropertyType, 357 'Error_Instances': cybox_common.ErrorInstancesType, 358 'Data_Segment': cybox_common.StringObjectPropertyType, 359 'Certificate_Subject': cybox_common.StringObjectPropertyType, 360 'Language': cybox_common.StringObjectPropertyType, 361 'Property': cybox_common.PropertyType, 362 'Strings': cybox_common.ExtractedStringsType, 363 'File_System_Offset': cybox_common.IntegerObjectPropertyType, 364 'Compiler_Platform_Specification': cybox_common.PlatformSpecificationType, 365 'Reference_Description': cybox_common.StructuredTextType, 366 'Code_Snippet': cybox_common.ObjectPropertiesType, 367 'Local_Path': cybox_common.StringObjectPropertyType, 368 'Configuration_Settings': cybox_common.ConfigurationSettingsType, 369 'Simple_Hash_Value': cybox_common.SimpleHashValueType, 370 'Byte_String_Value': cybox_common.HexBinaryObjectPropertyType, 371 'Instance': cybox_common.ObjectPropertiesType, 372 'Import': cybox_common.StringObjectPropertyType, 373 'Identifier': cybox_common.PlatformIdentifierType, 374 'Tool_Specific_Data': cybox_common.ToolSpecificDataType, 375 'Execution_Environment': cybox_common.ExecutionEnvironmentType, 376 'Dependencies': cybox_common.DependenciesType, 377 'Offset': cybox_common.IntegerObjectPropertyType, 378 'Date': cybox_common.DateRangeType, 379 'Hashes': cybox_common.HashListType, 380 'Segments': cybox_common.HashSegmentsType, 381 'Segment_Count': cybox_common.IntegerObjectPropertyType, 382 'Usage_Context_Assumption': cybox_common.StructuredTextType, 383 'Block_Hash': cybox_common.FuzzyHashBlockType, 384 'Dependency': cybox_common.DependencyType, 385 'Error': cybox_common.ErrorType, 386 'Trigger_Point': cybox_common.HexBinaryObjectPropertyType, 387 'Environment_Variable': cybox_common.EnvironmentVariableType, 388 'Byte_Run': cybox_common.ByteRunType, 389 'Contributors': cybox_common.PersonnelType, 390 'Image_Offset': cybox_common.IntegerObjectPropertyType, 391 'Imports': cybox_common.ImportsType, 392 'Library': cybox_common.LibraryType, 393 'References': cybox_common.ToolReferencesType, 394 'Netname': cybox_common.StringObjectPropertyType, 395 'Internal_Strings': cybox_common.InternalStringsType, 396 'Custom_Properties': cybox_common.CustomPropertiesType, 397 'Configuration_Setting': cybox_common.ConfigurationSettingType, 398 'Libraries': cybox_common.LibrariesType, 399 'Function': cybox_common.StringObjectPropertyType, 400 'Description': cybox_common.StructuredTextType, 401 'User_Account_Info': cybox_common.ObjectPropertiesType, 402 'Build_Configuration': cybox_common.BuildConfigurationType, 403 'Address': cybox_common.HexBinaryObjectPropertyType, 404 'Search_Within': cybox_common.IntegerObjectPropertyType, 405 'Segment': cybox_common.HashSegmentType, 406 'Compiler': cybox_common.CompilerType, 407 'Name': cybox_common.StringObjectPropertyType, 408 'Signature_Description': cybox_common.StringObjectPropertyType, 409 'Block_Size': cybox_common.IntegerObjectPropertyType, 410 'Search_Distance': cybox_common.IntegerObjectPropertyType, 411 'Fuzzy_Hash_Value': cybox_common.FuzzyHashValueType, 412 'Current_Uses': cybox_common.NonNegativeIntegerObjectPropertyType, 413 'Dependency_Description': cybox_common.StructuredTextType, 414 'Contributor': cybox_common.ContributorType, 415 'Tools': cybox_common.ToolsInformationType, 416 'Data_Size': cybox_common.DataSizeType, 417} 418 419USAGE_TEXT = """ 420Usage: python <Parser>.py [ -s ] <in_xml_file> 421""" 422 423def usage(): 424 print(USAGE_TEXT) 425 sys.exit(1) 426 427def get_root_tag(node): 428 tag = Tag_pattern_.match(node.tag).groups()[-1] 429 rootClass = GDSClassesMapping.get(tag) 430 if rootClass is None: 431 rootClass = globals().get(tag) 432 return tag, rootClass 433 434def parse(inFileName): 435 doc = parsexml_(inFileName) 436 rootNode = doc.getroot() 437 rootTag, rootClass = get_root_tag(rootNode) 438 if rootClass is None: 439 rootTag = 'Windows_Network_Share' 440 rootClass = WindowsNetworkShareObjectType 441 rootObj = rootClass.factory() 442 rootObj.build(rootNode) 443 # Enable Python to collect the space used by the DOM. 444 doc = None 445# sys.stdout.write('<?xml version="1.0" ?>\n') 446# rootObj.export(sys.stdout.write, 0, name_=rootTag, 447# namespacedef_='', 448# pretty_print=True) 449 return rootObj 450 451def parseEtree(inFileName): 452 doc = parsexml_(inFileName) 453 rootNode = doc.getroot() 454 rootTag, rootClass = get_root_tag(rootNode) 455 if rootClass is None: 456 rootTag = 'Windows_Network_Share' 457 rootClass = WindowsNetworkShareObjectType 458 rootObj = rootClass.factory() 459 rootObj.build(rootNode) 460 # Enable Python to collect the space used by the DOM. 461 doc = None 462 rootElement = rootObj.to_etree(None, name_=rootTag) 463 content = etree_.tostring(rootElement, pretty_print=True, 464 xml_declaration=True, encoding="utf-8") 465 sys.stdout.write(content) 466 sys.stdout.write('\n') 467 return rootObj, rootElement 468 469def parseString(inString): 470 from mixbox.vendor.six import StringIO 471 doc = parsexml_(StringIO(inString)) 472 rootNode = doc.getroot() 473 rootTag, rootClass = get_root_tag(rootNode) 474 if rootClass is None: 475 rootTag = 'Windows_Network_Share' 476 rootClass = WindowsNetworkShareObjectType 477 rootObj = rootClass.factory() 478 rootObj.build(rootNode) 479 # Enable Python to collect the space used by the DOM. 480 doc = None 481# sys.stdout.write('<?xml version="1.0" ?>\n') 482# rootObj.export(sys.stdout.write, 0, name_="Windows_Network_Share", 483# namespacedef_='') 484 return rootObj 485 486def main(): 487 args = sys.argv[1:] 488 if len(args) == 1: 489 parse(args[0]) 490 else: 491 usage() 492 493if __name__ == '__main__': 494 #import pdb; pdb.set_trace() 495 main() 496 497__all__ = [ 498 "WindowsNetworkShareObjectType", 499 "SharedResourceType" 500 ] 501