Python md5.md5() Examples

The following are 30 code examples of md5.md5(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module md5 , or try the search function .
Example #1
Source File: main.py    From oabot with MIT License 6 votes vote down vote up
def __init__(self, tpl, page):
        """
        :param tpl: a mwparserfromhell template: the original template
                that we want to change
        """
        self.template = tpl
        self.orig_string = unicode(self.template)
        r = md5.md5()
        r.update(self.orig_string.encode('utf-8'))
        self.orig_hash = r.hexdigest()
        self.classification = None
        self.conflicting_value = ''
        self.proposed_change = ''
        self.proposed_link = None
        self.index = None
        self.page = page
        self.proposed_link_policy = None
        self.issn = None 
Example #2
Source File: addon.py    From Kodi with GNU Lesser General Public License v3.0 6 votes vote down vote up
def _get_video(self, sid, eid, ehash):
        myhash = hashlib.md5(
            str(self.client.token) + \
            str(eid) + \
            str(sid) + \
            str(ehash)
        ).hexdigest()

        data = {
            "eid": eid,
            "hash": myhash
        }
        result = self.client.request(self.PLAY_EPISODES_URL.format(eid=eid), data)

        if not isinstance(result, dict) or result.get("ok", 0) == 0:
            raise SoapException("Bad getting videolink")

        return result 
Example #3
Source File: mathmpl.py    From Computable with MIT License 6 votes vote down vote up
def latex2html(node, source):
    inline = isinstance(node.parent, nodes.TextElement)
    latex = node['latex']
    name = 'math-%s' % md5(latex.encode()).hexdigest()[-10:]

    destdir = os.path.join(setup.app.builder.outdir, '_images', 'mathmpl')
    if not os.path.exists(destdir):
        os.makedirs(destdir)
    dest = os.path.join(destdir, '%s.png' % name)
    path = os.path.join(setup.app.builder.imgpath, 'mathmpl')

    depth = latex2png(latex, dest, node['fontset'])

    if inline:
        cls = ''
    else:
        cls = 'class="center" '
    if inline and depth != 0:
        style = 'style="position: relative; bottom: -%dpx"' % (depth + 1)
    else:
        style = ''

    return '<img src="%s/%s.png" %s%s/>' % (path, name, cls, style) 
Example #4
Source File: modManager.py    From BombSquad-Community-Mod-Manager with The Unlicense 6 votes vote down vote up
def __init__(self, d):
        self.data = d
        self.author = d.get('author')
        if 'filename' in d:
            self.filename = d['filename']
            self.base = self.filename[:-3]
        else:
            raise RuntimeError('mod without filename')
        if 'name' in d:
            self.name = d['name']
        else:
            self.name = self.filename
        if 'md5' in d:
            self.md5 = d['md5']
        else:
            raise RuntimeError('mod without md5')

        self.changelog = d.get('changelog', [])
        self.old_md5s = d.get('old_md5s', [])
        self.category = d.get('category', None)
        self.requires = d.get('requires', [])
        self.supports = d.get('supports', [])
        self.tag = d.get('tag', None) 
Example #5
Source File: digest.py    From mishkal with GNU General Public License v3.0 6 votes vote down vote up
def compute(self, ha1, username, response, method,
                      path, nonce, nc, cnonce, qop):
        """ computes the authentication, raises error if unsuccessful """
        if not ha1:
            return self.build_authentication()
        ha2 = md5('%s:%s' % (method, path)).hexdigest()
        if qop:
            chk = "%s:%s:%s:%s:%s:%s" % (ha1, nonce, nc, cnonce, qop, ha2)
        else:
            chk = "%s:%s:%s" % (ha1, nonce, ha2)
        if response != md5(chk).hexdigest():
            if nonce in self.nonce:
                del self.nonce[nonce]
            return self.build_authentication()
        pnc = self.nonce.get(nonce,'00000000')
        if nc <= pnc:
            if nonce in self.nonce:
                del self.nonce[nonce]
            return self.build_authentication(stale = True)
        self.nonce[nonce] = nc
        return username 
Example #6
Source File: wsse.py    From suds-py3 with GNU Lesser General Public License v3.0 6 votes vote down vote up
def setnonce(self, text=None):
        """
        Set I{nonce} which is arbitraty set of bytes to prevent
        reply attacks.
        @param text: The nonce text value.
            Generated when I{None}.
        @type text: str
        """
        if text is None:
            s = []
            s.append(self.username)
            s.append(self.password)
            s.append(Token.sysdate())
            m = sha56()
            m.update(':'.join(s).encode("utf-8"))
            self.nonce = m.hexdigest()
        else:
            self.nonce = text 
Example #7
Source File: downloader.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def md5_hexdigest(file):
    """
    Calculate and return the MD5 checksum for a given file.
    ``file`` may either be a filename or an open stream.
    """
    if isinstance(file, basestring):
        file = open(file, 'rb')

    md5_digest = md5()
    while True:
        block = file.read(1024*16) # 16k blocks
        if not block: break
        md5_digest.update(block)
    return md5_digest.hexdigest()

# change this to periodically yield progress messages?
# [xx] get rid of topdir parameter -- we should be checking
# this when we build the index, anyway. 
Example #8
Source File: mathmpl.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def latex2html(node, source):
    inline = isinstance(node.parent, nodes.TextElement)
    latex = node['latex']
    name = 'math-%s' % md5(latex.encode()).hexdigest()[-10:]

    destdir = os.path.join(setup.app.builder.outdir, '_images', 'mathmpl')
    if not os.path.exists(destdir):
        os.makedirs(destdir)
    dest = os.path.join(destdir, '%s.png' % name)
    path = os.path.join(setup.app.builder.imgpath, 'mathmpl')

    depth = latex2png(latex, dest, node['fontset'])

    if inline:
        cls = ''
    else:
        cls = 'class="center" '
    if inline and depth != 0:
        style = 'style="position: relative; bottom: -%dpx"' % (depth + 1)
    else:
        style = ''

    return '<img src="%s/%s.png" %s%s/>' % (path, name, cls, style) 
Example #9
Source File: ez_setup.py    From clonedigger with GNU General Public License v3.0 5 votes vote down vote up
def _validate_md5(egg_name, data):
    if egg_name in md5_data:
        from md5 import md5
        digest = md5(data).hexdigest()
        if digest != md5_data[egg_name]:
            print((
                "md5 validation of %s failed!  (Possible download problem?)"
                % egg_name
            ), file=sys.stderr)
            sys.exit(2)
    return data 
Example #10
Source File: fontfinder.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def _getCacheFileName(self):
        """Base this on the directories...same set of directories
        should give same cache"""
        hash = md5(''.join(self._dirs)).hexdigest()
        from reportlab.lib.utils import get_rl_tempfile
        fn = get_rl_tempfile('fonts_%s.dat' % hash)
        return fn 
Example #11
Source File: ez_setup.py    From clonedigger with GNU General Public License v3.0 5 votes vote down vote up
def update_md5(filenames):
    """Update our built-in md5 registry"""

    import re
    from md5 import md5

    for name in filenames:
        base = os.path.basename(name)
        f = open(name,'rb')
        md5_data[base] = md5(f.read()).hexdigest()
        f.close()

    data = ["    %r: %r,\n" % it for it in list(md5_data.items())]
    data.sort()
    repl = "".join(data)

    import inspect
    srcfile = inspect.getsourcefile(sys.modules[__name__])
    f = open(srcfile, 'rb'); src = f.read(); f.close()

    match = re.search("\nmd5_data = {\n([^}]+)}", src)
    if not match:
        print("Internal error!", file=sys.stderr)
        sys.exit(2)

    src = src[:match.start(1)] + repl + src[match.end(1):]
    f = open(srcfile,'w')
    f.write(src)
    f.close() 
Example #12
Source File: modManager.py    From BombSquad-Community-Mod-Manager with The Unlicense 5 votes vote down vote up
def checkUpdate(self):
        if not self.is_installed():
            return False
        if self.local_md5() != self.md5:
            return True
        return False 
Example #13
Source File: yacc.py    From SRL-Python with MIT License 5 votes vote down vote up
def signature(self):
        try:
            from hashlib import md5
        except ImportError:
            from md5 import md5
        try:
            sig = md5()
            if self.start:
                sig.update(self.start.encode('latin-1'))
            if self.prec:
                sig.update(''.join([''.join(p) for p in self.prec]).encode('latin-1'))
            if self.tokens:
                sig.update(' '.join(self.tokens).encode('latin-1'))
            for f in self.pfuncs:
                if f[3]:
                    sig.update(f[3].encode('latin-1'))
        except (TypeError, ValueError):
            pass

        digest = base64.b16encode(sig.digest())
        if sys.version_info[0] >= 3:
            digest = digest.decode('latin-1')
        return digest

    # -----------------------------------------------------------------------------
    # validate_modules()
    #
    # This method checks to see if there are duplicated p_rulename() functions
    # in the parser module file.  Without this function, it is really easy for
    # users to make mistakes by cutting and pasting code fragments (and it's a real
    # bugger to try and figure out why the resulting parser doesn't work).  Therefore,
    # we just do a little regular expression pattern matching of def statements
    # to try and detect duplicates.
    # ----------------------------------------------------------------------------- 
Example #14
Source File: inheritance_diagram.py    From cyipopt with Eclipse Public License 1.0 5 votes vote down vote up
def get_graph_hash(node):
    return md5(node['content'] + str(node['parts'])).hexdigest()[-10:] 
Example #15
Source File: yacc.py    From MARA_Framework with GNU Lesser General Public License v3.0 5 votes vote down vote up
def signature(self):
        try:
            from hashlib import md5
        except ImportError:
            from md5 import md5
        try:
            sig = md5()
            if self.start:
                sig.update(self.start.encode('latin-1'))
            if self.prec:
                sig.update(''.join([''.join(p) for p in self.prec]).encode('latin-1'))
            if self.tokens:
                sig.update(' '.join(self.tokens).encode('latin-1'))
            for f in self.pfuncs:
                if f[3]:
                    sig.update(f[3].encode('latin-1'))
        except (TypeError, ValueError):
            pass

        digest = base64.b16encode(sig.digest())
        if sys.version_info[0] >= 3:
            digest = digest.decode('latin-1')
        return digest

    # -----------------------------------------------------------------------------
    # validate_modules()
    #
    # This method checks to see if there are duplicated p_rulename() functions
    # in the parser module file.  Without this function, it is really easy for
    # users to make mistakes by cutting and pasting code fragments (and it's a real
    # bugger to try and figure out why the resulting parser doesn't work).  Therefore,
    # we just do a little regular expression pattern matching of def statements
    # to try and detect duplicates.
    # ----------------------------------------------------------------------------- 
Example #16
Source File: pdfdocument.py    From ParanoiDF with GNU General Public License v3.0 5 votes vote down vote up
def decrypt_rc4(self, objid, genno, data):
        key = self.decrypt_key + struct.pack('<L', objid)[:3]+struct.pack('<L', genno)[:2]
        hash = md5.md5(key)
        key = hash.digest()[:min(len(key), 16)]
        return Arcfour(key).process(data) 
Example #17
Source File: auto_reloader.py    From BombSquad-Community-Mod-Manager with The Unlicense 5 votes vote down vote up
def __init__(self, filename):
		self._filename = filename
		with open(IMPORT_FOLDER + self._filename, "r") as f:
			self._module_md5 = md5(f.read()).hexdigest()
		self._did_print_error = False
		self._import_module()
		if self._is_available() and self._type == "game":
			self._game = self._module.bsGetGames()[0]
		else:
			self._game = None 
Example #18
Source File: auto_reloader.py    From BombSquad-Community-Mod-Manager with The Unlicense 5 votes vote down vote up
def _reload_module(self):
		bs.screenMessage("reloading " + self._filename)
		self._prepare_reload()
		self._import_module()
		#self._module = import_module(self._filename[:-3], package=IMPORT_FOLDER.split("/")[-2])
		with open(IMPORT_FOLDER + self._filename, "r") as f:
			self._module_md5 = md5(f.read()).hexdigest()
		self._did_print_error = False
		if self._is_available() and self._type == "game":
			self._game = self._module.bsGetGames()[0]
		else:
			self._game = None
		bs.playSound(bs.getSound('swish')) 
Example #19
Source File: ez_setup.py    From clonedigger with GNU General Public License v3.0 5 votes vote down vote up
def update_md5(filenames):
    """Update our built-in md5 registry"""

    import re
    from md5 import md5

    for name in filenames:
        base = os.path.basename(name)
        f = open(name,'rb')
        md5_data[base] = md5(f.read()).hexdigest()
        f.close()

    data = ["    %r: %r,\n" % it for it in list(md5_data.items())]
    data.sort()
    repl = "".join(data)

    import inspect
    srcfile = inspect.getsourcefile(sys.modules[__name__])
    f = open(srcfile, 'rb'); src = f.read(); f.close()

    match = re.search("\nmd5_data = {\n([^}]+)}", src)
    if not match:
        print("Internal error!", file=sys.stderr)
        sys.exit(2)

    src = src[:match.start(1)] + repl + src[match.end(1):]
    f = open(srcfile,'w')
    f.write(src)
    f.close() 
Example #20
Source File: ez_setup.py    From clonedigger with GNU General Public License v3.0 5 votes vote down vote up
def _validate_md5(egg_name, data):
    if egg_name in md5_data:
        from md5 import md5
        digest = md5(data).hexdigest()
        if digest != md5_data[egg_name]:
            print((
                "md5 validation of %s failed!  (Possible download problem?)"
                % egg_name
            ), file=sys.stderr)
            sys.exit(2)
    return data 
Example #21
Source File: cache.py    From pheme-twitter-conversation-collection with Apache License 2.0 5 votes vote down vote up
def _get_path(self, key):
        md5 = hashlib.md5()
        md5.update(key)
        return os.path.join(self.cache_dir, md5.hexdigest()) 
Example #22
Source File: markdown.py    From honeything with GNU General Public License v3.0 5 votes vote down vote up
def _do_link_patterns(self, text):
        """Caveat emptor: there isn't much guarding against link
        patterns being formed inside other standard Markdown links, e.g.
        inside a [link def][like this].

        Dev Notes: *Could* consider prefixing regexes with a negative
        lookbehind assertion to attempt to guard against this.
        """
        link_from_hash = {}
        for regex, repl in self.link_patterns:
            replacements = []
            for match in regex.finditer(text):
                if hasattr(repl, "__call__"):
                    href = repl(match)
                else:
                    href = match.expand(repl)
                replacements.append((match.span(), href))
            for (start, end), href in reversed(replacements):
                escaped_href = (
                    href.replace('"', '&quot;')  # b/c of attr quote
                        # To avoid markdown <em> and <strong>:
                        .replace('*', g_escape_table['*'])
                        .replace('_', g_escape_table['_']))
                link = '<a href="%s">%s</a>' % (escaped_href, text[start:end])
                hash = md5(link).hexdigest()
                link_from_hash[hash] = link
                text = text[:start] + hash + text[end:]
        for hash, link in link_from_hash.items():
            text = text.replace(hash, link)
        return text 
Example #23
Source File: cidfonts.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def _hash(self, text):
        hasher = md5()
        hasher.update(text)
        return hasher.digest() 
Example #24
Source File: Utils.py    From royal-chaos with MIT License 5 votes vote down vote up
def h_list(lst):
	m=md5()
	m.update(str(lst))
	return m.digest() 
Example #25
Source File: Utils.py    From royal-chaos with MIT License 5 votes vote down vote up
def h_file_win32(fname):
	try:
		fd=os.open(fname,os.O_BINARY|os.O_RDONLY|os.O_NOINHERIT)
	except OSError:
		raise IOError('Cannot read from %r'%fname)
	f=os.fdopen(fd,'rb')
	m=md5()
	try:
		while fname:
			fname=f.read(200000)
			m.update(fname)
	finally:
		f.close()
	return m.digest() 
Example #26
Source File: Utils.py    From royal-chaos with MIT License 5 votes vote down vote up
def h_file(fname):
	f=open(fname,'rb')
	m=md5()
	try:
		while fname:
			fname=f.read(200000)
			m.update(fname)
	finally:
		f.close()
	return m.digest() 
Example #27
Source File: yacc.py    From retdec-regression-tests-framework with MIT License 5 votes vote down vote up
def signature(self):
        try:
            from hashlib import md5
        except ImportError:
            from md5 import md5
        try:
            sig = md5()
            if self.start:
                sig.update(self.start.encode('latin-1'))
            if self.prec:
                sig.update(''.join([''.join(p) for p in self.prec]).encode('latin-1'))
            if self.tokens:
                sig.update(' '.join(self.tokens).encode('latin-1'))
            for f in self.pfuncs:
                if f[3]:
                    sig.update(f[3].encode('latin-1'))
        except (TypeError, ValueError):
            pass

        digest = base64.b16encode(sig.digest())
        if sys.version_info[0] >= 3:
            digest = digest.decode('latin-1')
        return digest

    # -----------------------------------------------------------------------------
    # validate_modules()
    #
    # This method checks to see if there are duplicated p_rulename() functions
    # in the parser module file.  Without this function, it is really easy for
    # users to make mistakes by cutting and pasting code fragments (and it's a real
    # bugger to try and figure out why the resulting parser doesn't work).  Therefore,
    # we just do a little regular expression pattern matching of def statements
    # to try and detect duplicates.
    # ----------------------------------------------------------------------------- 
Example #28
Source File: Utils.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def h_list(lst):
	m=md5()
	m.update(str(lst))
	return m.digest() 
Example #29
Source File: Utils.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def h_file_win32(fname):
	try:
		fd=os.open(fname,os.O_BINARY|os.O_RDONLY|os.O_NOINHERIT)
	except OSError:
		raise IOError('Cannot read from %r'%fname)
	f=os.fdopen(fd,'rb')
	m=md5()
	try:
		while fname:
			fname=f.read(200000)
			m.update(fname)
	finally:
		f.close()
	return m.digest() 
Example #30
Source File: Utils.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def h_file(fname):
	f=open(fname,'rb')
	m=md5()
	try:
		while fname:
			fname=f.read(200000)
			m.update(fname)
	finally:
		f.close()
	return m.digest()