Esempio n. 1
0
 def png_fetch(self, ucid, seq=1):
     log.info(
         u"{backend_name}: png_fetch, ucid={ucid}, seq={seq}; user={username}"
         .format(ucid=ucid, seq=seq, **self.__dict__))
     tif = self.tif_fetch(ucid, seq)
     if tif:
         png = to_png(tif)
         return png
Esempio n. 2
0
def get_drawing_png(document, page, kind):

    # 2. Try to fetch drawing from OPS, fall back to other patent offices
    try:
        payload = get_ops_image(document, page, kind, 'tiff')

    except HTTPNotFound:

        # fallback to USPTO (U.S.)
        if document.upper().startswith('US'):
            document_id = normalize_patent(split_patent_number(document),
                                           for_ops=False)
            try:
                payload = get_uspto_image_cached(document_id)
            except PayloadEmpty as ex:
                raise HTTPNotFound(
                    'No drawing for "{0}" at OPS or USPTO'.format(document))

        # fallback to CIPO (Canada)
        elif document.upper().startswith('CA'):
            document_id = split_patent_number(document)
            try:
                payload = get_cipo_image_cached(document_id)
            except PayloadEmpty as ex:
                raise HTTPNotFound(
                    'No drawing for "{0}" at OPS or CIPO'.format(document))

        # otherwise, pass through exception
        else:
            raise

    # 3. Croak if no image available
    if not payload:
        msg = 'No image available for document={document}, kind={kind}, page={page}'.format(
            **locals())
        log.warn(msg)
        raise HTTPNotFound(msg)

    # 4. Convert image from TIFF to PNG format
    payload = to_png(BytesIO(payload))

    return payload