src/reportlab/__init__.py
changeset 4260 58d91bf065e0
parent 4259 c740bbf613b9
child 4261 8ad30c29b9af
equal deleted inserted replaced
4259:c740bbf613b9 4260:58d91bf065e0
     3 __doc__="""The Reportlab PDF generation library."""
     3 __doc__="""The Reportlab PDF generation library."""
     4 Version = "3.3.3"
     4 Version = "3.3.3"
     5 __version__=Version
     5 __version__=Version
     6 __date__='20160330'
     6 __date__='20160330'
     7 
     7 
     8 import sys, os, imp
     8 import sys, os
     9 
     9 
    10 if sys.version_info[0:2]!=(2, 7) and sys.version_info<(3, 3):
    10 if sys.version_info[0:2]!=(2, 7) and sys.version_info<(3, 3):
    11     raise ImportError("""reportlab requires Python 2.7+ or 3.3+; 3.0-3.2 are not supported.""")
    11     raise ImportError("""reportlab requires Python 2.7+ or 3.3+; 3.0-3.2 are not supported.""")
    12 
    12 
    13 #define these early in reportlab's life
    13 #define these early in reportlab's life
    18 
    18 
    19     import builtins
    19     import builtins
    20     builtins.cmp = cmp
    20     builtins.cmp = cmp
    21     builtins.xrange = range
    21     builtins.xrange = range
    22     del cmp, builtins
    22     del cmp, builtins
       
    23     def _fake_import(fn,name):
       
    24         from importlib import machinery
       
    25         m = machinery.SourceFileLoader(name,fn)
       
    26         try:
       
    27             return m.load_module(name)
       
    28         except FileNotFoundError:
       
    29             raise ImportError('file %s not found' % ascii(fn))
    23 else:
    30 else:
    24     from future_builtins import ascii
    31     from future_builtins import ascii
    25     import __builtin__
    32     import __builtin__
    26     __builtin__.ascii = ascii
    33     __builtin__.ascii = ascii
    27     del ascii, __builtin__
    34     del ascii, __builtin__
       
    35     def _fake_import(fn,name):
       
    36         if os.path.isfile(fn):
       
    37             import imp
       
    38             with open(fn,'rb') as f:
       
    39                 imp.load_source(name,fn,f)
    28 
    40 
    29 #try to use dynamic modifications from
    41 #try to use dynamic modifications from
    30 #reportlab.local_rl_mods.py
    42 #reportlab.local_rl_mods.py
    31 #reportlab_mods.py or ~/.reportlab_mods
    43 #reportlab_mods.py or ~/.reportlab_mods
    32 try:
    44 try:
    33     import reportlab.local_rl_mods
    45     import reportlab.local_rl_mods
    34 except ImportError:
    46 except ImportError:
    35     pass
    47     pass
    36 
    48 
    37 def _fake_import(fn,name):
       
    38     if os.path.isfile(fn):
       
    39         with open(fn,'rb') as f:
       
    40             imp.load_source(name,fn,f)
       
    41 
       
    42 try:
    49 try:
    43     import reportlab_mods   #application specific modifications can be anywhere on python path
    50     import reportlab_mods   #application specific modifications can be anywhere on python path
    44 except ImportError:
    51 except ImportError:
    45     try:
    52     try:
    46         _fake_import(os.path.expanduser(os.path.join('~','.reportlab_mods')),'reportlab_mods')
    53         _fake_import(os.path.expanduser(os.path.join('~','.reportlab_mods')),'reportlab_mods')