;ò > ÄDc@sÓdkZdkZdkZdkZdkiZdkiZdki Z dk Tdk i Z dk iZdkiZdkiZdefd„ƒYZe idhde<ƒZdeifd„ƒYZeZdS(N(s*sSqliteLookupDBcBsktZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z e i d d ƒZ d „Z RS( NcCs‘y dk}Wntj otid‚nX||_y|i|iƒ|_Wn9|ij o*}t i |ƒ}|i|_|‚nXdS(Ns^You need to have PySQLite installed to use this plugin. Download it at ( ssqlites ImportErrors callbackssErrorsfilenamesselfsconnectsdbs DatabaseErrorsesdbisInvalidDBError(sselfsfilenamessqlitese((s./Lookup/plugin.pys__init__.s   cCs|iiƒdS(N(sselfsdbsclose(sself((s./Lookup/plugin.pysclose=scCsX|iiƒ}|id|ƒt|iƒdƒ}|djo ti ‚n|SdS(NsSELECT COUNT(*) FROM %si( sselfsdbscursorsexecutes tableNamesintsfetchonesrowssdbis NoRecordError(sselfs tableNamesrowsscursor((s./Lookup/plugin.pysgetRecordCount@s   cCsF|iiƒ}d|}|i|ƒ|idjotSntSdS(Ns_SELECT name FROM sqlite_master WHERE type='table' AND name='%s'i( sselfsdbscursorsnamessqlsexecutesrowcountsFalsesTrue(sselfsnamescursorssql((s./Lookup/plugin.pys checkLookupHs   c Cs|iiƒ}|id|ƒd|}x²tii|ƒD]ž} | i dƒ} y.|i | dƒ\}}|iddƒ}WnEtj o9|id|ƒtd|i| ƒ}ti|‚nX|i|||ƒq=W|id ||fƒ|iiƒdS( Ns&CREATE TABLE %s (key TEXT, value TEXT)s INSERT INTO %s VALUES (%%s, %%s)s is\:s:s DROP TABLE %ssInvalid line in %s: %qs CREATE INDEX %s_keys ON %s (key)(sselfsdbscursorsexecutesnamessqlsutilssfilesnonCommentNonEmptyLinessfdslinesrstripssplitRessplitskeysvaluesreplaces ValueErrorsformatsss callbackssErrorscommit( sselfsnamesfdssplitResvaluescursorssskeyssqlsline((s./Lookup/plugin.pys addLookupSs  cCsN|iiƒ}|i|ƒo"|id|ƒ|iiƒn ti‚dS(Ns DROP TABLE %s( sselfsdbscursors checkLookupsnamesexecutescommitsdbis NoRecordError(sselfsnamescursor((s./Lookup/plugin.pys dropLookupds cCsT|iiƒ}d|}|i||ƒ|idjo ti ‚n |i ƒSdS(Ns'SELECT value FROM %s WHERE key LIKE %%si( sselfsdbscursorsnamessqlsexecuteskeysrowcountsdbis NoRecordErrorsfetchall(sselfsnameskeyscursorssql((s./Lookup/plugin.pys getResultsls   cCsQ|iiƒ}d|}|i|ƒ|idjo ti‚n |i ƒSdS(NsDSELECT key, value FROM %s ORDER BY random() LIMIT 1i( sselfsdbscursorsnamessqlsexecutesrowcountsdbis NoRecordErrorsfetchone(sselfsnameskeyscursorssql((s./Lookup/plugin.pysgetRandomResultus    s*?s%_cCs0|iiƒ}g} g}d} xh|D]`\} }| djoG| i d| |fƒ|d„} |ii | d| ƒ| d7} q(q(Wx8|D]0}| i d|ƒ|i |i|iƒƒq“W| o ti‚nd|di| ƒf} |i| |ƒ|id jo ti‚n |iƒSdS( Nspsregexps%s(%s)cCstt|i|ƒƒƒSdS(N(sintsboolsrssearchss(sssr((s./Lookup/plugin.pyspˆsis %s LIKE %%ss"SELECT key, value FROM %s WHERE %ss AND i(sselfsdbscursorscriteriasformatss predicateNamesoptionssoptionsargsappendscolumnspscreate_functionsglobssglobs translates _sqlTranss callbackss ArgumentErrorsnamesjoinssqlsexecutesrowcountsdbis NoRecordErrorsfetchall(sselfsnamesoptionssglobsscolumnsargsglobsformatsscursorsps predicateNamessqlscriteriasoption((s./Lookup/plugin.pys searchResults€s,     (s__name__s __module__s__init__sclosesgetRecordCounts checkLookups addLookups dropLookups getResultssgetRandomResultsstrings maketranss _sqlTranss searchResults(((s./Lookup/plugin.pysSqliteLookupDB-s      sLookupssqlitecBs4tZd„Zd„Zd„Zd„Zd„Zd„Zd„Ze edd fd gƒZe i d ƒZ d „Z e e dd fehd d<ƒd dgƒZ ed„Zd„Zd„Zd„Zd„Ze eehdd<dd<ƒdedƒgƒZd„Ze ededƒgƒZRS(NcCs§tt|ƒ|_|ii|ƒtiƒ|_yt ƒ|_ Wn:t i j o+}|iid|it|ƒƒ‚nXxqtiiƒD]`\}}|iƒ}|idƒo8|tdƒ}d|joqŽn|i||ƒqŽqŽWtiiii}xœ|i dt!ƒD]ˆ\}}|iƒ}|ƒ}y9|i i"|ƒ o|i#||ƒn|i$|ƒWqt%j o}|ii&d||ƒqXqWdS(NsError loading %s: %sssupybot.plugins.lookup.lookups.s.s fullNamessCouldn't add lookup %s: %s('ssupersLookupsselfs_Lookup__parents__init__sircs callbackssCanonicalNameDicts lookupDomainssLookupDBsdbsdbisInvalidDBErrorseslogs exceptionsfilenamesstrsregistrys_caches iteritemssnamesvalueslowers startswithslensaddRegistryValuesconfssupybotspluginsslookupssgroups getValuessFalses checkLookups addDatabases addCommands Exceptionswarning(sselfsircsesnamesvaluesfilenamesgroup((s./Lookup/plugin.pys__init__Ÿs6      cCs<|ii|ƒ o ||ijotSq8tSntSdS(N(sselfs_Lookup__parentsisCommandMethodsnames lookupDomainssTruesFalse(sselfsname((s./Lookup/plugin.pysisCommandMethodºs cCs7|iiƒ}|i|iiƒƒ|iƒ|SdS(N(sselfs_Lookup__parents listCommandsscommandssextends lookupDomainsskeysssort(sselfscommands((s./Lookup/plugin.pys listCommandsÃs cCs=y|ii|ƒSWn"tj o|i|dSnXdS(Ni(sselfs_Lookup__parentsgetCommandMethodscommandsAttributeErrors lookupDomains(sselfscommand((s./Lookup/plugin.pysgetCommandMethodÉscCstii|dƒSdS(Ni2(sutilssstrs ellipsisifyss(sselfss((s./Lookup/plugin.pys_shrinkÏscCs|iiƒdS(N(sselfsdbsclose(sself((s./Lookup/plugin.pysdieÒscCs„||ijo|idƒdSny5|ii|ƒ|i|=|i|ƒ|iƒWn#t i j o|idƒnXdS(s7 Removes the lookup for . s$That's not a valid lookup to remove.NsNo such lookup exists.( snamesselfs lookupDomainssircserrorsdbs dropLookupsdelRegistryValuess replySuccesssdbis NoRecordError(sselfsircsmsgsargssname((s./Lookup/plugin.pysremoveÕs   scheckCapabilitysadmins commandNames(? Adds a lookup for with the key/value pairs specified in the colon-delimited file specified by . is searched for in conf.supybot.directories.data. If is not singular, we try to make it singular before creating the command. If the --nokey option is specified, the new lookup will display only the value when queried, and will omit the key from the response. snokeys0I already have a command in this plugin named %sNsCould not open %s: %sisLookup %s added.(sFalsesnokeysoptlistsoptionsargumentsTruesutilssstrs depluralizesnamesselfsisCommandMethodsssircserrorsdbs checkLookups addDatabasesfilenamesEnvironmentErrorsesargss addCommandsaddRegistryValues replySuccess( sselfsircsmsgsargssoptlistsnamesfilenamesnokeysargumentsssesoption((s./Lookup/plugin.pysaddçs(       snokeyssfilenamecCs]tiiii}ti||ti |dƒƒti|i |ƒdti |dƒƒdS(Nssnokey(sconfssupybotspluginssLookupslookupssgroupsregisterGlobalValuesnamesregistrysStringsfilenamesgetsBooleansnokey(sselfsnamesfilenamesnokeysgroup((s./Lookup/plugin.pysaddRegistryValuescCs#tiiii}|i|ƒdS(N(sconfssupybotspluginssLookupslookupssgroups unregistersname(sselfsnamesgroup((s./Lookup/plugin.pysdelRegistryValues scCsKtiiii|ƒ}t|ƒ}|i i |||i ƒ|i ƒdS(N(sconfssupybots directoriessdatasdirizesfilenamesfilesfdsselfsdbs addLookupsnames_splitResclose(sselfsnamesfilenamesfd((s./Lookup/plugin.pys addDatabases cs{‡d†}|iiˆƒ}dˆtii|ˆƒf}ti i |ˆ|ƒ}t i ||tƒ}||iˆ] If is given, looks up in the %s database. Otherwise, returns a random key: value pair from the database. There are %s in the database. (sfsselfsdbsgetRecordCountsnamesrowssutilssstrsnItemss docstringspythonschangeFunctionNamesnewsinstancemethodsLookups lookupDomains(sselfsnamesrowssfs docstring((snames./Lookup/plugin.pys addCommands  cCsd} x+|D]#\} } | djo d} q q W|ii|ƒo¥yw|ii|||| ƒ} gi }| D]+} |d| d|i| dƒfƒqs~}|itd|ƒƒWqýtij o|id|ƒqýXn|id |ƒd S( s6[--{regexp} ] [--values] [ ...] Searches the domain for lookups matching . If --regexp is given, its associated value is taken as a regexp and matched against the lookups. If --values is given, search the values rather than the keys. skeysvaluessvalues%s: %siis%Ls$No entries in %s matched that query.sI don't have a domain %sN(scolumnsoptlistsoptionsargsselfsdbs checkLookupsnames searchResultssglobssresultssappends_[1]sitems_shrinkslookupssircsreplysformatsdbis NoRecordErrorserror(sselfsircsmsgsargssoptlistsnamesglobss_[1]slookupsscolumnsresultssitemsargsoption((s./Lookup/plugin.pyssearch&s  Bsvaluessregexps regexpMatchers somethingsglobc Csc|ii|ƒo;g}|oÈy|ii||ƒ}Wn1tij o"|i d||fƒdSnXt |ƒdjo|i |ddƒqJgi }|D]} || dƒq§~} |i d|di| ƒfƒq_|ii||ƒ\}}d|} |i| ƒ o|i d||fƒq_|i d |ƒn|i d |ƒdS( sP Looks up the value of in the domain . sI couldn't find %s in %s.Niis%s could be %ss, or slookups.%s.nokeys%s: %ss%ssI don't have a domain %s(sselfsdbs checkLookupsnamesresultsskeys getResultssdbis NoRecordErrorsircserrorslensreplysappends_[1]stsvaluessjoinsgetRandomResultsvalues nokeyRegKeys registryValue( sselfsircsmsgsargssnameskeysvaluesresultss_[1]svaluessts nokeyRegKey((s./Lookup/plugin.pys_lookup?s& +$ stext(s__name__s __module__s__init__sisCommandMethods listCommandssgetCommandMethods_shrinksdiesremoveswrapsrescompiles_splitResaddsgetoptssFalsesaddRegistryValuesdelRegistryValuess addDatabases addCommandssearchsanys_lookups additional(((s./Lookup/plugin.pysLookupžs&       0     6 (sresnewsgetoptsstrings supybot.dbisdbis supybot.confsconfs supybot.utilssutilsssupybot.commandsssupybot.pluginsspluginsssupybot.ircutilssircutilsssupybot.registrysregistryssupybot.callbackss callbackssobjectsSqliteLookupDBsDBsLookupDBsPluginsLookupsClass(sdbisstrings callbackssutilsspluginssSqliteLookupDBsresLookupsregistrysconfsnewsgetoptsLookupDBsClasssircutils((s./Lookup/plugin.pys?s           o¿