~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to .pc/git-updates.diff/PIL/BufrStubImagePlugin.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (1.1.4)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130131204920-7tnuhqhlsqdza4c2
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# The Python Imaging Library
 
3
# $Id$
 
4
#
 
5
# BUFR stub adapter
 
6
#
 
7
# Copyright (c) 1996-2003 by Fredrik Lundh
 
8
#
 
9
# See the README file for information on usage and redistribution.
 
10
#
 
11
 
 
12
import Image, ImageFile
 
13
 
 
14
_handler = None
 
15
 
 
16
##
 
17
# Install application-specific BUFR image handler.
 
18
#
 
19
# @param handler Handler object.
 
20
 
 
21
def register_handler(handler):
 
22
    global _handler
 
23
    _handler = handler
 
24
 
 
25
# --------------------------------------------------------------------
 
26
# Image adapter
 
27
 
 
28
def _accept(prefix):
 
29
    return prefix[:4] == "BUFR" or prefix[:4] == "ZCZC"
 
30
 
 
31
class BufrStubImageFile(ImageFile.StubImageFile):
 
32
 
 
33
    format = "BUFR"
 
34
    format_description = "BUFR"
 
35
 
 
36
    def _open(self):
 
37
 
 
38
        offset = self.fp.tell()
 
39
 
 
40
        if not _accept(self.fp.read(8)):
 
41
            raise SyntaxError("Not a BUFR file")
 
42
 
 
43
        self.fp.seek(offset)
 
44
 
 
45
        # make something up
 
46
        self.mode = "F"
 
47
        self.size = 1, 1
 
48
 
 
49
        loader = self._load()
 
50
        if loader:
 
51
            loader.open(self)
 
52
 
 
53
    def _load(self):
 
54
        return _handler
 
55
 
 
56
def _save(im, fp, filename):
 
57
    if _handler is None or not hasattr("_handler", "save"):
 
58
        raise IOError("BUFR save handler not installed")
 
59
    _handler.save(im, fp, filename)
 
60
 
 
61
 
 
62
# --------------------------------------------------------------------
 
63
# Registry
 
64
 
 
65
Image.register_open(BufrStubImageFile.format, BufrStubImageFile, _accept)
 
66
Image.register_save(BufrStubImageFile.format, _save)
 
67
 
 
68
Image.register_extension(BufrStubImageFile.format, ".bufr")