Example #1
0
    def _load_by_sid(self, shortid):
        """
        Can return multiple
        :type shortid: str
        :rtype msdn.document.MsdnFunction
        """
        rv = []
        func = MsdnFunction(shortid)
        logging.debug(func)
        cur = self.conn.cursor()

        cur.execute(
            "select fid, name, decorated, dll, rva, shortid from Function, Shortid where ShortId.shortid=? and Function.sid=ShortId.sid",
            (shortid,))
        rows = cur.fetchall()
        if not rows:
            logging.debug("cache miss")
            rv.append(func)
            return rv

        for row in rows:
            func = MsdnFunction(shortid)
            func.name = row["name"]
            func.decorated = row["decorated"]
            func.dll = row["dll"]
            func.rva = row["rva"]
            func.shortid = row["shortid"]
            fid = row["fid"]

            cur.execute(
                "select Locale, Version, Alt.scid, Src.scid, code from Alternate as Alt, SourceCode as Src where fid=? and Alt.scid=Src.scid",
                (fid,))
            alts = cur.fetchall()
            if not alts:
                logging.debug("no alternate versions of function %s" % func)
                return MsdnFunction(shortid)

            for alt in alts:
                logging.debug("func %s alternate %s" % (func, ",".join(str(i) for i in iter(alt))))
                func.add_code_snippet(func.name, alt["locale"], alt["version"], alt["code"], func.dll)

            rv.append(func)

        cur.close()
        return rv
Example #2
0
    def _load_by_name(self, name):
        """
        Returns one
        :type name:str
        :param name:undecorated function name
        :rtype msdn.document.MsdnFunction
        """
        func = MsdnFunction()
        logging.debug(name)
        cur = self.conn.cursor()
        cur.execute("select fid, name, decorated, dll, rva, sid from Function where name=?", (name,))
        row = cur.fetchone()
        if not row:
            logging.debug("cache miss")
            return MsdnFunction()

        func.name = row["name"]
        func.decorated = row["decorated"]
        func.dll = row["dll"]
        func.rva = row["rva"]
        sid = row["sid"]

        cur.execute("select shortid from ShortId where sid=?", (sid,))
        row = cur.fetchone()
        if not row:
            logging.debug("no ShortID found: %s" % func)
            return MsdnFunction()

        func.shortid = row["shortid"]
        return func
Example #3
0
def scrape_update(msdn_id):
    """

    Creates a Function from function ID then parses the responses from the MTPS web service. First, it gets the
    alternate forms based on version and locale. For each version it requests the XHTML primary document, which is then
    parsed for the code snippets and parent dll. The result is printed to stdout.

    :param msdn_id: Named tuple of MsdnId type to maintain single function argument
    :type msdn_id: MsdnId
    :rtype list
    """
    msdn_shortid = msdn_id.sid
    names = msdn_id.names
    logging.debug(msdn_shortid)
    msfunc = MsdnFunction(msdn_shortid)
    msfunc.fetch_code_snippets()
    logging.debug("Found %s code snippets" % len(msfunc.snippets))
    for name in names:
        msfunc.name = name
        if CACHE_RESULT:
            CODECACHE.save(msfunc)
    return msfunc.snippets