single variable or dictionary to xml representation
(val, name, trim_if_too_big=True, additional_in_xml="", evaluate_full_value=True)
| 393 | |
| 394 | |
| 395 | def var_to_xml(val, name, trim_if_too_big=True, additional_in_xml="", evaluate_full_value=True): |
| 396 | """single variable or dictionary to xml representation""" |
| 397 | |
| 398 | type_name, type_qualifier, is_exception_on_eval, resolver, value = get_variable_details(val, evaluate_full_value) |
| 399 | |
| 400 | scope = get_var_scope(name, val, "", True) |
| 401 | try: |
| 402 | name = quote(name, "/>_= ") # TODO: Fix PY-5834 without using quote |
| 403 | except: |
| 404 | pass |
| 405 | |
| 406 | xml = '<var name="%s" type="%s" ' % (make_valid_xml_value(name), make_valid_xml_value(type_name)) |
| 407 | |
| 408 | if type_qualifier: |
| 409 | xml_qualifier = 'qualifier="%s"' % make_valid_xml_value(type_qualifier) |
| 410 | else: |
| 411 | xml_qualifier = "" |
| 412 | |
| 413 | if value: |
| 414 | # cannot be too big... communication may not handle it. |
| 415 | if len(value) > MAXIMUM_VARIABLE_REPRESENTATION_SIZE and trim_if_too_big: |
| 416 | value = value[0:MAXIMUM_VARIABLE_REPRESENTATION_SIZE] |
| 417 | value += "..." |
| 418 | |
| 419 | xml_value = ' value="%s"' % (make_valid_xml_value(quote(value, "/>_= "))) |
| 420 | else: |
| 421 | xml_value = "" |
| 422 | |
| 423 | if is_exception_on_eval: |
| 424 | xml_container = ' isErrorOnEval="True"' |
| 425 | else: |
| 426 | if resolver is not None: |
| 427 | xml_container = ' isContainer="True"' |
| 428 | else: |
| 429 | xml_container = "" |
| 430 | |
| 431 | if scope: |
| 432 | return "".join((xml, xml_qualifier, xml_value, xml_container, additional_in_xml, ' scope="', scope, '"', " />\n")) |
| 433 | else: |
| 434 | return "".join((xml, xml_qualifier, xml_value, xml_container, additional_in_xml, " />\n")) |
no test coverage detected