Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.6 / 3....
  • Linux Kernel 3.0.82 LTS...
  • KDE Software Compilatio...
  • PulseAudio 4.0
  • Wireshark 1.10.0
  • NetworkManager 0.9.8.2
  • LibreOffice 3.6.6 / 4.0...
  • SystemRescueCd 3.7.0
  • Linux Kernel 3.10 RC6
  • Ubuntu Tweak 0.8.5
  • Home > Linux > Programming > Libraries

    seven 1.0.0

    Download button

    No screenshots available
    Downloads: 156  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Attila Olah | More programs
    Python License / FREE
    February 6th, 2012, 05:39 GMT [view history]
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    seven description

    Python 2.5 compatibility wrapper for Python 2.7 code

    seven is a Python 2.6+ compatibility layer for Python 2.5. It allows you to import Python 2.6 or 2.7 code in a 2.5 interpreter. It is mainly intended to be used on Google App Engine.

    Basic usage

    Before importing non-compatible code, you need to start the seven import hook by calling seven.start():

    >>> import seven
    >>> seven.start()

    >>> import incompatible.modules

    >>> seven.stop() # optional


    The above will install an import hook and preprocess all modules before importing them using lib2to3 from the Python 2.7 stdlib. The installed hook will process all imported python modules until you call seven.stop(). If you don't stop it, all imports will be processed.

    Import whitelists

    Preprocessing all imported modules might not always be a good idea, mainly for two reasons. Firs, it comes with a slight performance penalty. Second, more important reason is that exceptions raised in modules that have been processed by the import hook can be really hard to debug. Line numbers are usually wrong, and the filename is not displayed correctly. These things might be improved in the future, but for now it is advised that only the necessary modules be processed.

    The following example will only preprocess the modules foo, spam.eggs and their submodules, foo.* and spam.eggs.*:

    >>> seven.start(['foo', 'spam.eggs'])

    What gets fixed?

    Of course, not all fixers have been implemented yet. The following features are available (without using from __future__ imports):

    - with statement (from __future__ import with_statement)
    - absolute imports (from __future__ import absolute_imports)
    - integer division (from __future__ import division)
    - class decorators

    Class decorators are converted like this:

    @decorated
    class C:
     pass


    becomes:

    class C:
     pass
    C = decorated(C)


    How to disable logging and pickling?

    On certain production environments, logging might not be very useful, or writing files might not be possible (e.g. App Engine). To disable logging or writing pickle dumps, create a module named sevenconfig and add the log = False or speedups = False globals (or both). Make sure the module is importable before importing seven.

    What needs to be implemented?

    The following features do not have fixers yet:

    - indented class decorators
    - except Exception as e:
    - advanced string formatting
    - print as a function
    - set literals
    - dict and set comprehensions
    - multiple context managers in one with statement
    - etc.

    How to write fixers?

    By subclassing seven.lib2to3.fixer_base.BaseFix. You can also fork this project on GitHub, have a look at the existing fixers in src/seven/fixes and add your own, thend send me a pull request.


    Product's homepage

    Requirements:

    · Python

    What's New in This Release: [ read full changelog ]

    · Logging and pickling can now be turned off.

      


    TAGS:

    compatibility wrapper | Python library | Python | compatibility | wrapper

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM