示例#1
0
文件: window.py 项目: VsyachePuz/agui
    def __init__(self, name, file, parent=None):
        AWindow.__init__(self, name, file, parent)

        self.builder = Gtk.Builder()
        self.builder.add_from_file(self.file)
        self.item = self.builder.get_object(self.name)
        if self.parent is not None:
            self.item.set_transient_for(self.parent.item)

        self.types = {}
        for cls in self.classes:
            if hasattr(cls, 'type'):
                self.types[cls.type] = cls

        tree = ElementTree()
        tree.parse(self.file)
        ele_widgets = tree.getiterator("object")
        for ele_widget in ele_widgets:
            name = ele_widget.attrib['id']
            widget = self.builder.get_object(name)
            type = widget.__class__.__name__

            if type in self.types:
                self.widgets[name] = self.types[type](widget)
            else:
                self.other_widgets[name] = widget

        self.item.connect('delete-event', self.emit_closed)
示例#2
0
    def run(self):
        # Run the module only once
        if not constant.wifi_password:
            interfaces_dir = os.path.join(
                constant.profile['ALLUSERSPROFILE'],
                u'Microsoft\\Wlansvc\\Profiles\\Interfaces')

            # for windows Vista or higher
            if os.path.exists(interfaces_dir):

                pwd_found = []

                for wifi_dir in os.listdir(interfaces_dir):
                    if os.path.isdir(os.path.join(interfaces_dir, wifi_dir)):

                        repository = os.path.join(interfaces_dir, wifi_dir)
                        for file in os.listdir(repository):
                            values = {}
                            if os.path.isfile(os.path.join(repository, file)):
                                f = os.path.join(repository, file)
                                tree = ElementTree(file=f)
                                root = tree.getroot()
                                xmlns = root.tag.split("}")[0] + '}'

                                for elem in tree.iter():
                                    if elem.tag.endswith('SSID'):
                                        for w in elem:
                                            if w.tag == xmlns + 'name':
                                                values['SSID'] = w.text

                                    if elem.tag.endswith('authentication'):
                                        values['Authentication'] = elem.text

                                    if elem.tag.endswith('protected'):
                                        values['Protected'] = elem.text

                                    if elem.tag.endswith('keyMaterial'):
                                        key = elem.text
                                        try:
                                            password = self.decrypt_using_lsa_secret(
                                                key=key)
                                            if not password:
                                                password = self.decrypt_using_netsh(
                                                    ssid=values['SSID'])
                                            if password:
                                                values['Password'] = password
                                            else:
                                                values[
                                                    'INFO'] = '[!] Password not found.'
                                        except Exception:
                                            self.error(traceback.format_exc())
                                            values[
                                                'INFO'] = '[!] Password not found.'

                                if values and values.get(
                                        'Authentication') != 'open':
                                    pwd_found.append(values)

                constant.wifi_password = True
                return pwd_found
示例#3
0
    def add_from_file(self, filename):
        '''parses xml file and stores wanted details'''
        Gtk.Builder.add_from_file(self, filename)

        # extract data for the extra interfaces
        tree = ElementTree()
        tree.parse(filename)

        ele_widgets = tree.getiterator("object")
        for ele_widget in ele_widgets:
            name = ele_widget.attrib['id']
            widget = self.get_object(name)

            # populate indexes - a dictionary of widgets
            self.widgets[name] = widget

            # populate a reversed dictionary
            self._reverse_widget_dict[widget] = name

            # populate connections list
            ele_signals = ele_widget.findall("signal")

            connections = [(name, ele_signal.attrib['name'],
                            ele_signal.attrib['handler'])
                           for ele_signal in ele_signals]

            if connections:
                self.connections.extend(connections)

        ele_signals = tree.getiterator("signal")
        for ele_signal in ele_signals:
            self.glade_handler_dict.update(
                {ele_signal.attrib["handler"]: None})
示例#4
0
    def pagetext_search(self, locator, query, rows=None, start=None):
        """Does an advanced search on
               pagetext:blah locator:identifier
        where identifier is one of the id's from fulltext search.
        You get back a list of page numbers like [21, 25, 39]."""

        def extract(page_id):
            """TODO: DjVu format is deprecated. Is this function
            still even used?
            A page id is something like
            'adventsuburbanit00butlrich_0065.djvu',
            which this function extracts asa a locator and
            a leaf number ('adventsuburbanit00butlrich', 65). """

            g = re.search(r'(.*)_(\d{4})\.djvu$', page_id)
            a,b = g.group(1,2)
            return a, int(b)

        # try using qf= parameter here and see if it gives a speedup. @@
        # pdb.set_trace()
        query = self._prefix_query('pagetext', query)
        page_hits = self.raw_search(query,
                                    fq='locator:' + locator,
                                    rows=rows,
                                    start=start)
        XML = ElementTree()
        try:
            XML.parse(StringIO(page_hits))
        except SyntaxError as e:
            raise SolrError(e)
        page_ids = list(e.text for e in XML.getiterator('identifier'))
        return [extract(x)[1] for x in page_ids]
示例#5
0
def parse_position(path):
    """Parses the position attribute from .gexf file viz tag and returns the dict with the node sizes.

    Default nx.read_gexf() does not read attributes from the visualization namespace
    of .gexf files so we use this function to get the node positions, possibly after using layout 
    algorithms in Gephi. 
    
    To learn more see : https://gephi.org/gexf/format/viz.html 

    Parameters
    ----------
    path : str
        File or filename of the graph in .gexf format.
    
    Returns
    -------
    dict
        Returns dict containing the node positions. Example : {'1':(2.0,3.0)} 


    """
    tree = ElementTree(file=path)
    root = tree.getroot()
    nodes = [child for child in root.iter() if "nodes" in child.tag][0]
    positions = {}
    for node in nodes:
        id = node.attrib['id']
        position = [child for child in node
                    if "position" in child.tag][0].attrib
        positions[id] = (float(position['x']), float(position['y']))
    return positions
示例#6
0
def parse_size(path):
    """Parses the size attribute from .gexf file viz tag and returns the dict with the node sizes.

    Default nx.read_gexf() does not read attributes from the visualization namespace
    of .gexf files so we use this function to get the node sizes. 
    
    To learn more see : https://gephi.org/gexf/format/viz.html 

    Parameters
    ----------
    path : str
        File or filename of the graph in .gexf format.
    
    Returns
    -------
    dict
        Returns dict containing the node sizes. Example : {'1':52.0} 

    """
    tree = ElementTree(file=path)
    root = tree.getroot()
    nodes = [child for child in root.iter() if "nodes" in child.tag][0]
    sizes = {}
    for node in nodes:
        id = node.attrib['id']
        size = [child for child in node if "size" in child.tag][0].attrib
        sizes[id] = float(size['value'])
    return sizes
示例#7
0
文件: mimi.py 项目: welchr/snipper
def mimi_fetch_interactions(gene_id, taxid=None):
    gene_id = str(gene_id)

    url = MIMI_INT_URL % gene_id

    try:
        if _SNIPPER_DEBUG:
            print "DEBUG: executing MiMI URL %s" % url
    except:
        pass

    xml = urllib2.urlopen(url, timeout=CON_TIMEOUT)
    tree = ElementTree()
    tree.parse(xml)

    go_pattern = re.compile("(.+) \[GO:(\d+)\]")

    def extract(pattern, string):
        match = pattern.search(string)
        if match:
            return match.groups()
        else:
            return (None, None)

    results = []
    for int_gene in tree.getroot().findall(
            "MiMI/Response/ResultSet/Result/InteractingGene"):
        other_gene = int_gene.find("GeneID").text
        interaction = GeneInteraction(gene_id, other_gene)

        for element in int_gene.getchildren():
            if element.tag == "TaxonomyID":
                interaction.set_tax(element.text)
            elif element.tag == "InteractionAttribute":
                type = element.get('type')
                if type == "Component":
                    tup = extract(go_pattern, element.text)
                    interaction.add_component(*tup)
                elif type == "Function":
                    tup = extract(go_pattern, element.text)
                    interaction.add_function(*tup)
                elif type == "Process":
                    tup = extract(go_pattern, element.text)
                    interaction.add_process(*tup)
                elif type == "Provenance":
                    interaction.add_provenance(element.text)
                elif type == "PubMed":
                    interaction.add_pubmed(element.text)
                elif type == "InteractionType":
                    interaction.add_interaction_type(element.text)

        # Taxonomy ID filter.
        if taxid != None:
            if interaction.taxon_id != taxid:
                continue

        results.append(interaction)

    return results
示例#8
0
    def run(self, software_name=None):
        path = os.path.join(constant.profile['APPDATA'], u'SQL Developer')
        if os.path.exists(path):
            self._passphrase = self.get_passphrase(path)
            if self._passphrase:
                print_debug(
                    'INFO', u'Passphrase found: {passphrase}'.format(
                        passphrase=self._passphrase))
                xml_name = u'connections.xml'
                xml_file = None

                if os.path.exists(os.path.join(path, xml_name)):
                    xml_file = os.path.join(path, xml_name)
                else:
                    for p in os.listdir(path):
                        if p.startswith('system'):
                            new_directory = os.path.join(path, p)

                            for pp in os.listdir(new_directory):
                                if pp.startswith(
                                        u'o.jdeveloper.db.connection'):
                                    if os.path.exists(
                                            os.path.join(
                                                new_directory, pp, xml_name)):
                                        xml_file = os.path.join(
                                            new_directory, pp, xml_name)
                                    break

                if xml_file:
                    renamed_value = {
                        'sid': 'SID',
                        'port': 'Port',
                        'hostname': 'Host',
                        'user': '******',
                        'password': '******',
                        'ConnName': 'Name',
                        'customUrl': 'URL',
                        'SavePassword': '******',
                        'driver': 'Driver'
                    }
                    tree = ElementTree(file=xml_file)

                    pwd_found = []
                    for e in tree.findall('Reference'):
                        values = {}
                        for ee in e.findall('RefAddresses/StringRefAddr'):
                            if ee.attrib[
                                    'addrType'] in renamed_value and ee.find(
                                        'Contents').text is not None:
                                name = renamed_value[ee.attrib['addrType']]
                                value = ee.find(
                                    'Contents'
                                ).text if name != 'Password' else self.decrypt(
                                    ee.find('Contents').text)
                                values[name] = value

                        pwd_found.append(values)

                    return pwd_found
    def writeXMLTVConfig(self):

        if self.epgimport is None and self.xmltvimport is None and self.crossepg is None:
            return

        if int(self.epgimportversion[0]) >= 5 and int(
                self.xmltvimportversion[0]) >= 5 and int(
                    self.crossepgversion[0]) >= 5:
            return

        if config.plugins.seriesplugin.epgimport.value == False and config.plugins.seriesplugin.xmltvimport.value == False and config.plugins.seriesplugin.crossepg.value == False:
            return

        # Build Header
        from plugin import NAME, VERSION
        root = Element("sources")
        root.set('version', VERSION)
        root.set('created_by', NAME)
        root.append(
            Comment(
                _("Don't edit this manually unless you really know what you are doing"
                  )))

        element = SubElement(root,
                             "source",
                             type="gen_xmltv",
                             channels="wunschliste.channels.xml")

        SubElement(element, "description").text = "Wunschliste XMLTV"
        SubElement(element,
                   "url").text = config.plugins.seriesplugin.xmltv_url.value

        etree = ElementTree(root)

        indent(etree.getroot())

        if config.plugins.seriesplugin.epgimport.value:
            log.debug("Write: xml channels for epgimport")
            if self.epgimport:
                try:
                    self.epgimport.writeXML(etree)
                except Exception as e:
                    log.exception("Exception in write XML: " + str(e))

        if config.plugins.seriesplugin.xmltvimport.value:
            log.debug("Write: xml channels for xmltvimport")
            if self.xmltvimport:
                try:
                    self.xmltvimport.writeXML(etree)
                except Exception as e:
                    log.exception("Exception in write XML: " + str(e))

        if config.plugins.seriesplugin.crossepg.value:
            log.debug("Write: xml channels for crossepg")
            if self.crossepg:
                try:
                    self.crossepg.writeXML(etree)
                except Exception as e:
                    log.exception("Exception in write XML: " + str(e))
示例#10
0
文件: gexf.py 项目: paulrt/evo
 def write(self, fh):
     # Serialize graph G in GEXF to the open fh
     if self.prettyprint:
         self.indent(self.xml)
     document = ElementTree(self.xml)
     header = '<?xml version="1.0" encoding="%s"?>' % self.encoding
     fh.write(header.encode(self.encoding))
     document.write(fh, encoding=self.encoding)
示例#11
0
def serialize(data, name='object'):
    content_elem = Element('contenttype')
    content_elem.attrib['name'] = name
    _serialize(content_elem, data)
    tree = ElementTree(content_elem)
    f = StringIO()
    tree.write(f, 'UTF-8')
    return f.getvalue()
示例#12
0
def read_macro(filename):
    # Extract the OAD script code from ZEN macro file: *.czmac

    print('Reading OAD Macro: ', filename)
    tree = ElementTree(file=filename)
    pyscript = tree.find('Text').text

    return pyscript
示例#13
0
 def saveAP(self, apFileName, autoGdlFile) :
     root = Element('font')
     root.set('upem', str(self.emunits()))
     root.set('producer', 'graide 1.0')
     root.text = "\n\n"
     for g in self.glyphs :
         if g : g.createAP(root, self, autoGdlFile)
     ElementTree(root).write(apFileName, encoding="utf-8", xml_declaration=True)
示例#14
0
def msgfdb2pepxml(in_file,
                  out_file,
                  modifications_file=None,
                  mzxml=None,
                  fasta=None):
    """ Convert tab-separated ms-gfdb output to pepXML

    * in_file -- output file of MS-GFDB
    * out_file -- pepXML file to write to
    * modifications_file -- modifications file of MS-GFDB (Mods.txt)
    * mzxml -- input mzXML file of MS-GFDB
    * fasta -- input fasta file of MS-GFDB with database of peptides
    """
    if not out_file:
        out_filename = re.sub(r"\.msgfdb$", ".pep.xml", in_file.name)
        if out_filename == in_file.name:
            raise Exception(
                "Provide output file or input file with extension .msgfdb")
        out_file = open(out_filename, 'w')
    modifications = default_modifications
    num_mods = None
    if modifications_file:
        num_mods, modifications = read_modifications(modifications_file)
    msms_pipeline_analysis = create_msms_pipeline_analysis()
    tree = ElementTree(msms_pipeline_analysis)
    msms_run_summary = SubElement(msms_pipeline_analysis, 'msms_run_summary')
    base_name = remove_file_extention(os.path.abspath(in_file.name))
    msms_run_summary.set('base_name', base_name)
    SubElement(msms_run_summary, 'sample_enzyme')
    search_summary = SubElement(msms_run_summary, 'search_summary')
    search_summary.set('search_engine', "X! Tandem (k-score)")
    if fasta:
        search_database = SubElement(search_summary, 'search_database')
        search_database.set('local_path', os.path.abspath(fasta.name))
    apply_msgfdb(in_file, msms_run_summary, modifications, num_mods)
    set_hit_ranks(msms_run_summary)
    if mzxml:
        msrun = get_msrun(mzxml)
        ms_instrument = msrun.find('msInstrument')
        if ms_instrument is not None:
            for field in [
                    'msManufacturer', 'msModel', 'msIonisation', 'msDetector'
            ]:
                param = ms_instrument.find(field)
                if param is not None:
                    msms_run_summary.set(field, param.get('value'))
        set_retention_times(msrun, msms_run_summary)
    out = StringIO()
    tree.write(out, encoding='UTF-8', xml_declaration=True)
    out_file.write(out.getvalue().replace('>', '>\n'))
    in_file.close()
    out_file.close()
    if modifications_file:
        modifications_file.close()
    if mzxml:
        mzxml.close()
    if fasta:
        fasta.close()
示例#15
0
def ReadPropertiesFromFile(filename):
    """Return an list of controls from XML file filename"""

    # parse the file
    parsed = ElementTree().parse(filename)

    # Return the list that has been stored under 'CONTROL'
    props = _ReadXMLStructure(parsed)['CONTROL']
    if not isinstance(props, list):
        props = [props]

    # it is an old XML so let's fix it up a little
    if not ("_version_" in parsed.attrib.keys()):

        # find each of the control elements
        for ctrl_prop in props:

            ctrl_prop['Fonts'] = [
                _XMLToStruct(ctrl_prop['FONT'], "LOGFONTW"),
            ]

            ctrl_prop['Rectangle'] = \
                _XMLToStruct(ctrl_prop["RECTANGLE"], "RECT")

            ctrl_prop['ClientRects'] = [
                _XMLToStruct(ctrl_prop["CLIENTRECT"], "RECT"),
            ]

            ctrl_prop['Texts'] = _OLD_XMLToTitles(ctrl_prop["TITLES"])

            ctrl_prop['Class'] = ctrl_prop['CLASS']
            ctrl_prop['ContextHelpID'] = ctrl_prop['HELPID']
            ctrl_prop['ControlID'] = ctrl_prop['CTRLID']
            ctrl_prop['ExStyle'] = ctrl_prop['EXSTYLE']
            ctrl_prop['FriendlyClassName'] = ctrl_prop['FRIENDLYCLASS']
            ctrl_prop['IsUnicode'] = ctrl_prop['ISUNICODE']
            ctrl_prop['IsVisible'] = ctrl_prop['ISVISIBLE']
            ctrl_prop['Style'] = ctrl_prop['STYLE']
            ctrl_prop['UserData'] = ctrl_prop['USERDATA']

            for prop_name in [
                    'CLASS',
                    'CLIENTRECT',
                    'CTRLID',
                    'EXSTYLE',
                    'FONT',
                    'FRIENDLYCLASS',
                    'HELPID',
                    'ISUNICODE',
                    'ISVISIBLE',
                    'RECTANGLE',
                    'STYLE',
                    'TITLES',
                    'USERDATA',
            ]:
                del (ctrl_prop[prop_name])

    return props
示例#16
0
    def run(self):

        windir = os.path.join(constant.profile['HOMEDRIVE'],
                              string_to_unicode(os.sep), u'Windows')
        files = [
            'Panther\\Unattend.xml', 'Panther\\Unattended.xml',
            'Panther\\Unattend\\Unattended.xml',
            'Panther\\Unattend\\Unattend.xml',
            'System32\\Sysprep\\unattend.xml',
            'System32\\Sysprep\\Panther\\unattend.xml'
        ]

        pwd_found = []
        xmlns = '{urn:schemas-microsoft-com:unattend}'
        for file in files:
            path = os.path.join(windir, string_to_unicode(file))
            if os.path.exists(path):
                self.debug(u'Unattended file found: %s' % path)
                tree = ElementTree(file=path)
                root = tree.getroot()

                for setting in root.findall('%ssettings' % xmlns):
                    component = setting.find('%scomponent' % xmlns)

                    auto_logon = component.find('%sauto_logon' % xmlns)
                    if auto_logon:
                        username = auto_logon.find('%sUsername' % xmlns)
                        password = auto_logon.find('%sPassword' % xmlns)
                        if all((username, password)):
                            # Remove false positive (with following message on password => *SENSITIVE*DATA*DELETED*)
                            if 'deleted' not in password.text.lower():
                                pwd_found.append({
                                    'Login':
                                    username.text,
                                    'Password':
                                    self.try_b64_decode(password.text)
                                })

                    user_accounts = component.find('%suser_accounts' % xmlns)
                    if user_accounts:
                        local_accounts = user_accounts.find(
                            '%slocal_accounts' % xmlns)
                        if local_accounts:
                            for local_account in local_accounts.findall(
                                    '%slocal_account' % xmlns):
                                username = local_account.find('%sName' % xmlns)
                                password = local_account.find('%sPassword' %
                                                              xmlns)
                                if all((username, password)):
                                    if 'deleted' not in password.text.lower():
                                        pwd_found.append({
                                            'Login':
                                            username.text,
                                            'Password':
                                            self.try_b64_decode(password.text)
                                        })

        return pwd_found
示例#17
0
        def normalizeXML(value):

            if value[0] == '<':
                try:
                    tree = ElementTree(file=StringIO(value))
                except Exception:
                    return False, "           Could not parse XML value: %s\n" % (value,)
                value = tostring(tree.getroot())
            return value
示例#18
0
    def __str__(self):
        tree = ElementTree()
        tree.parse(self.exc)

        for elem in tree.iter():
            if elem.tag == "msg":
                err_msg = elem.text

        return "".join(["\n", str(self.exc), "\nAPI Error Message: ", err_msg])
示例#19
0
 def writerow(self, row):
     root = Element(u'row')
     if self.id_col:
         root.attrib[u'_id'] = unicode(row[0])
         row = row[1:]
     for k, v in zip(self.columns, row):
         self._insert_node(root, k, v)
     ElementTree(root).write(self.response, encoding=u'utf-8')
     self.response.write(b'\n')
示例#20
0
 def set_game_info(self, info):
     self.info = info
     tree = ElementTree()
     tree.parse(info["path"])
     link_node = tree.find("link")
     if link_node is not None:
         self.link_field.set_text(link_node.text.strip())
     else:
         self.link_field.set_text("")
示例#21
0
def parse_xml(source):
    '''Return an ElementTree.

    Includes comments and processing instructions.
    '''
    tree = ElementTree()
    pdk_parser = PDKXMLTreeBuilder()
    tree.parse(source, pdk_parser)
    return tree
示例#22
0
 def __init__(self):
     # Check service provider database file exists
     try:
         tree = ElementTree(file=PROVIDERS_PATH)
     except (IOError, SyntaxError), e:
         msg = ("Mobile broadband provider database: Could not read "
                "provider information %s error=%s") % (PROVIDERS_PATH, e)
         logging.warning(msg)
         raise ServiceProvidersError(msg)
示例#23
0
    def dowaitcount(self, original_request, collection, count, label=""):

        hrefs = []
        for _ignore in range(self.manager.server_info.waitcount):
            req = request(self.manager)
            req.method = "PROPFIND"
            req.host = original_request.host
            req.port = original_request.port
            req.ruris.append(collection[0])
            req.ruri = collection[0]
            req.headers["Depth"] = "1"
            if len(collection[1]):
                req.user = collection[1]
            if len(collection[2]):
                req.pswd = collection[2]
            req.data = data(self.manager)
            req.data.value = """<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:">
<D:prop>
<D:getetag/>
</D:prop>
</D:propfind>
"""
            req.data.content_type = "text/xml"
            result, _ignore_resulttxt, response, respdata = self.dorequest(req, False, False, label="%s | %s %d" % (label, "WAITCOUNT", count))
            hrefs = []
            if result and (response is not None) and (response.status == 207) and (respdata is not None):
                tree = ElementTree(file=StringIO(respdata))

                for response in tree.findall("{DAV:}response"):
                    href = response.findall("{DAV:}href")[0]
                    if href.text.rstrip("/") != collection[0].rstrip("/"):
                        hrefs.append(href.text)

                if len(hrefs) == count:
                    return True, None
            delay = self.manager.server_info.waitdelay
            starttime = time.time()
            while (time.time() < starttime + delay):
                pass

        if self.manager.debug and hrefs:
            # Get the content of each resource
            rdata = ""
            for href in hrefs:
                result, respdata = self.doget(req, (href, collection[1], collection[2],), label)
                test = "unknown"
                if respdata.startswith("BEGIN:VCALENDAR"):
                    uid = respdata.find("UID:")
                    if uid != -1:
                        uid = respdata[uid + 4:uid + respdata[uid:].find("\r\n")]
                        test = self.uidmaps.get(uid, "unknown")
                rdata += "\n\nhref: {h}\ntest: {t}\n\n{r}\n".format(h=href, t=test, r=respdata)

            return False, rdata
        else:
            return False, len(hrefs)
示例#24
0
文件: writer.py 项目: cbaehr/ckan
 def write_records(self, records):
     for r in records:
         root = Element(u'row')
         if self.id_col:
             root.attrib[u'_id'] = unicode(r[u'_id'])
         for c in self.columns:
             self._insert_node(root, c, r[c])
         ElementTree(root).write(self.response, encoding=u'utf-8')
         self.response.write(b'\n')
示例#25
0
def tweaked_parse_cdb_lu(file, graph, verbose=False):
    """
    tweaked version of parser._parse_cdb_lu which also returns the element tree
    for the lexical units
    """
    parser = iterparse(file)
    form2lu, c_lu_id2lu = _parse_lex_units(parser, graph, verbose)
    lu_etree = ElementTree(parser.root)
    return form2lu, c_lu_id2lu, lu_etree
示例#26
0
def get_categories_from_pmid(pmid):
    """
    Gets MeSH headings, returns those not deemed too broad.
    """
    if not type(pmid) == int:
        raise TypeError, "Cannot get Categories for PMID %s of type %s." % (pmid, type(pmid))
    url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=%s&retmode=xml' % pmid
    xml_file = _get_file_from_url(url)
    tree = ElementTree()
    tree.parse(xml_file)
    categories = []
    for heading in tree.iterfind('PubmedArticle/MedlineCitation/MeshHeadingList/MeshHeading'):
        htree = ElementTree(heading)
        descriptor_text = htree.find('DescriptorName').text
        if (htree.find('QualifierName') is not None) or \
            (' ' in descriptor_text and not 'and' in descriptor_text):
            categories.append(descriptor_text)
    return categories
示例#27
0
    def write(self, file):
        """
        write(file) -> None

        Write XML to filename of file object in 'file'
        """
        if DEBUG >= 0: print "in write(self, file)"
        et = ElementTree(self.root)
        et.write(file)
示例#28
0
 def _loadFile(fname, ignore_root=True):
     # Open and parse the config file
     try:
         tree = ElementTree(file=fname)
     except ExpatError, e:
         raise RuntimeError("Unable to parse file '%s' because: %s" % (
             fname,
             e,
         ))
示例#29
0
 def get_username(self, path):
     xml_file = os.path.join(path, 'shared.xml')
     if os.path.exists(xml_file):
         tree = ElementTree(file=xml_file)
         username = tree.find('Lib/Account/Default')
         try:
             return username.text
         except Exception:
             pass
示例#30
0
    def write(self, file):
        """
        write(file) -> None

        Write XML to filename of file object in 'file'
        """
        logger.log(9, 'write(file=%r)', file)
        et = ElementTree(self.root)
        et.write(file)