Pyxa is a special subset of Python which is highly optimized for security and privacy. The syntax of the language is not modified from Python2.7. But, the runtime semantics are slightly different.
Built-in Data Structures
tuple are all supported.
In order to use global references, you have to define your variable like this:
a = "my value" global a @taxa.route("/my_url") def myFunc(): response.add(a)
Global references have to be explicitly declared. You can also do this:
a = "my value" @taxa.route("/my_url") def myFunc(): global a response.add(a)
Dynamic imports are not supported since tServices only support single file mode in the devnet. Besides that, the developer can only import the supported libraries mentioned below.
Warning: Importing an unsupported module will cause a run-time error.
In the devnet, each tService request and response cannot contain more than 8KB of data in the "data" section. For example:
@taxa.route("/my_url") def myFunc(): response.add("8KB OF DATA")
global h def h(): return h2() global h2 def h2(): return "h2 called" @taxa.route("/") def f(): response.add(h())
Helper functions also need to obey the global reference rules.
unicode()- Unicode string
str()- Non-Unicode string
long()- Long Integer
set()- Collections with automatically removed duplicates
list()- General collections. Unlike tuple, these collections can be extended after initializing. Individual items can also be changed.
bytearray()- Return a new array of bytes
float()- An integer with a decimal part
tuple()- A list that can't have its size changed after initialization. Often used as an optimized list.
bool()- Evaluates input to either
abs()- Absolute value
>>> abs(-3) 3 <<< abs(3) 3
divmod()- division with remainder
>>> divmod(7, 2) (3, 1)
input()- Not implemented
open()- Not implemented
staticmethod()- Turns a class method from an instance method into a method on the class itself. Usually used as a decorator. The method does not need the "self" argument.
class Test(object): def instance_method(self): return 'i' @staticmethod def static(): return 's' >>> t = Test() >>> t.instance_method() 'i' >>> t.static() 's' >>> Test.static() 's' >>> Test.instance_method() TypeError: instance_method() missing 1 required positional argument: 'self'
all()- Returns True if all the items passed in collection evaluate to True.
>>> all([1, 1, 1, 1, 1, 1]) True >>> all([1, 1, 1, 0, 1, 1]) False
enumerate()- Adds a ordinal to each item in an iterable. Most commonly used when iterating through a collection and you want to keep count while doing so.
>>> enumerate(['a', 'b', 'c']) [(0, 'a'), (1, 'b'), (2, 'c')]
ord()- The reverse of
chr(). Returns an integer corresponding to the passed in character.
any()- Similar to
all(), except it returns True if any item evaluates to True.
eval()- Not Implemented
isinstance()- Returns True if the first argument is an instance of the second argument (which should always be a class).
>>> isinstance(4, int) True
pow()- Raise first argument to the power of the second argument
>>> pow(3, 2) 9
sum()- Adds up all numbers in the collection passed in
>>> sum([1, 2, 3, 4, 5]) 15
basestring()- This abstract type is the superclass for
unicode. It cannot be called or instantiated, but it can be used to test whether an object is an instance of
isinstance(obj, basestring)is equivalent to
isinstance(obj, (str, unicode)).
execfile()- Not implemented
issubclass()- Return True if class is a subclass (direct, indirect or virtual) of classinfo. A class is considered a subclass of itself. classinfo may be a tuple of class objects, in which case every entry in classinfo will be checked. In any other case, a
TypeErrorexception is raised.
print()- Not implemented
super()- Calls to the superclass implementation
bin()- Returns a string of the binary representation of the passed in integer. The result always starts with "0b".
>>> bin(97656) '0b10111110101111000'
file()- Constructor function for the
filetype. The constructor’s arguments are the same as those of the
iter()- Return an iterator object
property()- Return a property attribute for new-style classes (classes that derive from
filter()- Construct a list from those elements of iterable for which function returns True
len()- Returns the length of the passed-in collection
>>> len([1,2,3,4]) 4
range()- Generates a list of integers
>>> range(2, 8) [2, 3, 4, 5, 6, 7] >>> range(2, 8, 2) [2, 4, 6]
type()- Returns the type of the passed-in object
>>> type(3) is int True
raw_input()- Not implemented
unichr()- Return the Unicode string of one character whose Unicode code is the integer i.
Trueif the object argument appears callable,
format()- Convert a value to a “formatted” representation, as controlled by format_spec.
locals()- Update and return a dictionary representing the current local symbol table.
reduce()- Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a single value.
chr()- Return a string of one character whose ASCII code is the integer i.
frozenset()- Return a new
frozensetobject, optionally with elements taken from iterable.
frozensetis a built-in class.
reload()- Reload a previously imported module.
vars()- Return the
__dict__attribute for a module, class, instance, or any other object with a
classmethod()- Return a class method for function.
getattr()- Return the value of the named attribute of object. name must be a string.
map()- Applies a callable to each item in collection in the second argument.
>>> map(lambda x: x * 2, [5, 6, 7, 8]) [10, 12, 14, 16] >>>
Also, maps can be expressed as list comprehensions:
>>> [x * 2 for x in [5, 6, 7, 8]] [10, 12, 14, 16] >>>
repr()- Return a string containing a printable representation of an object.
range()but returns an iterator instead of just a list.
cmp()- Compare the two objects x and y and return an integer according to the outcome.
globals()- Return a dictionary representing the current global symbol table.
max()- Returns the maximum value from the collection passed in.
>>> max([6,5,4,3]) 6
reversed()- Return a reverse iterator.
zip()- This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.
compile()- Compile the source into a code or AST object.
hasattr()- The arguments are an object and a string. The result is
Trueif the string is the name of one of the object’s attributes,
memoryview()- Return a “memory view” object created from the given argument.
round()- Return the floating point value number rounded to ndigits digits after the decimal point.
_import__()- The function imports the module name, potentially using the given globals and locals to determine how to interpret the name in a package context.
__import__(name[, globals[, locals[, fromlist[, level]]]])
complex()- Return a complex number with the value real + imag1j or convert a string or number to a complex number.
hash()- Return the hash value of the object (if it has one).
min()- Returns the minimum value from the collection passed in.
>>> min([6,5,4,3]) 3
delattr()- This is a relative of
setattr(). The arguments are an object and a string.
help()- Invoke the built-in help system.
next()- Retrieve the next item from the iterator by calling its
setattr()- This is the counterpart of
getattr(). The arguments are an object, a string and an arbitrary value.
hex()- Convert an integer number (of any size) to a lowercase hexadecimal string prefixed with "0x".
>>> hex(255) '0xff' >>> hex(-42) '-0x2a' >>> hex(1L) '0x1L'
object()- Return a new featureless object.
objectis a base for all new style classes.
slice()- Return a slice object representing the set of indices specified by
range(start, stop, step).
dir()- Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.
id()- Return the “identity” of an object.
oct()- Convert an integer number (of any size) to an octal string.
sorted()- Returns a copy of the passed in list sorted.
>>> sorted([9,4,1,8,4,6]) [1, 4, 4, 6, 8, 9]
global gen def gen(): yield 1 yield 2 yield 'x' @taxa.route("/f") def f(): response.add(str(list(gen()))) # [1, 2, 'x']