Did I find the right examples for you? yes no

All Samples(52)  |  Call(52)  |  Derive(0)  |  Import(0)
Reads large blocks in a safe way.  Unlike fp.read(n), this function
doesn't trust the user.  If the requested size is larger than
SAFEBLOCK, the file is read block by block.

:param fp: File handle.  Must implement a <b>read</b> method.
:param size: Number of bytes to read.
:returns: A string containing up to <i>size</i> bytes of data.

        def _safe_read(fp, size):
    """
    Reads large blocks in a safe way.  Unlike fp.read(n), this function
    doesn't trust the user.  If the requested size is larger than
    SAFEBLOCK, the file is read block by block.

    :param fp: File handle.  Must implement a read method.
    :param size: Number of bytes to read.
    :returns: A string containing up to size bytes of data.
    """
    if size <= 0:
        return b""
    if size <= SAFEBLOCK:
        return fp.read(size)
    data = []
    while size > 0:
        block = fp.read(min(size, SAFEBLOCK))
        if not block:
            break
        data.append(block)
        size = size - len(block)
    return b"".join(data)
        


src/a/n/antisocial-HEAD/ve/lib/python2.7/site-packages/PIL/PngImagePlugin.py   antisocial(Download)
            if cid == endchunk:
                break
            self.crc(cid, ImageFile._safe_read(self.fp, len))
            cids.append(cid)
 
    def chunk_iCCP(self, pos, len):
 
        # ICC profile
        s = ImageFile._safe_read(self.fp, len)
        # according to PNG spec, the iCCP chunk contains:
    def chunk_IHDR(self, pos, len):
 
        # image header
        s = ImageFile._safe_read(self.fp, len)
        self.im_size = i32(s), i32(s[4:])
    def chunk_PLTE(self, pos, len):
 
        # palette
        s = ImageFile._safe_read(self.fp, len)
        if self.im_mode == "P":
    def chunk_tRNS(self, pos, len):
 
        # transparency
        s = ImageFile._safe_read(self.fp, len)
        if self.im_mode == "P":

src/p/i/Pillow-2.4.0/PIL/PngImagePlugin.py   Pillow(Download)
            if cid == endchunk:
                break
            self.crc(cid, ImageFile._safe_read(self.fp, len))
            cids.append(cid)
 
    def chunk_iCCP(self, pos, len):
 
        # ICC profile
        s = ImageFile._safe_read(self.fp, len)
        # according to PNG spec, the iCCP chunk contains:
    def chunk_IHDR(self, pos, len):
 
        # image header
        s = ImageFile._safe_read(self.fp, len)
        self.im_size = i32(s), i32(s[4:])
    def chunk_PLTE(self, pos, len):
 
        # palette
        s = ImageFile._safe_read(self.fp, len)
        if self.im_mode == "P":
    def chunk_tRNS(self, pos, len):
 
        # transparency
        s = ImageFile._safe_read(self.fp, len)
        if self.im_mode == "P":

src/p/i/Pillow-HEAD/PIL/PngImagePlugin.py   Pillow(Download)
            if cid == endchunk:
                break
            self.crc(cid, ImageFile._safe_read(self.fp, len))
            cids.append(cid)
 
    def chunk_iCCP(self, pos, len):
 
        # ICC profile
        s = ImageFile._safe_read(self.fp, len)
        # according to PNG spec, the iCCP chunk contains:
    def chunk_IHDR(self, pos, len):
 
        # image header
        s = ImageFile._safe_read(self.fp, len)
        self.im_size = i32(s), i32(s[4:])
    def chunk_PLTE(self, pos, len):
 
        # palette
        s = ImageFile._safe_read(self.fp, len)
        if self.im_mode == "P":
    def chunk_tRNS(self, pos, len):
 
        # transparency
        s = ImageFile._safe_read(self.fp, len)
        if self.im_mode == "P":

src/a/n/antisocial-HEAD/ve/lib/python2.7/site-packages/PIL/JpegImagePlugin.py   antisocial(Download)
def Skip(self, marker):
    n = i16(self.fp.read(2))-2
    ImageFile._safe_read(self.fp, n)
 
def APP(self, marker):
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
 
    app = "APP%d" % (marker&15)
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
 
    self.app["COM"] = s # compatibility
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
    self.size = i16(s[3:]), i16(s[1:])
 
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
    while len(s):
        if len(s) < 65:

src/p/i/Pillow-2.4.0/PIL/JpegImagePlugin.py   Pillow(Download)
def Skip(self, marker):
    n = i16(self.fp.read(2))-2
    ImageFile._safe_read(self.fp, n)
 
def APP(self, marker):
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
 
    app = "APP%d" % (marker&15)
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
 
    self.app["COM"] = s # compatibility
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
    self.size = i16(s[3:]), i16(s[1:])
 
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
    while len(s):
        if len(s) < 65:

src/p/i/Pillow-HEAD/PIL/JpegImagePlugin.py   Pillow(Download)
def Skip(self, marker):
    n = i16(self.fp.read(2))-2
    ImageFile._safe_read(self.fp, n)
 
def APP(self, marker):
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
 
    app = "APP%d" % (marker&15)
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
 
    self.app["COM"] = s # compatibility
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
    self.size = i16(s[3:]), i16(s[1:])
 
 
    n = i16(self.fp.read(2))-2
    s = ImageFile._safe_read(self.fp, n)
    while len(s):
        if len(s) < 65:

src/a/n/antisocial-HEAD/ve/lib/python2.7/site-packages/PIL/BmpImagePlugin.py   antisocial(Download)
        # CORE/INFO
        s = read(4)
        s = s + ImageFile._safe_read(self.fp, i32(s)-4)
 
        if len(s) == 12:

src/p/i/Pillow-2.4.0/PIL/BmpImagePlugin.py   Pillow(Download)
        # CORE/INFO
        s = read(4)
        s = s + ImageFile._safe_read(self.fp, i32(s)-4)
 
        if len(s) == 12:

src/p/i/Pillow-HEAD/PIL/BmpImagePlugin.py   Pillow(Download)
        # CORE/INFO
        s = read(4)
        s = s + ImageFile._safe_read(self.fp, i32(s)-4)
 
        if len(s) == 12:

src/a/n/antisocial-HEAD/ve/lib/python2.7/site-packages/PIL/TiffImagePlugin.py   antisocial(Download)
                here = fp.tell()
                fp.seek(i32(ifd, 8))
                data = ImageFile._safe_read(fp, size)
                fp.seek(here)
            else:

  1 | 2  Next