o `-@sbdZddlmZddlmZddlmZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZe jdkr?eejfZnefZGd d d eZd d d dddddZe dZe dZe dZe dZe dZdaadaae dZ!e dZ"d2ddZ#ddZ$ddZ%d d!Z&d"d#Z'd$d%Z(d&d'Z)d(d)Z*d*d+Z+d,d-Z,d.d/Z-d2d0d1Z.dS)3z-Provide time related exceptions and functions)division)old_div)mapN)config)util)c@s eZdZdS) TimeExceptionN)__name__ __module__ __qualname__r r 4/usr/lib/python3/dist-packages/duplicity/dup_time.pyr+sr<iQi: i'i3)smhDWMYz^[0-9]+$z^([0-9]+)([smhDWMY])zD^(?P[0-9]{4})[-/](?P[0-9]{1,2})[-/](?P[0-9]{1,2})$zD^(?P[0-9]{1,2})[-/](?P[0-9]{1,2})[-/](?P[0-9]{4})$z9^(?P[0-9]{4})(?P[0-9]{2})(?P[0-9]{2})Z$zBad interval string "%s" Intervals are specified like 2Y (2 years) or 2h30m (2.5 hours). The allowed special characters are s, m, h, D, W, M, and Y. See the man page for more information.afBad time string "%s" The acceptible time strings are intervals (like "3D64s"), w3-datetime strings, like "2002-04-26T04:22:01-07:00" (strings like "2002-04-26T04:22:01" are also acceptable - duplicity will use the current time zone), or ordinary dates like 2/4/1997 or 2001-04-23 (various combinations are acceptable, but the month always precedes the day).cCs2|ptt}t|tvsJ|t|aadS)z/Sets the current time in curtime and curtimestrN)inttimetype integer_types timetostringcurtime curtimestr) time_in_secstr r r setcurtimeOsr!cCs&t|tvs Jt|t|aadS)z2Sets the previous time in prevtime and prevtimestrN)rrprevtimer prevtimestr)rr r r setprevtimeWsr$cCsRtjrt|}tdtjdtjd|t|dSt|}td|S)zBReturn w3 or duplicity datetime compliant listing of timeinsecondsz %Y-%m-%dT%Hz%Mz%Sz%Y%m%dT%H%M%SZ)r old_filenamesr localtimestrftimetime_separatorgettzdgmtime) timeinsecondslcltimer r r r^s     rc Csz|ddd\}}t|dkrEttt|dd|dd|ddg\}}}ttt|dd |d d|ddg\}}}nttt|d \}}}ttt|tj\}}}d |krmd ksrJ|J|d |kr}dksJJd |krdksJJd|krdksJJd|krdksJJd|krdksJJ||||||dddf } t|dkrt| } n t | } | t j } t|dkrt| WSt| t |ddWSt ttfyYdSw)zReturn time in seconds from w3 or duplicity timestring If there is an error parsing the string, or it doesn't look like a valid datetime string, return None. NTr-ili4r ;=r%)splitlenlistrrrr)calendartimegmrmktimetimezone tzdtoseconds TypeError ValueErrorAssertionError) timestringdatedaytimeyearmonthdayhourminutesecond timetuple utc_in_secs local_in_secsr r r stringtotimeos<      $      rRcCstt|S)zReturn pretty version of time)rasctimer')r,r r r timetoprettysrTcCs tt|S)z2Return pretty version of time given w3 time string)rTrR)rFr r r stringtoprettys rUcCsg}t|d\}}|dkr|d|n |dkr|dt|d\}}|dkr1|d|n |dkr:|d|dkrD|dn|rJ|dkr^t|trW|d |n|d |d |S) z9Convert num of seconds to readable string like "2 hours".rrz%d hoursz1 hourrz %d minutesz1 minutez1 secondz %s secondsz %.2f seconds )divmodappend isinstancerjoin)secondspartlisthoursminutesr r r inttoprettys$      r_csfdd}tdkr|d}rHt}|s|t|d|d}}|tvs2|dkr5|||t|7}|dds|S)z@Convert a string expressing an interval (e.g. "4D2s") to secondsctttN)rbad_interval_stringrescaper interval_stringr r errorz!intstringtoseconds..errorr4rrN)r<_interval_regexpmatchrgroup_interval_conv_dictend)rerftotalrinumextr rdr intstringtosecondss    rpcCs|dkr tdtjd}ntdtjd}|dkrd}n |dkr#d}ndStttt|d\}}d|kr.errorrz%s-%02d-%02dT00:00:00%srIrJrK) r_integer_regexpsearchrrRr*rpr_genstr_date_regexp1_genstr_date_regexp2_genstr_date_regexp3rj)roverride_curtimerfr rir rr genstrtotimes>         rra)/__doc__ __future__r past.utilsrbuiltinsrrtypesrer>sys duplicityrr version_inforLongTyper Exceptionrrkcompilerrhrrrrrr"r#_rbrr!r$rrRrTrUr_rpr*rBr~rr r r r sN             8