Repository URL to install this package:
Version:
3.3.42 ▾
|
ó ~EYc @ s$ d Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z e d Z d Z d Z d Z e e d Z d Z d d Z d Z d e f d YZ d e f d YZ d e f d YZ d Z d Z d Z d S( s3 Miscellaneous utility functions for use with Swift.iÿÿÿÿNt truet 1t yest ont tt yt d41d8cd98f00b204e9800998ecf8427ec C s. | t k p- t | t j o- | j t k S( s¯ Returns True if the value is either True or a string in TRUE_VALUES. Returns False otherwise. This function comes from swift.common.utils.config_true_value() ( t Truet isinstancet sixt string_typest lowert TRUE_VALUES( t value( ( sF /home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/utils.pyt config_true_value s c C s | s d | St | } d g t d } x6 | d D] } | d k rN Pn | d :} q8 W| d } | st d | S| d k r d | | f Sd | | f Sd S( s convert a number > 1024 to printable format, either in 4 char -h format as with ls -lh or return as 12 char right justified string s %12st KMGTPEZYiÿÿÿÿiÿ g @s %4si s %3d%ss %.1f%sN( t floatt Nonet list( t num_bytest human_flagt numt suffixest suffix( ( sF /home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/utils.pyt prt_bytes( s c C s yL t | } | j s' t n t | } | d k rK t n Wn t k rk t d n Xt | t j r´ y | j d } Wqº t k r° t d qº Xn | } | j d d } t | d k s| d st | d | rý d n d ! r,| rt d q,t d n d d d d d g } | j | k r{t j d } | j d | j n | st t j | } n | } d j | j t | | rÄd n d | g } t | t j sø| j d } n t j | | j d t j j } d j d | d | d | } | r]| d j | d 7} n t | t j r|| j d S| Sd S( sÅ Generates a temporary URL that gives unauthenticated access to the Swift object. :param path: The full path to the Swift object or prefix if a prefix-based temporary URL should be generated. Example: /v1/AUTH_account/c/o or /v1/AUTH_account/c/prefix. :param seconds: If absolute is False then this specifies the amount of time in seconds for which the temporary URL will be valid. If absolute is True then this specifies an absolute time at which the temporary URL will expire. :param key: The secret temporary URL key set on the Swift cluster. To set a key, run 'swift post -m "Temp-URL-Key: <substitute tempurl key here>"' :param method: A HTTP method, typically either GET or PUT, to allow for this temporary URL. :param absolute: if True then the seconds parameter is interpreted as an absolute Unix time, otherwise seconds is interpreted as a relative time offset from current time. :param prefix: if True then a prefix-based temporary URL will be generated. :raises: ValueError if seconds is not a whole number or path is not to an object. :return: the path portion of a temporary URL i s seconds must be a whole numbers utf-8s# path must be representable as UTF-8t /i i i s# path must at least contain /v1/a/c/s2 path must be full path to an object e.g. /v1/a/c/ot GETt PUTt HEADt POSTt DELETEt swiftclientsC Non default HTTP method %s for tempurl specified, possibly an erroru s prefix:t u0 {path}?temp_url_sig={sig}&temp_url_expires={exp}t patht sigt expu &temp_url_prefix={}N( R t is_integert ValueErrort intR R t binary_typet decodet UnicodeDecodeErrort splitt lent allt uppert loggingt getLoggert warningt timet joint strt encodet hmact newt hashlibt sha1t hexdigestt format( R! t secondst keyt methodt absolutet prefixt path_for_bodyt partst standard_methodst loggert expirationt hmac_bodyR" t temp_url( ( sF /home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/utils.pyt generate_temp_urlB sP < ' c C s± | j d d k rN t j d t j | d d } | j } Wd QXn d } | j d d } d | k r | j d d d j d d d } n t j | j | S( Ns content-encodingt gzipt fileobjt modet rs utf-8s content-typeR s ; charset=i t ;i ( t getRH t GzipFileR t BytesIOt readR* t jsont loadsR( ( t headerst bodyt gzt charsett content_type( ( sF /home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/utils.pyt parse_api_response s $)R c C sÌ i } t | t j r' | j } n x | D] } t | t j rz d | k re t d | n | j d d } n t | d k r¢ t d | f n | d j | | | d j <q. W| S( Nt :sO Metadata parameter %s must contain a ':'. Example: 'Color:Blue' or 'Size:Large'i i sb Metadata parameter %r must have exactly two items. Example: ('Color', 'Blue') or ['Size', 'Large']i ( R t collectionst Mappingt itemsR R R% R* R+ t stript title( t optionsR? RS t item( ( sF /home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/utils.pyt split_request_headers s &c C s? y&