bISc@sUdZddlZddlZddlZddlmZmZmZddlm Z m Z ddlm Z ddl m Z ejd4kZi d5d 6d6d6d7d6d8d6d9d6d:d 6d;d$6d<d(6d=d,6ZejejejejejejejejfZd-e fd.YZd/e fd0YZd1e fd2YZd3ZdS(>s*Checker for string formatting operations. iN(t ITokenCheckertIAstroidCheckert IRawChecker(t BaseCheckertBaseTokenChecker(tutils(tcheck_messagesiis3Unsupported format character %r (%#02x) at index %dsbad-format-charactersQUsed when a unsupported format character is used in a format string.tE1300s4Format string ends in middle of conversion specifierstruncated-format-strings\Used when a format string terminates before the end of a conversion specifier.tE1301s?Mixing named and unnamed conversion specifiers in format stringsmixed-format-stringsUsed when a format string contains both named (e.g. '%(foo)d') and unnamed (e.g. '%d') conversion specifiers. This is also used when a named conversion specifier contains * for the minimum field width and/or precision.tE1302s*Expected mapping for format string, not %ssformat-needs-mappings}Used when a format string that uses named conversion specifiers is used with an argument that is not a mapping.tE1303s7Format string dictionary key should be a string, not %ssbad-format-string-keysUsed when a format string that uses named conversion specifiers is used with a dictionary whose keys are not all strings.tW1300s)Unused key %r in format string dictionarysunused-format-string-keysUsed when a format string that uses named conversion specifiers is used with a dictionary that conWtains keys not required by the format string.tW1301s*Missing key %r in format string dictionarysmissing-format-string-keysUsed when a format string that uses named conversion specifiers is used with a dictionary that doesn't contain all the keys required by the format string.tE1304s$Too many arguments for format stringstoo-many-format-argsslUsed when a format string that uses unnamed conversion specifiers is given too many arguments.tE1305s&Not enough arguments for format stringstoo-few-format-argssjUsed when a format string that uses unnamed conversion specifiers is given too few argumentstE1306tStringFormatCheckercBs>eZdZefZdZeZeej dZ RS(sChecks string formatting operations to ensure that the format string is valid and the arguments match the format string. tstringc Cs|jdkrdS|j}|j}t|tjoFt|jtsMdS|j}ytj |\}}Wnvtj k r}||j }|j dd|d|t ||j fdStjk r|j dd|dSX|r |r |j dd|n|rlt|tjr%t} t} xs|jD]h\} } t| tjr| j} t| tr| j| q|j dd|d| q;t} q;W| sx9|D].} | | kr|j dd|d| qqWnx}| D].} | |kr|j d d|d| qqWqt|ttjfrt|j}|j d d|d|qnt|tjrt|j}n.t|ttjtjfrd }nd}|dk r||kr|j d d|q||kr|j d d|qndS(Nt%sbad-format-charactertnodetargsstruncated-format-stringsmixed-format-stringsbad-format-string-keysmissing-format-string-keysunused-format-string-keysformat-needs-mappingistoo-many-format-argsstoo-few-format-args(toptlefttrightt isinstancetastroidtConsttvaluet basestringRtparse_format_stringtUnsupportedFormatCharactertindext add_messagetordtIncompleteFormatStringtDicttsettFalsetitemstaddtTruet OTHER_NODEStTuplettypet__name__tlenteltstDictComptNone(tselfRRRt format_stringt required_keystrequired_num_argstetctkeyst unknown_keystkt_tkeyt type_nametnum_args((sQ/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/strings.pyt visit_binopYsd    +      #  #     ( R,t __module__t__doc__Rt__implements__tnametMSGStmsgsRR7R>(((sQ/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/strings.pyRPs  tStringMethodsCheckercBs?eZefZdZidd6ZeejdZ RS(Rs!Suspicious argument in %s.%s callsbad-str-strip-callsGThe argument to a str.{l,r,}strip call contains a duplicate character, tE1310c Cstj|j}t|tjrt|jtjr|jjd kr|jd kr|j rtj|j d}t|tj sdSt |j t t |j kr|jdd |d |jj|jfqndS( Ntstrtunicodetbyteststriptlstriptrstripisbad-str-strip-callRR(sstrsunicodesbytes(sstripslstripsrstrip(Rt safe_infertfuncRRt BoundMethodtboundtInstanceRBRRR-RR$R (R1RRNtarg((sQ/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/strings.pytvisit_callfuncs $(s!Suspicious argument in %s.%s callsbad-str-strip-callsGThe argument to a str.{l,r,}strip call contains a duplicate character, ( R,R?RRARBRDRRCR7RS(((sQ/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/strings.pyREs  tStringConstantCheckercBsdeZdZeefZdZidd6dd 6Zd Zd Z d Z d Z dZ dZ RS(sCheck string literalststring_constantsRAnomalous backslash in string: '%s'. String constant might be missing an r prefix.sanomalous-backslash-in-stringsBUsed when a backslash is in a literal string but not as an escape.tW1401saAnomalous Unicode escape in byte string: '%s'. String constant might be missing an r or u prefix.s"anomalous-unicode-escape-in-stringsSUsed when an escape like \u is encountered in a byte string where it has no effect.tW1402sabfnrtvx \'"01234567tuUNcCsd|jk|_dS(Ntunicode_literals(tfuture_importst_unicode_literals(R1tmodule((sQ/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/strings.pytprocess_modulescCsOxH|D]@\}}\}}}}|tjkr|j|||qqWdS(N(ttokenizetSTRINGtprocess_string_token(R1ttokensttok_typettokent start_rowt start_colR:((sQ/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/strings.pytprocess_tokenss"c Csx0t|D]"\}}|dkr |}Pq q W|| j}||}|d |dkopd|knr|dd!} n |dd!} d|kr|j|| ||ndS(Ns'"iiiitr(t enumeratetlowertprocess_non_raw_string_token( R1RcRdRetiR6t quote_chartprefixt after_prefixt string_body((sQ/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/strings.pyR`s  (   cCsd}xtr|jd|}|dkr1Pn||d}|||d!}||jkrd|krnqts}|jrd|krq|jdd |d |fn.||jkr|jd d |d |fn|d7}q Wd S( sCcheck for bad escapes in a non-raw string. prefix: lowercase string of eg 'ur' string prefix markers. string_body: the un-parsed body of the string, not including the quote marks. start_row: integer line number in the source. start_col: integer column number in the source. is\iiitutbs"anomalous-unicode-escape-in-stringtlineRsanomalous-backslash-in-stringN(R(tfindtUNICODE_ESCAPE_CHARACTERSt_PY3KR[R tESCAPE_CHARACTERS(R1RmRoRdReRkt next_chartmatch((sQ/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/strings.pyRjs$     (sRAnomalous backslash in string: '%s'. String constant might be missing an r prefix.sanomalous-backslash-in-stringsBUsed when a backslash is in a literal string but not as an escape.(saAnomalous Unicode escape in byte string: '%s'. String constant might be missing an r or u prefix.s"anomalous-unicode-escape-in-stringsSUsed when an escape like \u is encountered in a byte string where it has no effect.(R,R?R@RRRARBRDRvRtR]RfR`Rj(((sQ/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/strings.pyRTs      cCs=|jt||jt||jt|dS(s.required method to auto register this checker N(tregister_checkerRRERT(tlinter((sQ/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/strings.pytregister,s(ii(s3Unsupported format character %r (%#02x) at index %dsbad-format-charactersQUsed when a unsupported format character is used in a format string.(s4Format string ends in middle of conversion specifierstruncated-format-strings\Used when a format string terminates before the end of a conversion specifier.(s?Mixing named and unnamed conversion specifiers in format stringsmixed-format-stringsUsed when a format string contains both named (e.g. '%(foo)d') and unnamed (e.g. '%d') conversion specifiers. This is also used when a named conversion specifier contains * for the minimum field width and/or precision.(s*Expected mapping for format string, not %ssformat-needs-mappings}Used when a format string that uses named conversion specifiers is used with an argument that is not a mapping.(s7Format string dictionary key should be a string, not %ssbad-format-string-keysUsed when a format string that uses named conversion specifiers is used with a dictionary whose keys are not all strings.(s)Unused key %r in format string dictionarysunused-format-string-keysUsed when a format string that uses named conversion specifiers is used with a dictionary that conWtains keys not required by the format string.(s*Missing key %r in format string dictionarysmissing-format-string-keysUsed when a format string that uses named conversion specifiers is used with a dictionary that doesn't contain all the keys required by the format string.(s$Too many arguments for format stringstoo-many-format-argsslUsed when a format string that uses unnamed conversion specifiers is given too many arguments.(s&Not enough arguments for format stringstoo-few-format-argssjUsed when a format string that uses unnamed conversion specifiers is given too few arguments(R@tsysR^Rtpylint.interfacesRRRtpylint.checkersRRRtpylint.checkers.utilsRt version_infoRuRCRtListt BackquotetLambdatFunctiontListComptSetComptGenExprR)RRERTR{(((sQ/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/strings.pytsV     Zh