Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # # ---------------- TEST RAIL -----------------
- # import requests
- # from requests.auth import HTTPBasicAuth
- # import json
- #
- #
- # auth = HTTPBasicAuth('seletin@llnw.com', 'HslznRLgi0l/QaPWEbRx-JassJLCvecHaxh62RY.P')
- # base_url = 'https://testrail.llnw.net/index.php?'
- # headers = {'Content-Type': 'application/json'}
- #
- # # # get sections
- # # url = '/api/v2/get_sections/{proj_id}'.format(proj_id=13) # 13 - nginx
- # # r = requests.get(base_url+url, headers=headers, auth=auth)
- # # print json.dumps(r.json(), indent=2)
- #
- # # remove section
- # url = '/api/v2/delete_section/{section_id}'.format(section_id=2322)
- # r = requests.post(base_url+url, headers=headers, auth=auth)
- # print r.status_code # 200 ok - section removed
- # data = {
- # "name": "tcp_send_bufsize_origin"
- # }
- # r = requests.post('https://testrail.llnw.net/index.php?/api/v2/update_section/27936', json=data, auth=auth)
- # ----------------------------- PEOPLE pass changer -----------------
- # from selenium import webdriver
- #
- # old_pass = ''
- # inc = 56
- #
- # w = webdriver.Chrome()
- # w.implicitly_wait(15)
- # w.get('https://people.llnw.com/login.php?user=user&path=')
- # w.find_element_by_xpath(".//*[@id='ext-comp-1003']").send_keys('seletin@llnw.com')
- # w.find_element_by_xpath(".//*[@id='ext-comp-1004']").send_keys(old_pass)
- # w.find_element_by_xpath(".//*[@id='ext-gen31']").click()
- # for x in range(30):
- # w.find_element_by_xpath(".//*[@id='edittb']/tbody/tr[2]/td[2]/em").click()
- # w.find_element_by_xpath("//button[contains(text(), 'Change ED Password')]").click()
- # w.find_element_by_xpath("//*[@id='oldpass']").send_keys(old_pass)
- # w.find_element_by_xpath("//*[@id='newpass']").send_keys(old_pass[:-2]+str(inc))
- # w.find_element_by_xpath("//*[@id='confirmnewpass']").send_keys(old_pass[:-2]+str(inc))
- # old_pass = old_pass[:-2]+str(inc)
- # print 'old pass:', old_pass
- # inc += 1
- # w.find_element_by_xpath("//button[contains(text(), 'Save')]").click()
- # from time import sleep
- # sleep(1)
- # w.find_element_by_xpath("//div[@class='x-window-br']//button[contains(text(), 'OK')]").click()
- #
- # sleep(2)
- #
- # ----------------- ATOM parser -----------------
- # from ltf.edgeprism.magic.mp4atoms import Atom, parse_file, write_file
- #
- # atoms = parse_file('original.mp4')
- # print atoms.moov.trak.mdia.minf.stbl.ctts.entry_count
- # atoms.moov.trak.mdia.minf.stbl.ctts.entry_count = (999,)
- # write_file('modified.mp4', atoms)
- #
- # atoms = parse_file('modified.mp4')
- # print atoms.moov.trak.mdia.minf.stbl.ctts.entry_count
- # import ssl
- # import socket
- # s = socket.socket()
- # wrapped = ssl.wrap_socket(s)
- # wrapped.selected_alpn_protocol()
- # from hyper import HTTPConnection
- #
- # c = HTTPConnection('google.com', port=443, secure=True)
- #
- # r = c.request('GET', '/')
- # print r
- import xml.etree.ElementTree as ElementTree
- class XmlListConfig(list):
- def __init__(self, aList):
- for element in aList:
- if len(element):
- # treat like dict
- if len(element) == 1 or element[0].tag != element[1].tag:
- self.append(XmlDictConfig(element))
- # treat like list
- elif element[0].tag == element[1].tag:
- self.append(XmlListConfig(element))
- elif element.text:
- text = element.text.strip()
- if text:
- self.append(text)
- class XmlDictConfig(dict):
- '''
- Example usage:
- >>> tree = ElementTree.parse('your_file.xml')
- >>> root = tree.getroot()
- >>> xmldict = XmlDictConfig(root)
- Or, if you want to use an XML string:
- >>> root = ElementTree.XML(xml_string)
- >>> xmldict = XmlDictConfig(root)
- And then use xmldict for what it is... a dict.
- '''
- def __init__(self, parent_element):
- if parent_element.items():
- self.update(dict(parent_element.items()))
- for element in parent_element:
- if len(element):
- # treat like dict - we assume that if the first two tags
- # in a series are different, then they are all different.
- if len(element) == 1 or element[0].tag != element[1].tag:
- aDict = XmlDictConfig(element)
- # treat like list - we assume that if the first two tags
- # in a series are the same, then the rest are the same.
- else:
- # here, we put the list in dictionary; the key is the
- # tag name the list elements all share in common, and
- # the value is the list itself
- aDict = {element[0].tag: XmlListConfig(element)}
- # if the tag has attributes, add those to the dict
- if element.items():
- aDict.update(dict(element.items()))
- self.update({element.tag: aDict})
- # this assumes that if you've got an attribute in a tag,
- # you won't be having any text. This may or may not be a
- # good idea -- time will tell. It works for the way we are
- # currently doing XML configuration files...
- elif element.items():
- self.update({element.tag: dict(element.items())})
- # finally, if there are no child tags and no attributes, extract
- # the text
- else:
- self.update({element.tag: element.text})
- tree = ElementTree.parse('1.xml')
- root = tree.getroot()
- for x in root.findall('leaderboard'):
- xmldict = XmlDictConfig(x)
- print xmldict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement