uawdijnntqw1x1x1
IP : 18.216.26.192
Hostname : ns1.eurodns.top
Kernel : Linux ns1.eurodns.top 4.18.0-553.5.1.lve.1.el7h.x86_64 #1 SMP Fri Jun 14 14:24:52 UTC 2024 x86_64
Disable Function : mail,sendmail,exec,passthru,shell_exec,system,popen,curl_multi_exec,show_source,eval,open_base
OS : Linux
PATH:
/
home
/
..
/
lib
/
python2.7
/
site-packages
/
rhn
/
..
/
urlgrabber
/
grabber.pyc
/
/
� �^c @sodZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl Z ddlZddlZddl Z ddlZddlmZddlmZddlmZddlZddlZddlZddlmZmZmZy)ddlZeed�r>eZnWnek rXeZnXy!d ejd �dddUWn d Z nXyddl!m"Z"Wnek r�Z#d�Z"nXea$d�Z%ed�Z&d�Z'e&�e'�d�Z"dd�Z(d�Z)de*fd��YZ+dfd��YZ,ed�Z-d�Z.ed�Z/dfd��YZ0d fd!��YZ1d"�Z2d#�Z3d$e4fd%��YZ5e5�Z6d&e4fd'��YZ7eed(�r�ej8ej9ej:B�nej;�a<d)�Z=ea>d*�Z?d+�Z@d,�ZAd-�ZBeddeeed.dd/d0d1d2d3ged4� ZCiZDx"d5D]ZEd6eFeE�eDeE<qoW[Ed7�ZGd8�ZHd9�ZIddlJZJd:fd;��YZKd<fd=��YZLgZMed>�ZNd?fd@��YZOdA�ZPdB�ZQedC�ZRdD�ZSdE�ZTdF�ZUdG�ZVedHkrkeP�eQ�eRdI�ndS(Js�KA high-level cross-protocol url-grabber. GENERAL ARGUMENTS (kwargs) Where possible, the module-level default is indicated, and legal values are provided. copy_local = 0 [0|1] ignored except for file:// urls, in which case it specifies whether urlgrab should still make a copy of the file, or simply point to the existing copy. The module level default for this option is 0. close_connection = 0 [0|1] tells URLGrabber to close the connection after a file has been transferred. This is ignored unless the download happens with the http keepalive handler (keepalive=1). Otherwise, the connection is left open for further use. The module level default for this option is 0 (keepalive connections will not be closed). keepalive = 1 [0|1] specifies whether keepalive should be used for HTTP/1.1 servers that support it. The module level default for this option is 1 (keepalive is enabled). progress_obj = None a class instance that supports the following methods: po.start(filename, url, basename, size, now, text) # length will be None if unknown po.update(read) # read == bytes read so far po.end() multi_progress_obj = None a class instance that supports the following methods: mo.start(total_files, total_size) mo.newMeter() => meter mo.removeMeter(meter) mo.end() The 'meter' object is similar to progress_obj, but multiple instances may be created and updated at the same time. When downloading multiple files in parallel and multi_progress_obj is None progress_obj is used in compatibility mode: finished files are shown but there's no in-progress display. curl_obj = None a pycurl.Curl instance to be used instead of the default module-level instance. Note that you don't have to configure the passed instance in any way; urlgrabber will do all the necessary work. This option exists primarily to allow using urlgrabber from multiple threads in your application, in which case you would want to instantiate a fresh Curl object for each thread, to avoid race conditions. See the curl documentation on thread safety for more information: https://curl.haxx.se/libcurl/c/threadsafe.html Note that connection reuse (keepalive=1) is limited to the Curl instance it was enabled on so if you're using multiple instances in your application, connections won't be shared among them. text = None specifies alternative text to be passed to the progress meter object. If not given, the default progress meter will use the basename of the file. throttle = 1.0 a number - if it's an int, it's the bytes/second throttle limit. If it's a float, it is first multiplied by bandwidth. If throttle == 0, throttling is disabled. If None, the module-level default (which can be set on default_grabber.throttle) is used. See BANDWIDTH THROTTLING for more information. timeout = 300 a positive integer expressing the number of seconds to wait before timing out attempts to connect to a server. If the value is None or 0, connection attempts will not time out. The timeout is passed to the underlying pycurl object as its CONNECTTIMEOUT option, see the curl documentation on CURLOPT_CONNECTTIMEOUT for more information. http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTCONNECTTIMEOUT minrate = 1000 This sets the low speed threshold in bytes per second. If the server is sending data slower than this for at least `timeout' seconds, the library aborts the connection. bandwidth = 0 the nominal max bandwidth in bytes/second. If throttle is a float and bandwidth == 0, throttling is disabled. If None, the module-level default (which can be set on default_grabber.bandwidth) is used. See BANDWIDTH THROTTLING for more information. range = None a tuple of the form (first_byte, last_byte) describing a byte range to retrieve. Either or both of the values may set to None. If first_byte is None, byte offset 0 is assumed. If last_byte is None, the last byte available is assumed. Note that the range specification is python-like in that (0,10) will yield the first 10 bytes of the file. If set to None, no range will be used. reget = None [None|'simple'|'check_timestamp'] whether to attempt to reget a partially-downloaded file. Reget only applies to .urlgrab and (obviously) only if there is a partially downloaded file. Reget has two modes: 'simple' -- the local file will always be trusted. If there are 100 bytes in the local file, then the download will always begin 100 bytes into the requested file. 'check_timestamp' -- the timestamp of the server file will be compared to the timestamp of the local file. ONLY if the local file is newer than or the same age as the server file will reget be used. If the server file is newer, or the timestamp is not returned, the entire file will be fetched. NOTE: urlgrabber can do very little to verify that the partial file on disk is identical to the beginning of the remote file. You may want to either employ a custom "checkfunc" or simply avoid using reget in situations where corruption is a concern. user_agent = 'urlgrabber/VERSION' a string, usually of the form 'AGENT/VERSION' that is provided to HTTP servers in the User-agent header. The module level default for this option is "urlgrabber/VERSION". http_headers = None a tuple of 2-tuples, each containing a header and value. These will be used for http and https requests only. For example, you can do http_headers = (('Pragma', 'no-cache'),) ftp_headers = None this is just like http_headers, but will be used for ftp requests. proxies = None a dictionary that maps protocol schemes to proxy hosts. For example, to use a proxy server on host "foo" port 3128 for http and https URLs: proxies={ 'http' : 'http://foo:3128', 'https' : 'http://foo:3128' } note that proxy authentication information may be provided using normal URL constructs: proxies={ 'http' : 'http://user:host@foo:3128' } libproxy = False Use the libproxy module (if installed) to find proxies. The libproxy code is only used if the proxies dictionary does not provide any proxies. no_cache = False When True, server-side cache will be disabled for http and https requests. This is equivalent to setting http_headers = (('Pragma', 'no-cache'),) prefix = None a url prefix that will be prepended to all requested urls. For example: g = URLGrabber(prefix='http://foo.com/mirror/') g.urlgrab('some/file.txt') ## this will fetch 'http://foo.com/mirror/some/file.txt' This option exists primarily to allow identical behavior to MirrorGroup (and derived) instances. Note: a '/' will be inserted if necessary, so you cannot specify a prefix that ends with a partial file or directory name. opener = None No-op when using the curl backend (default) cache_openers = True No-op when using the curl backend (default) data = None Only relevant for the HTTP family (and ignored for other protocols), this allows HTTP POSTs. When the data kwarg is present (and not None), an HTTP request will automatically become a POST rather than GET. This is done by direct passthrough to urllib2. If you use this, you may also want to set the 'Content-length' and 'Content-type' headers with the http_headers option. Note that python 2.2 handles the case of these badly and if you do not use the proper case (shown here), your values will be overridden with the defaults. urlparser = URLParser() The URLParser class handles pre-processing of URLs, including auth-handling for user/pass encoded in http urls, file handing (that is, filenames not sent as a URL), and URL quoting. If you want to override any of this behavior, you can pass in a replacement instance. See also the 'quote' option. quote = None Whether or not to quote the path portion of a url. quote = 1 -> quote the URLs (they're not quoted yet) quote = 0 -> do not quote them (they're already quoted) quote = None -> guess what to do This option only affects proper urls like 'file:///etc/passwd'; it does not affect 'raw' filenames like '/etc/passwd'. The latter will always be quoted as they are converted to URLs. Also, only the path part of a url is quoted. If you need more fine-grained control, you should probably subclass URLParser and pass it in via the 'urlparser' option. username = None username to use for simple http auth - is automatically quoted for special characters password = None password to use for simple http auth - is automatically quoted for special characters ssl_ca_cert = None this option can be used if M2Crypto is available and will be ignored otherwise. If provided, it will be used to create an SSL context. If both ssl_ca_cert and ssl_context are provided, then ssl_context will be ignored and a new context will be created from ssl_ca_cert. ssl_context = None No-op when using the curl backend (default) ssl_verify_peer = True Check the server's certificate to make sure it is valid with what our CA validates ssl_verify_host = True Check the server's hostname to make sure it matches the certificate DN ssl_key = None Path to the key the client should use to connect/authenticate with ssl_key_type = 'PEM' PEM or DER - format of key ssl_cert = None Path to the ssl certificate the client should use to to authenticate with ssl_cert_type = 'PEM' PEM or DER - format of certificate ssl_key_pass = None password to access the ssl_key size = None size (in bytes) or Maximum size of the thing being downloaded. This is mostly to keep us from exploding with an endless datastream max_header_size = 2097152 Maximum size (in bytes) of the headers. ip_resolve = 'whatever' What type of name to IP resolving to use, default is to do both IPV4 and IPV6. async = (key, limit) When this option is set, the urlgrab() is not processed immediately but queued. parallel_wait() then processes grabs in parallel, limiting the numer of connections in each 'key' group to at most 'limit'. max_connections The global connection limit. timedhosts The filename of the host download statistics. If defined, urlgrabber will update the stats at the end of every download. At the end of parallel_wait(), the updated stats are saved. If synchronous grabs are used, you should call th_save(). default_speed, half_life These options only affect the async mirror selection code. The default_speed option sets the speed estimate for mirrors we have never downloaded from, and defaults to 1 MBps. The speed estimate also drifts exponentially from the speed actually measured to the default speed, with default period of 30 days. ftp_disable_epsv = False False, True This options disables Extended Passive Mode (the EPSV command) which does not work correctly on some buggy ftp servers. RETRY RELATED ARGUMENTS retry = None the number of times to retry the grab before bailing. If this is zero, it will retry forever. This was intentional... really, it was :). If this value is not supplied or is supplied but is None retrying does not occur. retrycodes = [-1,2,4,5,6,7] a sequence of errorcodes (values of e.errno) for which it should retry. See the doc on URLGrabError for more details on this. You might consider modifying a copy of the default codes rather than building yours from scratch so that if the list is extended in the future (or one code is split into two) you can still enjoy the benefits of the default list. You can do that with something like this: retrycodes = urlgrabber.grabber.URLGrabberOptions().retrycodes if 12 not in retrycodes: retrycodes.append(12) checkfunc = None a function to do additional checks. This defaults to None, which means no additional checking. The function should simply return on a successful check. It should raise URLGrabError on an unsuccessful check. Raising of any other exception will be considered immediate failure and no retries will occur. If it raises URLGrabError, the error code will determine the retry behavior. Negative error numbers are reserved for use by these passed in functions, so you can use many negative numbers for different types of failure. By default, -1 results in a retry, but this can be customized with retrycodes. If you simply pass in a function, it will be given exactly one argument: a CallbackObject instance with the .url attribute defined and either .filename (for urlgrab) or .data (for urlread). For urlgrab, .filename is the name of the local file. For urlread, .data is the actual string data. If you need other arguments passed to the callback (program state of some sort), you can do so like this: checkfunc=(function, ('arg1', 2), {'kwarg': 3}) if the downloaded file has filename /tmp/stuff, then this will result in this call (for urlgrab): function(obj, 'arg1', 2, kwarg=3) # obj.filename = '/tmp/stuff' # obj.url = 'http://foo.com/stuff' NOTE: both the "args" tuple and "kwargs" dict must be present if you use this syntax, but either (or both) can be empty. failure_callback = None The callback that gets called during retries when an attempt to fetch a file fails. The syntax for specifying the callback is identical to checkfunc, except for the attributes defined in the CallbackObject instance. The attributes for failure_callback are: exception = the raised exception url = the url we're trying to fetch tries = the number of tries so far (including this one) retry = the value of the retry option retry_no_cache = the value of the retry_no_cache option The callback is present primarily to inform the calling program of the failure, but if it raises an exception (including the one it's passed) that exception will NOT be caught and will therefore cause future retries to be aborted. The callback is called for EVERY failure, including the last one. On the last try, the callback can raise an alternate exception, but it cannot (without severe trickiness) prevent the exception from being raised. failfunc = None The callback that gets called when urlgrab request fails. If defined, urlgrab() calls it instead of raising URLGrabError. Callback syntax is identical to failure_callback. Contrary to failure_callback, it's called only once. It's primary purpose is to use urlgrab() without a try/except block. interrupt_callback = None This callback is called if KeyboardInterrupt is received at any point in the transfer. Basically, this callback can have three impacts on the fetch process based on the way it exits: 1) raise no exception: the current fetch will be aborted, but any further retries will still take place 2) raise a URLGrabError: if you're using a MirrorGroup, then this will prompt a failover to the next mirror according to the behavior of the MirrorGroup subclass. It is recommended that you raise URLGrabError with code 15, 'user abort'. If you are NOT using a MirrorGroup subclass, then this is the same as (3). 3) raise some other exception (such as KeyboardInterrupt), which will not be caught at either the grabber or mirror levels. That is, it will be raised up all the way to the caller. This callback is very similar to failure_callback. They are passed the same arguments, so you could use the same function for both. retry_no_cache = False When True, automatically enable no_cache for future retries if checkfunc performs an unsuccessful check. This option is useful if your application expects a set of files from the same server to form an atomic unit and you write your checkfunc to ensure each file being downloaded belongs to such a unit. If transparent proxy caching is in effect, the files can become out-of-sync, disrupting the atomicity. Enabling this option will prevent that, while ensuring that you still enjoy the benefits of caching when possible. BANDWIDTH THROTTLING urlgrabber supports throttling via two values: throttle and bandwidth Between the two, you can either specify and absolute throttle threshold or specify a theshold as a fraction of maximum available bandwidth. throttle is a number - if it's an int, it's the bytes/second throttle limit. If it's a float, it is first multiplied by bandwidth. If throttle == 0, throttling is disabled. If None, the module-level default (which can be set with set_throttle) is used. bandwidth is the nominal max bandwidth in bytes/second. If throttle is a float and bandwidth == 0, throttling is disabled. If None, the module-level default (which can be set with set_bandwidth) is used. Note that when multiple downloads run simultaneously (multiprocessing or the parallel urlgrab() feature is used) the total bandwidth might exceed the throttle limit. You may want to also set max_connections=1 or scale your throttle option down accordingly. THROTTLING EXAMPLES: Lets say you have a 100 Mbps connection. This is (about) 10^8 bits per second, or 12,500,000 Bytes per second. You have a number of throttling options: *) set_bandwidth(12500000); set_throttle(0.5) # throttle is a float This will limit urlgrab to use half of your available bandwidth. *) set_throttle(6250000) # throttle is an int This will also limit urlgrab to use half of your available bandwidth, regardless of what bandwidth is set to. *) set_throttle(6250000); set_throttle(1.0) # float Use half your bandwidth *) set_throttle(6250000); set_throttle(2.0) # float Use up to 12,500,000 Bytes per second (your nominal max bandwidth) *) set_throttle(6250000); set_throttle(0) # throttle = 0 Disable throttling - this is more efficient than a very large throttle setting. *) set_throttle(0); set_throttle(1.0) # throttle is float, bandwidth = 0 Disable throttling - this is the default when the module is loaded. SUGGESTED AUTHOR IMPLEMENTATION (THROTTLING) While this is flexible, it's not extremely obvious to the user. I suggest you implement a float throttle as a percent to make the distinction between absolute and relative throttling very explicit. Also, you may want to convert the units to something more convenient than bytes/second, such as kbps or kB/s, etc. i����N(t responses(tparse150(tStringIO(t HTTPException(trange_tuple_normalizetrange_tuple_to_headert RangeErrortsetsfrom t.is import __version__s???(t_cCs|S(N((tst((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR AscCs |adS(sSet the DEBUG object. This is called by _init_default_logger when the environment variable URLGRABBER_DEBUG is set, but can also be called by a calling program. Basically, if the calling program uses the logging module and would like to incorporate urlgrabber logging, then it can do so this way. It's probably not necessary as most internal logging is only for debugging purposes. The passed-in object should be a logging.Logger instance. It will be pushed into the keepalive and byterange modules if they're being used. The mirror module pulls this object in on import, so you will need to manually push into it. In fact, you may find it tidier to simply push your logging object (or objects) into each of these modules independently. N(tDEBUG(tDBOBJ((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt set_loggerGscCs�yO|dkrtjd}n|jd�}ddl}|jj|dd�}|dkrrt|d�}n|dkr�t��n|j d�}t |�dkr�|d}nd}|dkr�|jtj �}n0|d kr|jtj�}n|j|�}|j|�|jd �}t|_|j|�|j|�Wn tttfk rqd}nXt|�dS(suExamines the environment variable URLGRABBER_DEBUG and creates a logging object (logging.logger) based on the contents. It takes the form URLGRABBER_DEBUG=level,filename where "level" can be either an integer or a log level from the logging module (DEBUG, INFO, etc). If the integer is zero or less, logging will be disabled. Filename is the filename where logs will be sent. If it is "-", then stdout will be used. If the filename is empty or missing, stderr will be used. If the variable cannot be processed or the logging module cannot be imported (python < 2.3) then logging will be disabled. Here are some examples: URLGRABBER_DEBUG=1,debug.txt # log everything to debug.txt URLGRABBER_DEBUG=WARNING,- # log warning and higher to stdout URLGRABBER_DEBUG=INFO # log info and higher to stderr This function is called during module initialization. It is not intended to be called from outside. The only reason it is a function at all is to keep the module-level namespace tidy and to collect the code into a nice block.tURLGRABBER_DEBUGt,i����Niis%(asctime)s %(message)stt-t urlgrabber(tNonetostenvirontsplittloggingt_levelNamestgettintt ValueErrort Formattertlent StreamHandlertsyststderrtstdouttFileHandlertsetFormattert getLoggertFalset propagatet addHandlertsetLeveltKeyErrortImportErrorR (tlogspectdbinfoRtlevelt formattertfilenamethandlerR((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_init_default_loggerZs6 cCs0ts dStjdt�tjdt�dS(Nsurlgrabber version = %sstrans function "_" = %s(Rtdebugt__version__R (((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_log_package_state�scCs|S(N((R ((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR �streplacecCs(t|t�r$|jd|�}n|S(s2convert 'unicode' to an encoded utf-8 byte string sutf-8(t isinstancetunicodetencode(tobjterrors((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_to_utf8�scCs6yt|�SWn!tk r1t|�jd�SXdS(Ntutf8(tstrtUnicodeEncodeErrorR7R8(te((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt exception2msg�s tURLGrabErrorcBseZdZd�ZRS(s� URLGrabError error codes: URLGrabber error codes (0 -- 255) 0 - everything looks good (you should never see this) 1 - malformed url 2 - local file doesn't exist 3 - request for non-file local file (dir, etc) 4 - IOError on fetch 5 - OSError on fetch 6 - no content length header when we expected one 7 - HTTPException 8 - Exceeded read limit (for urlread) 9 - Requested byte range not satisfiable. 10 - Byte range requested, but range support unavailable 11 - Illegal reget mode 12 - Socket timeout 13 - malformed proxy url 14 - HTTPError (includes .code and .exception attributes) 15 - user abort 16 - error writing to local file MirrorGroup error codes (256 -- 511) 256 - No more mirrors left to try Custom (non-builtin) classes derived from MirrorGroup (512 -- 767) [ this range reserved for application-specific error codes ] Retry codes (< 0) -1 - retry the download, unknown reason Note: to test which group a code is in, you can simply do integer division by 256: e.errno / 256 Negative codes are reserved for use by functions passed in to retrygrab with checkfunc. The value -1 is built in as a generic retry code and is already included in the retrycodes list. Therefore, you can create a custom check function that simply returns -1 and the fetch will be re-tried. For more customized retries, you can use other negative number and include them in retry-codes. This is nice for outputting useful messages about what failed. You can use these error codes like so: try: urlgrab(url) except URLGrabError, e: if e.errno == 3: ... # or print e.strerror # or simply print e #### print '[Errno %i] %s' % (e.errno, e.strerror) cGstj||�d|_dS(NsNo url specified(tIOErrort__init__turl(tselftargs((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRC�s(t__name__t __module__t__doc__RC(((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRA�s4tCallbackObjectcBseZdZd�ZRS(s�Container for returned callback data. This is currently a dummy class into which urlgrabber can stuff information for passing to callbacks. This way, the prototype for all callbacks is the same, regardless of the data that will be passed back. Any function that accepts a callback function as an argument SHOULD document what it will define in this object. It is possible that this class will have some greater functionality in the future. cKs|jj|�dS(N(t__dict__tupdate(REtkwargs((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRC�s(RGRHRIRC(((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRJ�scKstj|||�S(sJgrab the file at <url> and make a local copy at <filename> If filename is none, the basename of the url is used. urlgrab returns the filename of the local file, which may be different from the passed-in filename if the copy_local kwarg == 0. See module documentation for a description of possible kwargs. (tdefault_grabberturlgrab(RDR/RM((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRO�scKstj||�S(s0open the url and return a file object If a progress object or throttle specifications exist, then a special file object will be returned that supports them. The file object can be treated like any other file object. See module documentation for a description of possible kwargs. (RNturlopen(RDRM((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRPscKstj|||�S(s`read the url into a string, up to 'limit' bytes If the limit is exceeded, an exception will be thrown. Note that urlread is NOT intended to be used as a way of saying "I want the first N bytes" but rather 'read the whole file into memory, but don't use too much' See module documentation for a description of possible kwargs. (RNturlread(RDtlimitRM((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRQst URLParsercBsAeZdZd�Zd�Zd�Zd�ZdZd�ZRS(sGProcess the URLs before passing them to urllib2. This class does several things: * add any prefix * translate a "raw" file to a proper file: url * handle any http or https auth that's encoded within the url * quote the url Only the "parse" method is called directly, and it calls sub-methods. An instance of this class is held in the options object, which means that it's easy to change the behavior by sub-classing and passing the replacement in. It need only have a method like: url, parts = urlparser.parse(url, opts) cCsEt|�}|j}|jr6|j||j�}ntj|�}|\}}}}} } |s�t|�dkr�|tjkr�|ddkr�tj j |�}ndtj|�}tj|�}d}n|dkr�|j ||�}n|dkr|j|�}n|r,|j|�}ntj|�}||fS( s�parse the url and return the (modified) url and its parts Note: a raw file WILL be quoted when it's converted to a URL. However, other urls (ones which come with a proper scheme) may or may not be quoted according to opts.quote opts.quote = 1 --> quote it opts.quote = 0 --> do not quote it opts.quote = None --> guess iis/\sfile:thttpthttps(RTRUN(R;tquotetprefixt add_prefixturlparseRtstringtlettersRtpathtabspathturllibtpathname2urltprocess_httpRtguess_should_quotet urlunparse(RERDtoptsRVtpartstschemethostR\tparmtquerytfrag((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytparse/s( ( cCs?|ddks |ddkr-||}n|d|}|S(Ni����t/i((RERDRW((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRXUs c Cs.|\}}}}}}||||||fS(N(( RERdRDReRfR\RgRhRi((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR`\scCs=|\}}}}}}tj|�}||||||fS(s quote the URL This method quotes ONLY the path part. If you need to quote other parts, you should override this and pass in your derived class. The other alternative is to quote other parts before passing into urlgrabber. (R^RV(RERdReRfR\RgRhRi((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRVast0123456789ABCDEFc Cs�|\}}}}}}d|kr(dStj|d�}|dkr�x�|dkr�t|�|dkrodS||d|d!j�} | d|jks�| d|jkr�dStj|d|d�}qIWdSdS(s� Guess whether we should quote a path. This amounts to guessing whether it's already quoted. find ' ' -> 1 find '%' -> 1 find '%XX' -> 0 else -> 1 t it%i����ii(RZtfindRtupperthexvals( RERdReRfR\RgRhRitindtcode((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRans ( RGRHRIRjRXR`RVRqRa(((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRSs & tURLGrabberOptionscBseeZdZdd�Zd�Zd�Zd�Zd�Zd�Z d�Z d�Zd d �ZRS(sClass to ease kwargs handling.cKs3||_|dkr"|j�n|j|�dS(s�Initialize URLGrabberOptions object. Set default values for all options and then update options specified in kwargs. N(tdelegateRt _set_defaultst_set_attributes(RERuRM((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRC�s cCs8|jr+t|j|�r+t|j|�St|�dS(N(RuthasattrtgetattrtAttributeError(REtname((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt__getattr__�scCsM|jdkrdSt|j�td�kr;t|j�S|j|jSdS(sRCalculate raw throttle value from throttle and bandwidth values. iN(tthrottlettypetfloatt bandwidth(RE((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytraw_throttle�s cCsQd|_|d krdS|jr�|jj|�}|dkr�|dkra|jjd�}q�|dkr�|jjd�}q�n|dkr�d}n||_dS|jrMtdkr�yddl}|j�aWq�taq�XntrMxVtj|�D]B}|j d�rt r6t jd ||f�n||_PqqWqMndS(seFind the proxy to use for this URL. Use the proxies dictionary first, then libproxy. tftpRTRUNt_none_Ri����shttp://susing proxy "%s" for url %s(R�shttpshttps(RtproxytproxiesRtlibproxyt_libproxy_cachetProxyFactoryR%t getProxiest startswithRtinfo(RERDReR�R�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt find_proxy�s8 cKstd||�S(s�Create a derived URLGrabberOptions instance. This method creates a new instance and overrides the options specified in kwargs. Ru(Rt(RERM((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytderive�scKsi|jj|�|jd�r4t|j�|_n|jdkretdtd�|jf��ndS(s7Update object attributes with those provided in kwargs.trangetsimpletcheck_timestampisIllegal reget mode: %sN(NR�R�( RKRLthas_keyRR�tregetRRAR (RERM((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRw�scCsd|_d|_d|_d|_d|_d|_ddddddg|_d|_t |_ d|_d|_d|_ d t|_d|_d |_d|_t|_d|_d|_d|_d|_d|_d|_t|_d|_d|_d|_d|_ d|_!d|_"t#�|_$d|_%d|_&d|_'d|_(d|_)t|_*t|_+d|_,d|_-d|_.d|_/d|_0d|_1d |_2d|_3d|_4d|_5d|_6d|_7d|_8t|_9t|_:t|_;dS(s�Set all options to their default values. When adding new options, make sure a default is provided here. g�?ii����iiiiis urlgrabber/%sii,tPEMi iii<g��.ANi�i��i�'(<Rtprogress_objtmulti_progress_objtcurl_objR}R�tretryt retrycodest checkfunct _do_raisetfailfunct copy_localtclose_connectionR�R3t user_agentt ip_resolvet keepaliveR�R%R�R�R�tfailure_callbacktinterrupt_callbackRWtopenertTruet cache_openersttimeouttminratettextthttp_headerstftp_headerstdataRSt urlparserRVtusernametpasswordtssl_ca_certtssl_contexttssl_verify_peertssl_verify_hosttssl_keytssl_key_typetssl_certt ssl_cert_typetssl_key_passtsizetmax_header_sizetasynctmirror_grouptmax_connectionst timedhostst half_lifet default_speedtftp_disable_epsvtno_cachetretry_no_cache(RE((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRv�sl cCs |j�S(N(tformat(RE((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt__repr__ss cCs�|jj�}|jdk r.|jd�n|j�d}x9|D]1}||dt|�t|j|�f}qEW|jr�|jj|d�}||dd|f}n||d}|S(NRus{ s%-15s: %s, s s %-15s: %s s 'delegate't}(RKtkeysRuRtremovetsorttreprR�(REtindentR�tstktdf((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR�s % N( RGRHRIRRCR|R�R�R�RwRvR�R�(((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRt�s # = cCs |j�dS(N(t exception(R9((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR�(scCs?|s dSt|�r ||�S|\}}}||||�S(N(tcallable(tcbR9targtkarg((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt _run_callback+s t URLGrabbercBsSeZdZd�Zd�Zdd�Zddd�Zddd�Zd�Z RS(sProvides easy opening of URLs with a variety of options. All options are specified as kwargs. Options may be specified when the class is created and may be overridden on a per request basis. New objects inherit default values from default_grabber. cKst|�|_dS(N(RtRc(RERM((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRC<scGsd}x�|d}d}d}trEtjd||j|d�ny7t||f|i�}trwtjd�n|SWnOtk r�}|}|j}n.tk r�}|}|j}|s��q�nXtr�tjd|�n|rGtrtjd|�nt d|d|dd |d |jd|j �} t|| �n|jdkse||jkr�tr{tjd�n�nt|d d�} | dk r�| |j kr�tr�tjd| |j �n�n| dk r | dkr |j r t|_q q dS(Niisattempt %i/%s: %stsuccesss exception: %sscalling callback: %sR�RDttriesR�R�sretries exceeded, re-raisingterrnos)retrycode (%i) not in list %s, re-raising(RRR�R�tapplyRAR�tKeyboardInterruptR�RJR�R�RyR�R�R�(RERctfuncRFR�R�tcallbacktrR?R9t retrycode((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_retry?sT !cKs�t|�}|p|jj|�}trDtjdt|��n|jj||�\}}|j||d�d�}|j |||�S(sopen the url and return a file object If a progress object or throttle value specified when this object was created, then a special file object will be returned that supports them. The file object can be treated like any other file object. scombined options: %sicSst|ddd|�S(NR/Rc(tPyCurlFileObjectR(RcRD((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt retryfunc}s( R;RcR�RR2R�R�RjR�R�(RERDRcRMRdR�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRPqs cKs|t|�}|p|jj|�}trDtjdt|��n|jj||�\}}|\}}}} } }|j||�|d kr�t jjt j|��}|s�d}q�n|dkr�|jr�t j|�}|rt jjd||�}nt jj|�sHtdtd�|f�}||_|�q�t jj|�s�tdtd�|f�}||_|�q�|js�|jd k r�td |d |�} t|j| �n|Sn|jr||_||_t|jp�d�|_tj |�|Sd�}y|j!||||�SWn?tk rw}t"j#|dd|�||_$t|j%|�SXd S(s grab the file at <url> and make a local copy at <filename> If filename is none, the basename of the url is used. urlgrab returns the filename of the local file, which may be different from the passed-in filename if copy_local == 0. scombined options: %ss index.htmltfiles//isLocal file does not exist: %sisNot a normal file: %sR/RDicSs�t|||�}z�|j�|jrq|jd|jd}|jd|jd}tj|||d�n|jdk r�td|d|�}t |j|�nWd|j �X|S(NiiR/RD(R�t_do_grabt_tm_lastt _tm_firstt_THRLRR�RJR�tclose(RcRDR/tfotdlsztdltmR9((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR��s N(&R;RcR�RR2R�R�RjR�RRR\tbasenameR^tunquoteR�turl2pathnametnormpathtexistsRAR RDtisfileR�R�RJR�R�R/RR�t_async_queuetappendR�R�RLR�R�(RERDR/RcRMRdReRfR\RgRhRiterrR9R�R?((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRO�sV c Ks�t|�}|p|jj|�}trDtjdt|��n|jj||�\}}|j||d�|dk r�|d}nd�}|j ||||�}|r�t|�|kr�tdt d�||f�}||_|�n|S(s2read the url into a string, up to 'limit' bytes If the limit is exceeded, an exception will be thrown. Note that urlread is NOT intended to be used as a way of saying "I want the first N bytes" but rather 'read the whole file into memory, but don't use too much' scombined options: %siicSs�t|ddd|�}d}ze|dkr<|j�}n|j|�}|jdk r�td|d|�}t|j|�nWd|j�X|S(NR/RcRR�RD(R�RtreadR�RJR�R�(RcRDRRR�R�R9((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR��sisExceeded limit (%i): %sN(R;RcR�RR2R�R�RjR�RR�RRAR RD( RERDRRRcRMRdR�R�R�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRQ�s cCs!t|�r|difS|SdS(N((R�(REtcallback_obj((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_make_callback�s N( RGRHRIRCR�RRPRORQR�(((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR�3s 2E*R�cBs�eZd�Zd�Zd�Zd�Zd�Zee�Zedd��Z id�Z d�Zd �Zd �Z d�Zd�Zd �Zdd�Zd�Zdd�Zdd�Zdd�Zd�Zd�ZRS(cCsd|_d|_d|_||_tj|j�d|_||_t |_ d|_||_|jj dkrtd�nt |_d|_d|_tj�|_d|_d|_d|_t |_d|_d|_t |_d|_d|_|j�dS( NRiR�sYcheck_timestamp regets are not implemented in this ver of urlgrabber. Please report this.iii (NN(RR�t _hdr_dumpt_parsed_hdrRDRYturlsplitReR/R%R�t reget_timeRcR�tNotImplementedErrort _completet_rbuft _rbufsizettimet_ttimet_tsizet_amount_readt _reget_lengtht _prog_runningt_errorR�t _hdr_endedR�R�t_do_open(RERDR/Rc((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRC�s2 cCs/t|j|�r"t|j|�St|�dS(s�This effectively allows us to wrap at the instance level. Any attribute not found in _this_ object will be searched for in self.fo. This includes methods.N(RxR�RyRz(RER{((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR|scCsIy0|jt|�tj�f}|jdkr=||_n ||_|js�|jjr�|j |j }|jjj|jt j|j�|jd|d|jj�t|_|jjj|j�q�n|jt|�7_y|jj|�Wn,tk r$}tdt|��|_dSXt|�SWntk rDdSXdS(NR�R�ii����(RRR�R�RR�RRcR�R�Rtstartt_prog_reportnameR^R�RDt_prog_basenameR�R�RLR�twriteRBRAR@t _cb_errorR�(REtbufttmR�R?((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt _retrieve"s0 cCsk|jr'd|_d|_t|_n|jdt|j�d|jj�rRdSy�|jdkr|j �j d�dkr�|jd �d }t|�|_q�|j r�|jdkr�d|kr�t|_ d|_d|_d|_|jjd�q�n�|jdkr�d}|jd �rT|dj�}t|�dkrrd}qrn|jd�rrt|�}n|r�t|�|_q�n|j �j d�dkr�d j|jd �d �}|j�}tj|�d|_||_n|j|7_t|j�dkrD|dkrDt|_trDtjd�qDnt|�SWntk rftj SXdS(NRitcurtmax_sizei����RTRUscontent-length:t:is 200 OK R�s213 iis150 tlocations s header ended:(shttpshttps(sftp(!RR�R�R%t_over_max_sizeRRcR�RetlowerRoRRR�RR�RRR�ttruncateR�tstripRtjoinRYR�RDR�RR2R�tpycurltREADFUNC_ABORT(RERtlengthR�R((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt _hdr_retrieve?sR $ ! cCso|jr|jS|jjd�}|d7}t�}|j|j|�|jd�tj|�|_|jS(Ns ii(R�R�RoRR tseekt mimetoolstMessage(REt statusendthdrfp((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_return_hdr_objrs tfgetcCs|jjtj�S(N(R�tgetinfoRt RESPONSE_CODE(RE((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt<lambda>sc Cs0|s|j}n|js4|jjtjd�n|jjtjt�|jjtjt �|jjtj |j�|jjtj|j �|jjtj|j�|jjtjt �|jjtjt �|jjtjt �trtjdkr|jjtjt �n|jr@|jjtj|j�n|jr�|jj�}|dkr�|jjtjtj�n|dkr�|jjtjtj�n|dkr�|jjtjtj�q�n|jjtjt �|jjtjd�d}t|d�r,t |j!p#d �}n|jjtj"|�|jjtj#|j$p]d �|jjtj%|�|j&dkr�|j'r�|jjtj(|j'�|jjtj)|j'�n|jjtj*|j+�|j,r�|jjtj-d�n|j.r$|jjtj/|j.�n|j0rI|jjtj1|j0�n|j2r�|jjtj3|j2�|jjtjd�n|j4r�|jjtj5|j4�n|j6r�|jjtj7|j6�q�n|j&dkrdg}|j8dk r)x1|j8D]#\}}|j:d||f�q�Wn|j;rB|j:d�n|rd|jjtj<|�qdn|j=sv|j>r�|j?�}|r�|jjtj@|�q�nt|d�r�|jA�r�|jjtjBt |jA���n|jCdk r/|jjtjD|jC�|jjtjEtjFtjG�n|jHr�|jIr�|j&dkrl|jjtjJtjF�n|jHr�|jIr�d|jH|jIf}|jjtjK|�q�n|jLr�|jjtjMt �|jjtjNtO|jL��n|jPr|jjtjQt�n|jjtjR|jS�dS(Nii twhatevertipv4tipv6ii,R�ii�RUiRTs%s:%ssPragma:no-cacheR�(shttpshttps(shttpshttps(TRcR�R�tsetoptRtFORBID_REUSEt NOPROGRESSR%tNOSIGNALR�t WRITEFUNCTIONRtHEADERFUNCTIONRtPROGRESSFUNCTIONt_progress_updatetFAILONERRORtOPT_FILETIMEtFOLLOWLOCATIONRR-tVERBOSER�t USERAGENTR�Rt IPRESOLVEtIPRESOLVE_WHATEVERtIPRESOLVE_V4tIPRESOLVE_V6t MAXREDIRSRxRR�tCONNECTTIMEOUTtLOW_SPEED_LIMITR�tLOW_SPEED_TIMEReR�tCAPATHtCAINFOtSSL_VERIFYPEERR�R�tSSL_VERIFYHOSTR�tSSLKEYR�t SSLKEYTYPER�tSSLCERTR�tSSLCERTTYPER�tSSLKEYPASSWDR�RR�R�t HTTPHEADERR�R�t_build_rangetRANGER�tMAX_RECV_SPEED_LARGER�tPROXYt PROXYAUTHtHTTPAUTH_ANYtHTTPAUTH_GSSNEGOTIATER�R�tHTTPAUTHtUSERPWDR�tPOSTt POSTFIELDSR;R�tFTP_USE_EPSVtURLRD( RERctiprR�theadersttagtcontentt range_strtuserpwd((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt _set_opts�s� % " c CsM|jr dSy|jj�Wn�tjk r}|j}|jd}tj|j �}|j drx|j d}n|dkr�d|ko�dknr�t|dt��qI|dkr�t dtd�||f�}||_ |�qI|d krt�qIi+td �d6td�d 6td�d6td�d6td�d6td�d6td�d6td�d6td�d6td�d6td�d6td �d!6td"�d#6td$�d6td%�d&6td'�d(6td)�d*6td+�d6td,�d-6td.�d/6td0�d16td2�d36td4�d56td6�d76td8�d96td:�d 6td;�d<6td=�d>6td?�d@6tdA�dB6tdC�dD6tdE�dF6tdG�dH6tdI�dJ6tdK�dL6tdM�dN6tdO�dP6tdQ�dR6tdS�dT6tdU�dV6tdW�dX6tdY�dZ6td[�d\6}t|jd]�p^|j|d^�}|r�d|ko~dknr�d_|jj�||jdckr�tj|�p�|f}ndb||f}|}t d|�}||_ ||_|�nHX|j d]rI|j d]}t d|�}tj|j �|_ |�ndS(dNiii�i+RiisTimeout on %s: %si*sCouldn't resolve proxyisCouldn't resolve hostisCouldn't connectisBad reply to FTP serveris Access deniedi sBad reply to FTP passisBad reply to FTP pasvi sBad reply to FTP 227isCouldn't get FTP hostisCouldn't set FTP typeisPartial fileisFTP RETR command failedisHTTP returned errorisWrite errors Upload failedis Read erroris Out of MemoryisOperation timed outsFTP PORT command failedisFTP REST command failedisRange failedi!sHTTP POST failedi"sSSL CONNECT failedi#sCouldn't resume downloadi$sCouldn't read filei%sAborted by callbacksToo many redirectsi/s$Peer certificate failed verificationi3s%Got nothing: SSL certificate expired?i4sSSL engine not foundi5sSSL engine set failedi6sNetwork error send()i7sNetwork error recv()i8sLocal certificate failedi:sSSL set cipher failedi;sLocal CA certificate failedi<sHTTP bad transfer encodingi=sMaximum file size exceededi?sFTP SSL failedi@sAuthentication failureiCsOut of disk space on serveriFsRemove file existsiIs3Problem with the SSL CA cert (path? access rights?)iMis <Unknown>s%s Error %d - %sRTRUscurl#%s - "%s"(shttpshttps(R�R�tperformRterrort http_codeRFR^R�RDRRyR�RAR R=RReRpRRs( RER?RsterrcodeterrurlR�t pyerr2strterrstrtmsg((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_do_perform�s� ( %# cCsgt|jd�r6|jjdk r6|jj|_n t|_|jj�|j�|j�|jS(NR�( RxRcR�Rt_curl_cachetresetR[R�R�(RE((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRas$ cCsdS(N((RE((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_add_headerslscCs'd}d}|jjr�t|j�tjkr�ytj|j�}Wnt k rYq�X|tj |_|tj}||_ ||_|df}d|_n|jjr�|jj}|ddkr�d|df}n|d||df}n|r#t|�}|r#|jd�dSndS(NiRit=(RRcR�R~R/ttypestStringTypesRtstattOSErrortST_MTIMER�tST_SIZERRR�R�RR(REtreget_lengthtrtR�theader((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRHos,$ c Cs�|j|jfSyq|jjretj�}tj|jj�z|j|�}Wdtj|�Xn|j|�}|j�}Wn!t k r�}t dtd�|j|f�}|j|_|�n�t k r}t dtd�||jf�}|j|_|�n�tjk rn}t dtd�||jf�}|j|_||_|j|_|�nAtk r}t|d�r�t|jtj�r�t dtd�|j|f�}|j|_|�q�t d td �|j|f�}|j|_|�n�tk rU}t dtd�||jf�}|j|_|�nZtk r�}t dtd �|jj|j|f�}|j|_|�nX||fSdS(NisBad URL: %s : %si s%s on %sitreasonisTimeout on %s: %sisIOError on %s: %siisHTTP Exception (%s) on %s: %s(R�thdrRcR�tsockettgetdefaulttimeouttsetdefaulttimeouttopenR�RRAR RDRturllib2t HTTPErrorRsR�RBRxR6RrRlRt __class__RG( REtreqR�told_toR�RsR?R�tnew_e((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt _make_request�sT" " " $" " " cCs�|jr dSt}t|j�tjkr|jrt}t|j�|_t j j|j�|_|j rvd}nd}tr�tjd|j|f�nyt|j|�|_Wq#tk r}tdtd�|j|f�}|j|_|�q#Xnd|_d|_t�|_y|j�Wn3tk rf}|jj�|jj�|�nX|r�|jj�|jj�tdk r�ytj|jd|j�Wq�q�Xn|jjtj �}|d krNyt j!|j||f�WqNt"k rJ}tdtd �|j|j|f�}|j|_|�qNXnyt|jd�|_Wq�tk r�}tdtd�|j|f�}|j|_|�q�Xn|jj#d �t|_dS(s.dump the file to a filename or StringIO bufferNtabtwbs$opening local file "%s" with mode %sis-error opening local file from %s, IOError: %stMEMORYsuser.xdg.origin.urli����s7error setting timestamp on file %s from %s, OSError: %sR�s'error opening file from %s, IOError: %si($R�R%R~R/RiRjR�R=RRR\R�R R�RR�RwR�RBRAR RDRRdtflushR�txattrRRR�R#Rt INFO_FILETIMEtutimeRlR(REt _was_filenametmodeR?R�tmod_time((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR��sp ! cCs�|jrD|dk rDt|j�}||kr=||}qDdSn|jsZ|j�n|jg}t|j�}x�|dks�|rf|jj�r�|j|jj�tj�|j }|dkr�tj |�ntj�|_ n|dkr|j}nt||j�}y|j j|�}Wn�tjk rz}tdtd�|j|f�} |j| _| �n�tjk r�}tdtd�|j|f��|j| _| �nGtk r }tdtd�|j|f��|j| _| �nXt|�} | s Pn|r3|| }n|j|�|| }| |_|j| |_qxWtj|d�|_dS( sfill the buffer to contain at least 'amt' bytes by reading from the underlying file object. If amt is None, then it will read until it gets nothing more. It updates the progress meter and throttles after every self._rbufsize bytes.NiisSocket Error on %s: %sisTimeout on %s: %ssIOError on %s: %sR(R�RRR�R�RcR�RR�R�tsleepR�tminR�R�RtR]RAR RDR�RBR�RRZR(REtamttLRtbufsizetdifft readamounttnewR?R�tnewsize((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_fill_buffersX " " " cCso|jd|j|j�r dSy0|jrO||j7}|jjj|�nWnttfk rjdSXdS(NRi����( RRRRRcR�RLR�RB(REtdownload_totalt downloadedtupload_totaltuploaded((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR0[s cCs�|s-|jjs|j}q-|jj}n|s7tS|tt|�d�kr�td�|j||f}tj|f|_ t StS(Ng�������?s-Downloaded more than max size for %s: %s > %s(RcR�R%RRR RDRtE_FILESIZE_EXCEEDEDRR�(RERRRc((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRfs cCsQ|j|�|dkr/|jd}|_n|j| |j|}|_|S(NR(R�RR�(RER�R�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR�xs i����cCs=|js|j�n|jj�Stj|jd�}x�|dkr�d|kogt|j�knr�t|j�}|j||j �t|j�|ks�Pntj|jd|�}q;W|dkr�t|j�}n |d}d|ko t|j�knr|}n|j| |j|}|_|S(Ns ii( R�R�R�treadlineRZRoR�RR�R�(RERRtiR�R�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR��s" 5 % cCs3|jr"|jjj|j�n|jj�dS(N(RRcR�tendRR�R�(RE((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR��s cCs|jS(si Provide the geturl() method, used to be got from urllib.addinfourl, via. urllib.URLopener.* (RD(RE((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytgeturl�sN(RGRHRCR|RRR!tpropertyRsR^R[RdRRgRHR~R�RR�R0RR�R�R�R�(((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR��s, 3 t l # 9 Q? tGLOBAL_ACK_EINTRcCstj�tj�adS(sCTo make sure curl has reread the network/dns info we force a reloadN(ReR�RtCurl(((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytreset_curl_obj�s cCs |t_dS(s8Deprecated. Use: default_grabber.throttle = new_throttleN(RNR}(tnew_throttle((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytset_throttle�scCs |t_dS(s:Deprecated. Use: default_grabber.bandwidth = new_bandwidthN(RNR�(t new_bandwidth((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt set_bandwidth�scCs |t_dS(s@Deprecated. Use: default_grabber.progress_obj = new_progress_objN(RNR�(tnew_progress_obj((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytset_progress_obj�scCs |t_dS(s<Deprecated. Use: default_grabber.user_agent = new_user_agentN(RNR�(tnew_user_agent((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytset_user_agent�siiiiiic CsNi|d6|d6|d6|d6|d6|d6|d6| d6} t||| �S( s5Deprecated. Use: urlgrab() with the retry arg insteadR�R�R�R}R�R�R�R�(RO(RDR/R�R�R�R}R�tnumtriesR�R�RM((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt retrygrab�s s%[(,)] s%%%02xcCs|dkrdS|tkr dS|tkr0dSt|�tttfkrUt|�St|�tkry|j d�}nt|�tkr�d�}ddj t||��St|�tkr�dd j tt |��St|�tkrd d j tt |��Std|�dS(NRR�R%tUTF8cSstj||�S(N(t_quoter_mapR(tc((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytquoter�ss'%s'Rs(%s)Rs[%s]sCan't serialize %s(RR�R%R~RtlongRR=R7R8Rtmapttuplet_dumpstlistt TypeError(tvR�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR��s$ cCs\d�}d}g}d}}xtr)|t|�ksJ||dkr�||krs|j||||!��n|t|�kr�Pn||dkr�||dkr�t|�}n|dj|�|\}}n|d}}q"||dkr||f}g}|d}}q"|d7}q"W|r9t�nt|�dkrX|d}n|S(Nc SsD|dkrdS|dkr tS|dkr0tSyt|�SWntk rQnXyt|�SWntk rsnXt|�dkr@|d|dko�dknr@g}d}xutr-|jd |�}|j|||!�|dkr�Pn|jt t||d|d !d���|d }q�Wdj |�}n|S( NRR�R%iii����t'iRniiR(RR�R%RRRRRoR�tchrR(R�tretR�tj((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytdecode�s4 6 +is,)]s)]t)is[((RR�RR�R�R(R�R�tstktlR�R�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_loads�s4 " cCsZtj|d�}|sdSx*|ddkrH|tj|d�7}qW|d jd�S(Nii����s (RR�RR(tfdR((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt _readlinesst_ExternalDownloadercBs2eZd�Zd"Zd�Zd �Zd!�ZRS(#cCsdtjddtjdtj�|_|jjj�|_|jjj�|_i|_d|_dS(Ns /usr/libexec/urlgrabber-ext-downtstdinR!i( t subprocesstPopentPIPEtpopenR�tfilenoR!trunningtcnt(RE((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRC%s RDR/R�R�R�R�R}R�R�R�R�R�R�R�RWR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�cCs�g}xO|jD]D}t||�}|dkr7qn|jd|t|�f�qW|jrz|jrz|jd�ndj|�}tr�tj d|j |j|j�n|j d7_ ||j|j <tj|j|d�dS(Ns%s=%ssprogress_obj=TrueRmsattempt %i/%s: %sis (t_optionsRyRR�R�R�R�RRR�R�R�RDR�R�RR R�(RERcR�R�R�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRAs!"cCs�g}t|j�}|s:tr1tjd�nt�nxR|D]J}|jdd�}tt|d �\}}t|�dkr�|j |j j|�qAn|j j|�}|ddkr�d}tr>tjd�q>n\tt|d�|d�}|dd kr%t|d�|_ntr>tjd |�ntj|jt|d�t|d�||jd�|j|||f�qAW|S( Nsdownloader diedRmiiitOKR�it0sfailure: %sii(R�R!RR�R�RR�RRR�t _progressRLtpopRRARsR�RDRR�R�(RER�tlinestlinet_idR�Rctug_err((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR\Ps2 7cCs1|jjj�|jjj�|jj�dS(N(R�R�R�R!twait(RE((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytabortks(surlsfilenamestimeoutsminratesclose_connections keepalivesthrottles bandwidthsrangesregets user_agentshttp_headerssftp_headerssproxysprefixsusernamespasswordsssl_ca_certsssl_certs ssl_cert_typesssl_keysssl_key_typesssl_key_passsssl_verify_peersssl_verify_hostssizesmax_header_sizes ip_resolvesftp_disable_epsvsno_cache(RGRHRCR�RR\R�(((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR�$s" t_ExternalDownloaderPoolcBs,eZd�Zd�Zd�Zd�ZRS(cCs%tj�|_i|_i|_dS(N(tselecttepollR�tcache(RE((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRCqs cCs�tj|j�j}|jj|d�}|stt�}tj|j tj �}tj|j tj|tjB�n|j j|jtj�||j|j<|j|�dS(N(RYR�RDtnetlocR�R�RR�tfcntlR�tF_GETFDtF_SETFDt FD_CLOEXECR�tregisterR!R�tEPOLLINR�R(RERcRftdltfl((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRvs #cCsg}x |jj�D]�\}}|tj@rNtrEtjd�nt�n|tj@sat�|j |j �}|s�qnt|�dks�t�|j|�t j|ddj�j}||jkr�|j|j�n|jj|�|j j|�|j|<qW|S(Nsdownloader diedii(R�tpollR�tEPOLLHUPRR�R�R�tAssertionErrorR�R\RtextendRYR�RDR�R�R�t unregisterR�(RER�R�teventtdoneRf((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR\�s$ cCs_x4|jj�D]#}|jj|j�|j�qWx!|jj�D]}|j�qGWdS(N(R�tvaluesR�R�R!R�R�(RER�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR��s (RGRHRCRR\R�(((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR�ps csri}x_tD]W}|jr |jr |j|j�p:d\}}|d||jf||j<q q Wx.|D]&}||\}}|j||�qoWt��i�t����fd������fd�}z\y'd}xtr|t t�kr�j sPn|�q�nt|}|d7}x&t �j �tjj krX|�q3Wtr�tjdt �j �tjj �n|jrx|j\}}} } d}d}x�|jD]�} | d}|| kr�q�ntj|�\}}|d�j|d�:}|o+| jdi�jdt�}| j|d�||f}|dksb||kr�| }|}q�q�W|dkr�td td ��|_||j_t|j|�q�n|jd�p�|j}|jj|jdi��|_|d}|jdi�jd�}||f|_|j ||j!�}|j"j#||�\}}|j$||d�||_%n|j\}}|�kr�d}nx)�j|d�|p�d kr�|�q�Wtr�tjd|�j|d�|�n�|d�q�WWn.t&k r5}|j'dkr,�nt(�nXWd�j)�x|D]}|j*�qKWt2tj+�XdS(s)Process queued requests in parallel. iics�||_y�j|�Wn<tk rX}tdt|��|_t|j|�dSX|j\}}�j |d�d�|<|j r�|jr�|jj�|_ |j jd|j�q�tj�|_ ndS(NiiiR�(R�RRlRAR@R�R�R�R�RR�R�tnewMeterR�R�R�(RcR�R?tkeyRR(R�thost_con(s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR�s c s}xv�j�D]h\}}}|j\}}�|cd8<|dkr�|jr�yt|j|�Wq}tk ry}q}Xq�n|jr5|jr�|r�|jj d�n,|jj j||j7_|jj |�|jj|j�n?|jjd|jd|j�|jj|�|jj |�|`n|dkrGq n|dkr�|�kr�|jd kr�tr�tjd||�n�j|�t�n|jp�d}|jr�||_yt|j|�Wq�tk r�}d}q�Xn|j|krT|j|jkrT|jdkr:|jr:t|_n�||jd�q n|jr\|j\}}}} |j |j!t"|�f�|j#|d�d||<||_$||_|j%p�i} |jr t&|�|_t'| �} | jt|j|��n| j#dd�sP| j#d d�r=| j|�nt(j |�q n||_)n||_t|j*|�q WdS(NiR�tnowiismax_connections(%s) %s => 1itfailR�(ii(+R\R�RR�R�RAR�R�R�tfailuretrettotalR�R�tremoveMeterRR�RLR�RR�taddR�R�R�R�R�R�R�R�R�R�R�RDR@Rtmirrortdefault_actionRtdictR�R:R�(RcR�R�R�RRR�tmgR:tfailedtremovedtaction(R�R�tsingleR(s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR\�st ' ! smax_connections: %d/%dR�RMtprivateisNo more mirrors to try.tgrabberR�ismax_connections(%s): %d/%siN(ii(,R�R�R�RR�RR�RR�RR�RNRcR�RR�R�RtmirrorsR�testimateR%RAR R�R:R�R�R�R�RuR�t _join_urltrelative_urlR�RjR�RDRBR�R�R�R�tsave(tmetertmetersRctcountR�R\tidxR�R:R�R�tbestt best_speedR�R�tspeedR�R�R�RRRDRdR?((R�R�R�Rs6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt parallel_wait�s� % G % % ! !% R�cBsSeZiZdZed��Zed��Zedd��Zed��Z RS(cCs�tjj}|r�tjdkr�y�ttj��}x�t|�D]�}yS|j dd�\}}}}t|�t|�t t|�|�ftj|<WqCtk r�t r�t jd|�q�qCXqCWWntk r�nXtt_ndS(NRmis#Error parsing timedhosts: line "%s"(RNRcR�R�tdirtyRRR�RwtrsplitR�thostsRRR�RBR%(R/R�R�RfRR�tts((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytloadm s5 cCs�tjj}|r�tjtkr�d|tj�f}y]t|d�}x-tj D]"}|j |dtj |�qSW|j�tj||�Wnt k r�nXtt_ndS(Ns%s.%dtws %d %d %d (RNRcR�R�R R�RtgetpidRwRR R�trenameRBR%(R/ttmptfRf((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR| s cCs<tj|�jjd�dp"|}|s/dStj�tjj|�pNd\}}}tj�} |dkr�|r�|dkr�dSd|| t jj} t |dd�d}|dkr�| ||||| |}nd}n+t|d d�d krd}n |d7}||| ftj|<tt_dS( Nt@i����ig��.Aig�?g�?i Rsi�i(iii(RYR�R�RR�RRRR�RRNRcR�R�RyR�R (RDtdl_sizetdl_timeR�tbaseurlRfRR�R R�tk1tk2((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyRL� s&% !! cCs�tj�tj|�jjd�dp,|}tjj}ytj |\}}}Wnt k ro|dfSX|d|9}d|tj�tjj}||d||}||fS(NRi����iii( R�RRYR�R�RRNRcR�RR)R�R�(RRfR�RR�R R�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR�� s % N( RGRHRRR tstaticmethodRRRLR�(((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR�i sc Cs9ytjdd!\}}Wn/tk rKdGtjdGdGHtj�nXi}x@tjdD]1}tj|dd�\}}t|�||<q`Wtd�td�d t j t jfGHyddlm }Wntk r�}nX|�|d <ytt||f|�}Wntk r+}|GHn XdG|GHdS(Niisusage:is8<url> <filename> [copy_local=0|1] [close_connection=0|1]Rhg�?i is)throttle: %s, throttle bandwidth: %s B/si����(ttext_progress_meterR�sLOCAL FILE:i�(RtargvRtexitRZRRR�R�RNR}R�tprogressRR*R�RORA( RDR/RMtaR�R�RR?R{((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt _main_test� s0 c Cs6ytjdd!\}}Wn/tk rKdGtjdGdGHtj�nXi}x@tjdD]1}tj|dd�\}}t|�||<q`Wyddlm}Wnt k r�}nX|�|d <d d�}|did d 6f|d<yt t||f|�} Wntk r(}|GHn XdG| GHdS(Niisusage:is8<url> <filename> [copy_local=0|1] [close_connection=0|1]Rhi����(RR�tfoocSsp|G|GHddl}|j�}|dkrDdGHtdd��n|dkrgdGHtdd��ndGHdS( Ni����g�?s forcing retryg�?sforcing failurei����sforcing immediate failureR�(trandomRA(R/thellotthereR"trnum((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pytcfunc� s R#R$R�sLOCAL FILE:(shello( RRRRRZRRRRR*R�R�RA( RDR/RMRR�R�RR?R&R{((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_retry_test� s, c Cs�ddl}|dkr!t}nd|GHt|�}|j�}|j�x�tttt gD]p}|j |�}|j �}t|dd�}d|jG|||�|j �}||kr�dGHq_dGHq_WdS(Ni����susing file "%s" for comparisonsistesting %-30s tpassedtFAILED(t cStringIORt__file__RwR�R�t_test_file_object_smallreadt_test_file_object_readallt_test_file_object_readlinet_test_file_object_readlinesRR�RGtgetvalue( R/R*R�ts_inputttestfunctfo_inputt fo_outputtwrapperts_output((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt_file_object_test� s( cCs0x)|jd�}|j|�|sdSqdS(Ni(R�R (R5R4R�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR, s cCs|j�}|j|�dS(N(R�R (R5R4R�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR- scCs-x&|j�}|j|�|sdSqdS(N(R�R (R5R4R�((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR. s cCs)|j�}|jtj|d��dS(NR(t readlinesR RZR(R5R4tli((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyR/ st__main__ttest(WRIRRRYR�RZR^RxthttplibRRtthreadRiRkRtftplibRRRRtR�R�t byterangeRRRR�RxRR*RGRR3ti18nR RcRR R1R4R;R@RBRARJRORPRQRSRtR�R�tobjectR�RNR�tglobal_inittGLOBAL_DEFAULTR�R�ReR�R�R�R�R�R�R�R�R�tordR�R�R�R�R�R�R�R R�R R'R7R,R-R.R/(((s6/usr/lib/python2.7/site-packages/urlgrabber/grabber.pyt<module>s�$ ! 1 9 l� � ��� $ 0 L0�Q "
/home/../lib/python2.7/site-packages/rhn/../urlgrabber/grabber.pyc