This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description
byteplay lets you convert Python code objects into equivalent objects which are easy to play with, and lets you convert those objects back into Python code objects. It's useful for applying transformations on Python functions, and is also useful in learning Python byte code intricacies. This version works with Python 3.4 and 3.5.

For the full documentation see the "about" file located at
https://github.com/tallforasmurf/byteplay/blob/master/about.md

About byteplay
--------------------

byteplay3 is a module which lets you easily play with Python bytecode.
The basic idea is simple: define a new type named Code which is equivalent
to Python code objects, but Code objects, unlike Python code objects,
are easy to play with. Any Python code object can be converted to
a Code object, and vice-versa, without losing any important information.
Within a Code object, the bytecode instructions are represented in a
way that is easy to examine and modify.

Compatibility
----------------

This module, byteplay3, is based on the original by Noam Raph, which
is still available from pypi. If you have code that used byteplay under
Python 2, you can migrate to Python 3 just by changing your import line
to read "from byteplay3 import *". For minor incompatibilities, see the
"about" file linked above. Of course you will find more than minor
incompatibilities in Python 3's bytecode, which is considerably changed.

A Quick Example
---------------

Start with a silly function, convert its code to a Code object and display it::

>>> def f(a, b):
... print(a, b)
...
>>> f(3, 5)
3 5
>>> from byteplay3 import *
>>> # convert the code object of function f to a Code object
>>> c = Code.from_code(f.__code__)
>>> c
<byteplay3.code object="" at="" 0x1030da3c8="">
>>> # display the bytecode tuples in the Code object
>>> print( c.code )
2 1 LOAD_GLOBAL print
2 LOAD_FAST a
3 LOAD_FAST b
4 CALL_FUNCTION 2
5 POP_TOP
6 LOAD_CONST None
7 RETURN_VALUE

Ok, now let's play! Say we want to change the function so it prints its
arguments in reverse order. To do this, we will insert a ROT_TWO opcode
after the two arguments were loaded to the stack. (That is, after
LOAD_FAST b and before CALL_FUNCTION 2.)::

>>> c.code[4:4] = [(ROT_TWO,None)]

Then replace the code object in function f with a new one::

>>> f.__code__ = c.to_code()
>>> f(3,5)
5 3
Release History

Release History

3.5.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
byteplay3-3.5.0.tar.gz (23.4 kB) Copy SHA256 Checksum SHA256 Source Feb 5, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting