Spade

Mini Shell

Directory:~$ /proc/self/root/usr/lib/python2.7/site-packages/future/types/
Upload File

[Home] [System Details] [Kill Me]
Current File:~$ //proc/self/root/usr/lib/python2.7/site-packages/future/types/newstr.pyc

�
,�]c@s�dZddlmZddlmZmZmZmZddlm	Z	m
Z
ddlmZer}e
ZddlmZnddlmZdefd��YZd	eee�fd
��YZd	gZdS(s
This module redefines ``str`` on Python 2.x to be a subclass of the Py2
``unicode`` type that behaves like the Python 3.x ``str``.

The main differences between ``newstr`` and Python 2.x's ``unicode``
type are
the stricter type-checking and absence of a `u''` prefix in the
representation.

It is designed to be used together with the ``unicode_literals`` import
as follows:

    >>> from __future__ import unicode_literals
    >>> from builtins import str, isinstance

On Python 3.x and normally on Python 2.x, these expressions hold

    >>> str('blah') is 'blah'
    True
    >>> isinstance('blah', str)
    True

However, on Python 2.x, with this import:

    >>> from __future__ import unicode_literals

the same expressions are False:

    >>> str('blah') is 'blah'
    False
    >>> isinstance('blah', str)
    False

This module is designed to be imported together with ``unicode_literals``
on
Python 2 to bring the meaning of ``str`` back into alignment with
unprefixed
string literals (i.e. ``unicode`` subclasses).

Note that ``str()`` (and ``print()``) would then normally call the
``__unicode__`` method on objects in Python 2. To define string
representations of your objects portably across Py3 and Py2, use the
:func:`python_2_unicode_compatible` decorator in  :mod:`future.utils`.

i����(tNumber(tPY3tistexttwith_metaclasst
isnewbytes(tnotissubset(t	newobject(tIterablet
BaseNewStrcBseZd�ZRS(cCs-|tkrt|t�St|j|�SdS(N(tnewstrt
isinstancetunicodet
issubclasst	__class__(tclstinstance((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyt__instancecheck__;s
(t__name__t
__module__R(((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR	:sR
cBs'eZdZdZd�Zd�Zd�Zd�Zed�d��Z	ed�d��Z
d	�Zd
�Zd�Z
ed�d��Zed�d
��Zedd-�d��Zd�Zddd�Zedd�d��Zedd�d��Zedd�d.dd��Zedd�d.dd��Zedd�d��Zedd�d��Zedd�d��Zed�Zd�Zd�Zd
�Zd!Z
d"�Z!d#�Z"d$�Z#d%�Z$d&�Z%d'�Z&e'd.d.d(��Z(d)�Z)d*�Z*d+�Z+d,�Z,RS(/s6
    A backport of the Python 3 str object to Py2
    s,Can't convert '{0}' object to str
implicitlycOs�t|�dkr(tt|�j|�St|d�tkrR|tkrR|dSt|dt�rr|d}nkt|dt�r�d|ks�t|�dkr�|dj|d|�}q�|dj	�}n
|d}tt|�j||�S(s/
        From the Py3 str docstring:

          str(object='') -> str
          str(bytes_or_buffer[, encoding[, errors]]) -> str

          Create a new string object from the given object. If encoding or
          errors is specified, then the object must expose a data buffer
          that will be decoded using the given encoding and error handler.
          Otherwise, returns the result of object.__str__() (if defined)
          or repr(object).
          encoding defaults to sys.getdefaultencoding().
          errors defaults to 'strict'.

        itencodingi(
tlentsuperR
t__new__ttypeRRtbytestdecodet__str__(Rtargstkwargstvalue((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRHs"

cCstt|�j�}|dS(s&
        Without the u prefix
        i(RR
t__repr__(tselfR((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRjscCsttt|�j|��S(s�
        Warning: Python <= 2.7.6 has a bug that causes this method never
to be called
        when y is a slice object. Therefore the type of newstr()[:2] is
wrong
        (unicode instead of newstr).
        (R
Rt__getitem__(R
ty((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR!sscCs�d}t|�tkr!|}nUt|t�sLt|t�r[t|�r[t|�}nt|jt|����tt	|�t	|��S(Ns6'in
<string>' requires string as left operand, not {0}(
RR
RRRRt	TypeErrortformatRtlist(R
tkeyterrmsgtnewkey((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyt__contains__{s	+tnewbytescCsttt|�j|��S(N(R
Rt__add__(R
tother((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR+�scCs!yt|�|SWntSXdS(s
left + self N(R
tNotImplemented(R
tleft((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyt__radd__�scCsttt|�j|��S(N(R
Rt__mul__(R
R,((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR0�scCsttt|�j|��S(N(R
Rt__rmul__(R
R,((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR1�scCs�d}x>t|�D]0\}}t|�rt|j|���qqWt|�tkruttt|�j|��Stttt|��j|��SdS(Ns7sequence
item {0}: expected unicode string, found bytes(t	enumerateRR#R$RR
Rtjoin(R
titerableR'tititem((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR3�scGstt|�j||�S(N(RR
tfind(R
tsubR((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR7�scGstt|�j||�S(N(RR
trfind(R
R8R((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR9�siicGs"ttt|�j|||��S(N(R
Rtreplace(R
toldtnewR((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR:�scGstd��dS(Ns)decode
method has been disabled in newstr(tAttributeError(R
R((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR�ssutf-8tstrictcCs�ddlm}|dkr�|dkr7td��ng}xl|D]d}t|�}d|komdknr�|j||dg��qD|j|jd	|��qDW|d
�j|�S|tt|�j||��S(s�
        Returns bytes

        Encode S using the codec registered for encoding. Default encoding
        is 'utf-8'. errors may be given to set a different error
        handling scheme. Default is 'strict' meaning that
encoding errors raise
        a UnicodeEncodeError. Other possible values are 'ignore',
'replace' and
        'xmlcharrefreplace' as well as any other name registered
with
        codecs.register_error that can handle UnicodeEncodeErrors.
        i����(R*tsurrogateescapesutf-16s?FIXME: surrogateescape
handling is not yet implemented
properlyi�i��i�Rt(	tfuture.types.newbytesR*tNotImplementedErrortordtappendtencodeR3RR
(R
RterrorsR*tmybytestctcode((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRE�s
cGsit|t�rPx>|D]3}t|�rt|jjt|����qqWntt|�j	||�S(N(
RRRR#tno_convert_msgR$RRR
t
startswith(R
tprefixRtthing((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRK�s

(cGsit|t�rPx>|D]3}t|�rt|jjt|����qqWntt|�j	||�S(N(
RRRR#RJR$RRR
tendswith(R
RLRRM((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRN�s

(i����cCs8tt|�j||�}g|D]}t|�^q"S(N(RR
tsplit(R
tseptmaxsplittpartstpart((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRO�scCs8tt|�j||�}g|D]}t|�^q"S(N(RR
trsplit(R
RPRQRRRS((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRT�scCs,tt|�j|�}td�|D��S(Ncss|]}t|�VqdS(N(R
(t.0RS((s7/usr/lib/python2.7/site-packages/future/types/newstr.pys	<genexpr>s(RR
t	partitionttuple(R
RPRR((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRVscCs,tt|�j|�}td�|D��S(Ncss|]}t|�VqdS(N(R
(RURS((s7/usr/lib/python2.7/site-packages/future/types/newstr.pys	<genexpr>	s(RR
t
rpartitionRW(R
RPRR((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRXscGs1|j||�}|dkr-td��n|S(sb
        Like newstr.find() but raise ValueError when the substring is not
        found.
        i����ssubstring not found(R7t
ValueError(R
R8Rtpos((s7/usr/lib/python2.7/site-packages/future/types/newstr.pytindexscCs5tt|�j|�}g|D]}t|�^qS(s�
        S.splitlines(keepends=False) -> list of strings

        Return a list of the lines in S, breaking at line boundaries.
        Line breaks are not included in the resulting list unless keepends
        is given and true.
        (RR
t
splitlines(R
tkeependsRRRS((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR\s
cCsIt|t�s+t|t�rAt|�rAtt|�j|�StSdS(N(RRRRRR
t__eq__R-(R
R,((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR^#scCsKt|t�s+t|t�r>t|�r>tt|�j�St��dS(N(RRRRRR
t__hash__RB(R
((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR_*scCsIt|t�s+t|t�rAt|�rAtt|�j|�StSdS(N(RRRRRR
t__ne__tTrue(R
R,((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR`1ss
unorderable types: str() and
{0}cCsct|t�s+t|t�rAt|�rAtt|�j|�St|jj	t
|����dS(N(RRRRRR
t__lt__R#tunorderable_errR$R(R
R,((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRb:scCsct|t�s+t|t�rAt|�rAtt|�j|�St|jj	t
|����dS(N(RRRRRR
t__le__R#RcR$R(R
R,((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRd@scCsct|t�s+t|t�rAt|�rAtt|�j|�St|jj	t
|����dS(N(RRRRRR
t__gt__R#RcR$R(R
R,((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyReFscCsct|t�s+t|t�rAt|�rAtt|�j|�St|jj	t
|����dS(N(RRRRRR
t__ge__R#RcR$R(R
R,((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRfLscCs1|dkrtd��ntt|�j|�S(su
        A trick to cause the ``hasattr`` builtin-fn to return False for
        the 'decode' method on Py2.
        Rudecodes)decode method has been disabled in
newstr(sdecodeudecode(R=RR
t__getattribute__(R
tname((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyRgRscCs
t|�S(s@
        A hook for the future.utils.native() function.
        (R(R
((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyt
__native__[sc	Csy|dkr�|dkst�t|t�s<td��ni}x|j�D]=\}}t|�dkr|td��n||t|�<qOWn�t|t	�r�t|t	�r�td��nt|�t|�ks�td��ni}xTt
||�D]C\}}t|�dkr+td��nt|�|t|�<q�W|dk	rux!|D]}d|t|�<qXWn|S(s_
        Return a translation table usable for str.translate().

        If there is only one argument, it must be a dictionary mapping
Unicode
        ordinals (integers) or characters to Unicode ordinals, strings or
None.
        Character keys will be then converted to ordinals.
        If there are two arguments, they must be strings of equal length,
and
        in the resulting dictionary, each character in x will be mapped to
the
        character at the same position in y. If there is a third argument,
it
        must be a string, whose characters will be mapped to None in the
result.
        s<if you give only one argument to maketrans it must be a
dictis3keys in translate table must be strings or integerssx and y must
be unicode stringss8the first two maketrans arguments must have equal
lengthN(tNonetAssertionErrorRtdictR#titemsRRYRCRtzip(	txR"tztresultR&Rtxityitchar((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyt	maketransas,
cCs�g}x�|D]|}t|�|kr||t|�}|dkrGq
q�t|t�rf|j|�q�|jt|��q
|j|�q
Wdj|�S(s`
        S.translate(table) -> str

        Return a copy of the string S, where all characters have been
mapped
        through the given translation table, which must be a mapping of
        Unicode ordinals to Unicode ordinals, strings, or None.
        Unmapped characters are left untouched. Characters mapped to None
        are deleted.
        R@N(RCRjRRRDtchrR3(R
ttabletlRHtval((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyt	translate�s

cCstd��dS(Ntfixme(RB(R
((s7/usr/lib/python2.7/site-packages/future/types/newstr.pytisprintable�scCstd��dS(NR{(RB(R
((s7/usr/lib/python2.7/site-packages/future/types/newstr.pytisidentifier�scCstd��dS(NR{(RB(R
((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyt
format_map�s(iiN(-RRt__doc__RJRRR!R)RR+R/R0R1R3R7R9R:RRERKRNRjRORTRVRXR[tFalseR\R^R_R`RcRbRdReRfRgRitstaticmethodRuRzR|R}R~(((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyR
BsT	"								)
										&			N(RtnumbersRtfuture.utilsRRRRtfuture.typesRRtfuture.types.newobjectRtstrRtcollections.abcRtcollectionsRR	R
t__all__(((s7/usr/lib/python2.7/site-packages/future/types/newstr.pyt<module>)s"�i