File: interp_md5.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (59 lines) | stat: -rw-r--r-- 1,659 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from rpython.rlib import rmd5
from rpython.rlib.objectmodel import import_from_mixin
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.typedef import TypeDef
from pypy.interpreter.gateway import interp2app, unwrap_spec


class W_MD5(W_Root):
    """
    A subclass of RMD5 that can be exposed to app-level.
    """
    import_from_mixin(rmd5.RMD5)

    def __init__(self, space):
        self.space = space
        self._init()

    @unwrap_spec(string='bufferstr')
    def update_w(self, string):
        self.update(string)

    def digest_w(self):
        return self.space.newbytes(self.digest())

    def hexdigest_w(self):
        return self.space.newtext(self.hexdigest())

    def copy_w(self):
        clone = W_MD5(self.space)
        clone._copyfrom(self)
        return clone


@unwrap_spec(initialdata='bufferstr', usedforsecurity=bool)
def W_MD5___new__(space, w_subtype, initialdata='', usedforsecurity=True):
    """
    Create a new md5 object and call its initializer.
    """
    w_md5 = space.allocate_instance(W_MD5, w_subtype)
    md5 = space.interp_w(W_MD5, w_md5)
    W_MD5.__init__(md5, space)
    # Ignore usedforsecurity
    md5.update(initialdata)
    return w_md5


W_MD5.typedef = TypeDef(
    '_md5_md5',
    __new__   = interp2app(W_MD5___new__),
    update    = interp2app(W_MD5.update_w),
    digest    = interp2app(W_MD5.digest_w),
    hexdigest = interp2app(W_MD5.hexdigest_w),
    copy      = interp2app(W_MD5.copy_w),
    digest_size = 16,
    block_size = 64,
    name      = 'md5',
    __doc__   = """md5(arg) -> return new md5 object.

If arg is present, the method call update(arg) is made.""")