Back to index

python-biopython  1.60
Functions | Variables
Bio._py3k Namespace Reference

Functions

def _as_unicode
def _as_bytes
def _is_int_or_long
def _binary_to_string_handle

Variables

tuple _bytes_to_string = lambdab:b.decode()
tuple _string_to_bytes = lambdas:s.encode()
 _as_string = _as_unicode
 _handle

Function Documentation

def Bio._py3k._as_bytes (   s) [private]
Turn byte string or unicode string into a bytes string.

The Python 2 version returns a (byte) string.
Turn a (byte) string or a unicode string into a (byte) string.

Definition at line 25 of file _py3k.py.

00025 
00026     def _as_bytes(s):
00027         """Turn byte string or unicode string into a bytes string.
00028         
00029         The Python 2 version returns a (byte) string.
00030         """
00031         if isinstance(s, bytes):
00032             return s
00033         #Assume it is a unicode string
00034         #Note ISO-8859-1 aka Latin-1 preserves first 256 chars
00035         return codecs.latin_1_encode(s)[0]
00036 
    

Here is the caller graph for this function:

def Bio._py3k._as_unicode (   s) [private]
Turn byte string or unicode string into a unicode string.
Turn a (byte) string or a unicode string into a (byte) string.

Definition at line 16 of file _py3k.py.

00016 
00017     def _as_unicode(s):
00018         """Turn byte string or unicode string into a unicode string."""
00019         if isinstance(s, str):
00020             return s
00021         #Assume it is a bytes string
00022         #Note ISO-8859-1 aka Latin-1 preserves first 256 chars
00023         return codecs.latin_1_decode(s)[0]
00024 

def Bio._py3k._binary_to_string_handle (   handle) [private]
Treat a binary (bytes) handle like a text (unicode) handle.
Treat a binary handle like a text handle.

Definition at line 47 of file _py3k.py.

00047 
00048     def _binary_to_string_handle(handle):
00049         """Treat a binary (bytes) handle like a text (unicode) handle."""
00050         #See also http://bugs.python.org/issue5628
00051         #and http://bugs.python.org/issue13541
00052         #and http://bugs.python.org/issue13464 which should be fixed in Python 3.3
00053         #return io.TextIOWrapper(io.BufferedReader(handle))
00054         #TODO - Re-evaluate this workaround under Python 3.3
00055         #(perhaps we will only need it on Python 3.1 and 3.2?)
00056         class EvilHandleHack(object):
00057             def __init__(self, handle):
00058                 self._handle = handle
00059             def read(self, length=None):
00060                 return _as_string(self._handle.read(length))
00061             def readline(self):
00062                 return _as_string(self._handle.readline())
00063             def __iter__(self):
00064                 for line in self._handle:
00065                     yield _as_string(line)
00066             def close(self):
00067                 return self._handle.close()
00068             def seek(self, pos):
00069                 return self._handle.seek(pos)
00070             def tell(self):
00071                 return self._handle.tell(pos)
00072         return EvilHandleHack(handle)
00073 
else:

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio._py3k._is_int_or_long (   i) [private]
Check if the value is an integer.

Note there are no longs on Python 3.
Check if the value is an integer or long.

Definition at line 39 of file _py3k.py.

00039 
00040     def _is_int_or_long(i):
00041         """Check if the value is an integer.
00042 
00043         Note there are no longs on Python 3.
00044         """
00045         return isinstance(i, int)

Here is the caller graph for this function:


Variable Documentation

Definition at line 37 of file _py3k.py.

Bio._py3k._bytes_to_string = lambdab:b.decode()

Definition at line 13 of file _py3k.py.

Definition at line 57 of file _py3k.py.

tuple Bio._py3k._string_to_bytes = lambdas:s.encode()

Definition at line 14 of file _py3k.py.