-=[ Mr. Bumblebee ]=-
_Indonesia_

Path : /usr/lib/python2.7/dist-packages/bzrlib/transport/http/
File Upload :
Current File : //usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyc

ó
ÊVPc@@sdZddlmZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZm
Z
ddlmZddlmZddlmZdefd	„ƒYZd
ejfd„ƒYZdejfd
„ƒYZdd„ZdS(s|Base implementation of Transport over http.

There are separate implementation modules for each http client implementation.
i(tabsolute_importN(tdebugterrorst	transporttuiturlutils(tmedium(tmutter(tConnectedTransporttHttpTransportBasecB@sFeZdZd!d„Zd„Zd„Zdd„Zd„Zd„Z	d„Z
d	„Zd
ZdZ
dZdZd„Zd
„Zd„Zd„Zd!d„Zd!d„Zd„Zd!d„Zd„Zd!d!d„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z!d„Z"e#d„ƒZ$d „Z%RS("sÀBase class for http implementations.

    Does URL parsing, etc, but not any network IO.

    The protocol can be given as e.g. http+urllib://host/ to use a particular
    implementation.
    cC@s“tjd|ƒ}|s+td|ƒ‚n|jdƒ|_||_tt|ƒj|d|ƒd|_
|dk	r†|j|_n	d|_dS(s-Set the base path where files will be stored.s^(https?)(\+\w+)?://snot a http url: %rit_from_transporttmultiN(tretmatchtAssertionErrortgroupt_unqualified_schemet
_impl_nametsuperR	t__init__tNonet_mediumt_range_hint(tselftbaseRR
tproto_match((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyR8s		cC@std|ƒ‚dS(Nshas() is abstract on %r(tNotImplementedError(Rtrelpath((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pythasNscC@s|j|dƒ\}}|S(shGet the file at the given relative path.

        :param relpath: The relative path to the file
        N(t_getR(RRtcodet
response_file((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytgetQsicC@st|jƒ‚dS(sPGet a file, or part of a file.

        :param relpath: Path relative to transport base URL
        :param ranges: None to get the whole file;
            or  a list of _CoalescedOffset to fetch parts of a file.
        :param tail_amount: The amount to get from the end of the file.

        :returns: (http_code, result_file)
        N(RR(RRtrangesttail_amount((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyRYs
cC@sH|jj|ƒ}d|_|_d|_|_|j|_t	|ƒS(s~See ConnectedTransport._remote_path.

        user and passwords are not embedded in the path provided to the server.
        N(
t_parsed_urltcloneRtusertquoted_usertpasswordtquoted_passwordRtschemetstr(RRturl((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt_remote_pathes
c
C@sRtd|jjd|jjd|jjd|jjd|jd|jjƒ}|S(sAReturns a dict containing the credentials provided at build time.thosttportR%R'tprotocoltpath(tdictR#R-R.R%R'RR0(Rtauth((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt_create_authps
	cC@s(|jdkr!t|ƒ|_n|jS(sSee Transport.get_smart_medium.N(RRtSmartClientHTTPMedium(R((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytget_smart_mediumxscC@sn|jdkr)d|_td|ƒnA|jdkrRd|_td|ƒn|d|d|d‚dS(NRtsingles$Retry "%s" with single range requestsRetry "%s" without rangesiii(RRR(RRR!texc_info((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt_degrade_range_hint‚s		i€iÈcc@sˆt|ƒ}t}d	}xi|rƒt}t|ƒ}|j|d|jd|jd|jƒ}t|ƒ}dt	j
krštd|t|ƒt|ƒƒni}t
|ƒ}|jƒ}	y#x|j||ƒD]\}
}x¼|
jD]±\}}
|
j|}|j|tjƒ|j|
ƒ}t|ƒ}||
krUtj|||
d|ƒ‚n||
f|	kr…|	d|fV|jƒ}	qä||||
f<qäWx:|	|krÕ|j|	ƒ}|	d|fV|jƒ}	qœWqÎWWqtjtjtjtjfk
r}td||ƒt|tjƒs4||	krP|j||tjƒƒn|	gg|D]}|^q]}|	}t}qXqWd	S(
s¸Get parts of the file at the given relative path.

        :param offsets: A list of (offset, size) tuples.
        :param return: A list or generator of (offset, data) tuples
        tlimittfudge_factortmax_sizethttps,http readv of %s  offsets => %s collapsed %stactualis#Exception %r: %s during http._readvN( tlisttTrueRtFalsetsortedt_coalesce_offsetst_max_readv_combinet_bytes_to_read_before_seekt
_get_max_sizeRtdebug_flagsRtlentitertnextt_coalesce_readvR!tstarttseektostSEEK_SETtreadRtShortReadvErrortpoptInvalidRangetInvalidHttpRangetHttpBoundaryMissingt
isinstanceR8tsysR7(RRtoffsetst	try_againtretried_offsettsorted_offsetst	coalescedtdata_maptiter_offsetstcur_offset_and_sizetcur_coaltrfiletoffsettsizeRKtdatatdata_lent	this_datateto((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt_readv¤sX		

 c#@s~‡fd†}ˆjdkrLxY|||ƒD]\}}||fVq.Wn.t|ƒ}ˆjdkrsˆj}n.ˆjdkr‹|}ntdˆjfƒ‚d}g}	xŸ|D]—}
ˆjdkrß||
jˆjksñt|	ƒ|kr1x(|||	ƒD]\}}||fVqW|
g}	|
j}q´|	j|
ƒ||
j7}q´Wx(|||	ƒD]\}}||fVq_WdS(s;Issue several GET requests to satisfy the coalesced offsetsc3@sA|r=ˆj||ƒ\}}x|D]}||fVq%WndS(N(R(RR[RR`tcoal(R(sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt
get_and_yieldús
RR6sUnknown _range_hint %riN(RRRGt_max_get_rangesRREtlengthtappend(RRR[RjtcR`ttotalt
max_rangestcumulR!Ri((RsB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyRJ÷s2
	
	
cC@sdS(s”See Transport.recommended_page_size().

        For HTTP we suggest a large page size to reduce the overhead
        introduced by latency.
        i@ii((R((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytrecommended_page_size(scC@st|jƒ‚dS(s}POST body_bytes to .bzr/smart on this transport.

        :returns: (response code, response body file-like object).
        N(Rt_post(Rt
body_bytes((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyRs0s	cC@stjdƒ‚dS(s¨Copy the file-like object into the location.

        :param relpath: Location to put the contents, relative to base.
        :param f:       File-like object.
        shttp PUT not supportedN(RtTransportNotPossible(RRtftmode((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytput_file;scC@stjdƒ‚dS(s%Create a directory at the given path.shttp does not support mkdir()N(RRu(RRRw((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytmkdirCscC@stjdƒ‚dS(sSee Transport.rmdir.shttp does not support rmdir()N(RRu(RR((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytrmdirGscC@stjdƒ‚dS(sQAppend the text in the file-like object into the final
        location.
        shttp does not support append()N(RRu(RRRvRw((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytappend_fileKscC@stjdƒ‚dS(s3Copy the item at rel_from to the location at rel_toshttp does not support copy()N(RRu(Rtrel_fromtrel_to((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytcopyQscC@sJt|tƒr!tjdƒ‚n%tt|ƒj||d|d|ƒSdS(sêCopy a set of entries from self into another Transport.

        :param relpaths: A list/generator of entries to be copied.

        TODO: if other is LocalTransport, is it possible to
              do better than put(get())?
        s&http cannot be the target of copy_to()RwtpbN(RUR	RRuRtcopy_to(RtrelpathstotherRwR((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyR€Us
cC@stjdƒ‚dS(s3Move the item at rel_from to the location at rel_toshttp does not support move()N(RRu(RR|R}((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytmovegscC@stjdƒ‚dS(sDelete the item at relpathshttp does not support delete()N(RRu(RR((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytdeletekscC@s%|jjƒ}|j|_t|ƒS(s,See bzrlib.transport.Transport.external_url.(R#R$RR)R*(RR+((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytexternal_urloscC@stS(sSee Transport.is_readonly.(R?(R((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytis_readonlywscC@stS(sSee Transport.listable.(R@(R((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytlistable{scC@stjdƒ‚dS(s0Return the stat information for a file.
        shttp does not support stat()N(RRu(RR((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytstatscC@s dtfd„ƒY}||ƒS(sƒLock the given file for shared (read) access.
        :return: A lock object, which should be passed to Transport.unlock()
        t	BogusLockcB@seZd„Zd„ZRS(cS@s
||_dS(N(R0(RR0((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyR‹scS@sdS(N((R((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytunlocks(t__name__t
__module__RRŠ(((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyR‰Šs	(tobject(RRR‰((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt	lock_read„scC@stjdƒ‚dS(s×Lock the given file for exclusive (write) access.
        WARNING: many transports do not support this, so trying avoid using it

        :return: A lock object, which should be passed to Transport.unlock()
        s"http does not support lock_write()N(RRu(RR((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt
lock_write‘scC@sÛ|jdkr|j||ƒS|jdkrÓt|ƒdkrÀ|d	krPdS|dj}|d}|j|jd}|j|||dfgddddƒ}|jt|ƒdƒSq×|j||ƒSndSdS(
s¼Prepare a HTTP Range header at a level the server should accept.

        :return: the range header representing offsets/tail_amount or None if
            no header can be built.
        RR6iiÿÿÿÿiR9R:N(iN(Rt
_range_headerRGRRKRlRBR>(RRWR"RKtlasttendtwhole((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt_attempted_range_header™s

cC@sfg}x6|D].}|jd|j|j|jdfƒq
W|rY|jd|ƒndj|ƒS(s=Turn a list of bytes ranges into a HTTP Range header value.

        :param ranges: A list of _CoalescedOffset
        :param tail_amount: The amount to get from the end of the file.

        :return: HTTP range header string.

        At least a non-empty ranges *or* a tail_amount must be
        provided.
        s%d-%dis-%dt,(RmRKRltjoin(R!R"tstringsRa((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyRºs
c
C@sŠ|j|ƒ}|j|ƒ}t|jjƒ}|j|jdƒ}|j|ƒsYdS|j}|r||t|ƒ }n|jdkrL|j|jkrø|j	|jj	krø|j
|jj
krø|jdksë|j|jjkrø|j|ƒS|jd|j
}|j||jj|jj|j	|j
|ƒ}	tj|	ƒSn:|j|j|j|j|j	|j
|ƒ}	tj|	ƒSdS(sbReturns a transport suitable to re-issue a redirected request.

        :param source: The source url as returned by the server.
        :param target: The target url as returned by the server.

        The redirection can be handled only if the relpath involved is not
        renamed by the redirection.

        :returns: A transport or None.
        t/R<thttpst+N(shttpR™(t
_split_urlRGR#R0tstriptendswithRR)RR-R.R%R$Rt_unsplit_urlR'Rtget_transport_from_url(
Rtsourcettargett
parsed_sourcet
parsed_targettpltexcess_tailttarget_pathtredir_schemetnew_url((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt_redirected_toÐs:	
					N(&R‹RŒt__doc__RRRR RR,R3R5R8RDRCRkRERhRJRrRsRxRyRzR{R~R€RƒR„R…R†R‡RˆRŽRR”tstaticmethodRR©(((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyR	,sD					
		S	1											
		!R4cB@sGeZd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(cC@s/tt|ƒj|jƒtj|ƒ|_dS(N(RR4RRtweakreftreft_http_transport_ref(Rthttp_transport((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyRscC@s
t|ƒS(N(tSmartClientHTTPMediumRequest(R((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytget_requestscC@stS(N(R?(R((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytshould_probescC@sG|j}|jdƒr%|d}ntj|j|ƒ}tj|ƒS(Nsbzr+i(Rt
startswithRtrelative_urltunquote(RRttransport_basetrel_url((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytremote_path_from_transport"s
	
cC@s‘yV|jƒ}|j|ƒ\}}|dkrUtj|jdƒd|fƒ‚nWn4tjtjfk
rŒ}tjt|ƒƒ‚nX|S(NiÈs
.bzr/smarts"Expected 200 response code, got %r(R®RsRtInvalidHttpResponseR,tConnectionResettSmartProtocolErrorR*(RtbytesttRt
body_filelikeRf((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytsend_http_smart_request+scC@sdS(s¥See SmartMedium._report_activity.

        Does nothing; the underlying plain HTTP transport will report the
        activity that this medium would report.
        N((RR¼t	direction((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt_report_activity8scC@s|jƒ}|jƒdS(s#See SmartClientMedium.disconnect().N(R®t
disconnect(RR½((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyRÂ@s(	R‹RŒRR±R²R¸R¿RÁRÂ(((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyR4s						
	R°cB@sDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s:A SmartClientMediumRequest that works with an HTTP medium.cC@s tjj||ƒd|_dS(Nt(RtSmartClientMediumRequestRt_buffer(Rt
client_medium((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyRKscC@s|j|7_dS(N(RÅ(RR¼((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt
_accept_bytesOscC@s"|jj|jƒ}||_dS(N(RR¿RÅt_response_body(RRc((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt_finished_writingRscC@s|jj|ƒS(s)See SmartClientMediumRequest._read_bytes.(RÈRO(Rtcount((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt_read_bytesVscC@sAtj|jjƒ\}}|dkr=td|fƒ‚n|S(NRÃsR_get_line returned excess bytes, but this mediumrequest cannot handle excess. (%r)(Rt	_get_lineRÈROR(Rtlinetexcess((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt
_read_lineZscC@sdS(s/See SmartClientMediumRequest._finished_reading.N((R((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt_finished_readingbs(	R‹RŒRªRRÇRÉRËRÏRÐ(((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyR°Hs					iècC@stjdd|ƒd| S(sæVery approximate html->text translation, for presenting error bodies.

    :param length_limit: Truncate the result to this many characters.

    >>> unhtml_roughly("<b>bad</b> things happened\n")
    ' bad  things happened '
    s(<[^>]*>|\n|&nbsp;)t i(Rtsubn(t
maybe_htmltlength_limit((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pytunhtml_roughlygs(Rªt
__future__RRMRturlparseRVR¬tbzrlibRRRRRtbzrlib.smartRtbzrlib.traceRtbzrlib.transportRR	tSmartClientMediumR4RÄR°RÕ(((sB/usr/lib/python2.7/dist-packages/bzrlib/transport/http/__init__.pyt<module>s(ÿç6

Copyright © 2017 || Recoded By Mr.Bumblebee