Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.57 KB | None | 0 0
  1. #
  2. # # ---------------- TEST RAIL -----------------
  3. # import requests
  4. # from requests.auth import HTTPBasicAuth
  5. # import json
  6. #
  7. #
  8. # auth = HTTPBasicAuth('seletin@llnw.com', 'HslznRLgi0l/QaPWEbRx-JassJLCvecHaxh62RY.P')
  9. # base_url = 'https://testrail.llnw.net/index.php?'
  10. # headers = {'Content-Type': 'application/json'}
  11. #
  12. # # # get sections
  13. # # url = '/api/v2/get_sections/{proj_id}'.format(proj_id=13)  # 13 - nginx
  14. # # r = requests.get(base_url+url, headers=headers, auth=auth)
  15. # # print json.dumps(r.json(), indent=2)
  16. #
  17. # # remove section
  18. # url = '/api/v2/delete_section/{section_id}'.format(section_id=2322)
  19. # r = requests.post(base_url+url, headers=headers, auth=auth)
  20. # print r.status_code  # 200 ok - section removed
  21.  
  22. # data = {
  23. #     "name": "tcp_send_bufsize_origin"
  24. # }
  25. # r = requests.post('https://testrail.llnw.net/index.php?/api/v2/update_section/27936', json=data, auth=auth)
  26.  
  27.  
  28. # ----------------------------- PEOPLE pass changer -----------------
  29. # from selenium import webdriver
  30. #
  31. # old_pass = ''
  32. # inc = 56
  33. #
  34. # w = webdriver.Chrome()
  35. # w.implicitly_wait(15)
  36. # w.get('https://people.llnw.com/login.php?user=user&path=')
  37. # w.find_element_by_xpath(".//*[@id='ext-comp-1003']").send_keys('seletin@llnw.com')
  38. # w.find_element_by_xpath(".//*[@id='ext-comp-1004']").send_keys(old_pass)
  39. # w.find_element_by_xpath(".//*[@id='ext-gen31']").click()
  40. # for x in range(30):
  41. #     w.find_element_by_xpath(".//*[@id='edittb']/tbody/tr[2]/td[2]/em").click()
  42. #     w.find_element_by_xpath("//button[contains(text(), 'Change ED Password')]").click()
  43. #     w.find_element_by_xpath("//*[@id='oldpass']").send_keys(old_pass)
  44. #     w.find_element_by_xpath("//*[@id='newpass']").send_keys(old_pass[:-2]+str(inc))
  45. #     w.find_element_by_xpath("//*[@id='confirmnewpass']").send_keys(old_pass[:-2]+str(inc))
  46. #     old_pass = old_pass[:-2]+str(inc)
  47. #     print 'old pass:', old_pass
  48. #     inc += 1
  49. #     w.find_element_by_xpath("//button[contains(text(), 'Save')]").click()
  50. #     from time import sleep
  51. #     sleep(1)
  52. #     w.find_element_by_xpath("//div[@class='x-window-br']//button[contains(text(), 'OK')]").click()
  53. #
  54. #     sleep(2)
  55. #
  56.  
  57. # ----------------- ATOM parser -----------------
  58. # from ltf.edgeprism.magic.mp4atoms import Atom, parse_file, write_file
  59. #
  60. # atoms = parse_file('original.mp4')
  61. # print atoms.moov.trak.mdia.minf.stbl.ctts.entry_count
  62. # atoms.moov.trak.mdia.minf.stbl.ctts.entry_count = (999,)
  63. # write_file('modified.mp4', atoms)
  64. #
  65. # atoms = parse_file('modified.mp4')
  66. # print atoms.moov.trak.mdia.minf.stbl.ctts.entry_count
  67.  
  68. # import ssl
  69. # import socket
  70. # s = socket.socket()
  71. # wrapped = ssl.wrap_socket(s)
  72. # wrapped.selected_alpn_protocol()
  73.  
  74. # from hyper import HTTPConnection
  75. #
  76. # c = HTTPConnection('google.com', port=443, secure=True)
  77. #
  78. # r = c.request('GET', '/')
  79. # print r
  80.  
  81. import xml.etree.ElementTree as ElementTree
  82.  
  83.  
  84. class XmlListConfig(list):
  85.     def __init__(self, aList):
  86.         for element in aList:
  87.             if len(element):
  88.                 # treat like dict
  89.                 if len(element) == 1 or element[0].tag != element[1].tag:
  90.                     self.append(XmlDictConfig(element))
  91.                 # treat like list
  92.                 elif element[0].tag == element[1].tag:
  93.                     self.append(XmlListConfig(element))
  94.             elif element.text:
  95.                 text = element.text.strip()
  96.                 if text:
  97.                     self.append(text)
  98.  
  99.  
  100. class XmlDictConfig(dict):
  101.     '''
  102.    Example usage:
  103.  
  104.    >>> tree = ElementTree.parse('your_file.xml')
  105.    >>> root = tree.getroot()
  106.    >>> xmldict = XmlDictConfig(root)
  107.  
  108.    Or, if you want to use an XML string:
  109.  
  110.    >>> root = ElementTree.XML(xml_string)
  111.    >>> xmldict = XmlDictConfig(root)
  112.  
  113.    And then use xmldict for what it is... a dict.
  114.    '''
  115.     def __init__(self, parent_element):
  116.         if parent_element.items():
  117.             self.update(dict(parent_element.items()))
  118.         for element in parent_element:
  119.             if len(element):
  120.                 # treat like dict - we assume that if the first two tags
  121.                 # in a series are different, then they are all different.
  122.                 if len(element) == 1 or element[0].tag != element[1].tag:
  123.                     aDict = XmlDictConfig(element)
  124.                 # treat like list - we assume that if the first two tags
  125.                 # in a series are the same, then the rest are the same.
  126.                 else:
  127.                     # here, we put the list in dictionary; the key is the
  128.                     # tag name the list elements all share in common, and
  129.                     # the value is the list itself
  130.                     aDict = {element[0].tag: XmlListConfig(element)}
  131.                 # if the tag has attributes, add those to the dict
  132.                 if element.items():
  133.                     aDict.update(dict(element.items()))
  134.                 self.update({element.tag: aDict})
  135.             # this assumes that if you've got an attribute in a tag,
  136.             # you won't be having any text. This may or may not be a
  137.             # good idea -- time will tell. It works for the way we are
  138.             # currently doing XML configuration files...
  139.             elif element.items():
  140.                 self.update({element.tag: dict(element.items())})
  141.             # finally, if there are no child tags and no attributes, extract
  142.             # the text
  143.             else:
  144.                 self.update({element.tag: element.text})
  145.  
  146. tree = ElementTree.parse('1.xml')
  147. root = tree.getroot()
  148.  
  149. for x in root.findall('leaderboard'):
  150.     xmldict = XmlDictConfig(x)
  151.     print xmldict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement