diff options
author | Al Korgun <alkorgun@gmail.com> | 2013-06-25 14:29:17 +0400 |
---|---|---|
committer | Al Korgun <alkorgun@gmail.com> | 2013-06-25 14:29:17 +0400 |
commit | 74a57a3a0419e6c2313f715cedcc5cd4b28e542b (patch) | |
tree | 7329ee48c8e99e49957784189004d98a42431107 | |
parent | baf24e8415e99a974e230ae2cb2c8f232b949189 (diff) |
implemented partially support of the work without sqlite; "imdb" fixed; many important and little changes
-rw-r--r-- | BlackSmith.py | 80 | ||||
-rw-r--r-- | LICENSE | 402 | ||||
-rw-r--r-- | NOTICE | 10 | ||||
-rw-r--r-- | README | 8 | ||||
-rw-r--r-- | expansions/alive_keeper/code.py | 15 | ||||
-rw-r--r-- | expansions/allweb/code.py | 149 | ||||
-rw-r--r-- | expansions/basic_control/code.py | 18 | ||||
-rw-r--r-- | expansions/basic_control/insc.py | 2 | ||||
-rw-r--r-- | expansions/books/code.py | 57 | ||||
-rw-r--r-- | expansions/config/code.py | 62 | ||||
-rw-r--r-- | expansions/config/insc.py | 2 | ||||
-rw-r--r-- | expansions/cron/code.py | 2 | ||||
-rw-r--r-- | expansions/info/code.py | 4 | ||||
-rw-r--r-- | expansions/note/code.py | 7 | ||||
-rw-r--r-- | expansions/talkers/code.py | 75 | ||||
-rw-r--r-- | expansions/user_stats/code.py | 95 | ||||
-rw-r--r-- | expansions/wtf/code.py | 7 | ||||
-rw-r--r-- | expansions/wtf/insc.py | 2 | ||||
-rw-r--r-- | librarys.zip | bin | 99016 -> 99338 bytes |
19 files changed, 507 insertions, 490 deletions
diff --git a/BlackSmith.py b/BlackSmith.py index bf079ea..ee1eaba 100644 --- a/BlackSmith.py +++ b/BlackSmith.py @@ -169,6 +169,10 @@ Info = { class SelfExc(Exception): pass +def check_sqlite(): + + assert itypes.sqlite3, "py-sqlite3 required" + def exc_info(): exc, err, tb = sys.exc_info() if exc and err: @@ -192,9 +196,9 @@ def get_exc(): exc_str = lambda err, data = "%s - %s": data % (err.__class__.__name__, err[0] if err.args else None) -def exec_(instance, list = ()): +def apply(instance, args = ()): try: - code = instance(*list) + code = instance(*args) except: code = None return code @@ -267,8 +271,9 @@ GenInscFile = static % ("insc.py") GenConFile = static % ("config.ini") ConDispFile = static % ("clients.ini") ChatsFile = dynamic % ("chats.db") +ChatsFileBackup = dynamic % ("chats.cp") -(BsMark, BsVer, BsRev) = (2, 45, 0) +(BsMark, BsVer, BsRev) = (2, 46, 0) if os.access(SvnCache, os.R_OK): Cache = open(SvnCache).readlines() @@ -304,7 +309,7 @@ try: GenCon = ConfigParser.ConfigParser() GenCon.read(GenConFile) GenDisp, Instance = client_config(GenCon, "CLIENT") - InstansesDesc = {GenDisp: Instance} + InstancesDesc = {GenDisp: Instance} ConTls = eval(GenCon.get("STATES", "TLS")) Mserve = eval(GenCon.get("STATES", "MSERVE")) GetExc = eval(GenCon.get("STATES", "GETEXC")) @@ -322,7 +327,7 @@ try: ConDisp.read(ConDispFile) for Block in ConDisp.sections(): Disp, Instance = client_config(ConDisp, Block) - InstansesDesc[Disp] = Instance + InstancesDesc[Disp] = Instance except: Exit("\n\nOne of the configuration files is corrupted!", 1, 30) @@ -394,7 +399,7 @@ def composeThr(handler, Name, list = (), command = None): return iThr.KThread(execute_handler, Name, (handler, list, command,)) def StartThr(Thr, Number = 0): - if Number > 3: + if Number > 2: raise RuntimeError("exit") try: Thr.start() @@ -662,10 +667,14 @@ class sConf(object): get_nicks = lambda self: self.desc.keys() - sorted_users = lambda self: [self.get_user(nick) for nick in sorted(self.get_nicks())] - get_users = lambda self: self.desc.values() + def sorted_users(self): + for user in sorted(self.get_nicks()): + user = self.get_user(user) + if user: + yield user + def sjoined(self, nick, role, source, stanza): access = Galist.get(source, None) if not access and access != 0: @@ -750,7 +759,9 @@ class sConf(object): del desc[self.name] else: desc[self.name] = {"disp": self.disp, Types[12]: self.nick, "cPref": self.cPref, "code": self.code} - cat_file(ChatsFile, str(desc)) + desc = str(desc) + cat_file(ChatsFileBackup, desc) + cat_file(ChatsFile, desc) else: delivery(self.name) @@ -998,7 +1009,7 @@ def initialize_file(filename, data = "{}"): return True def del_file(filename): - exec_(os.remove, (cefile(filename),)) + apply(os.remove, (cefile(filename),)) def get_file(filename): with open(cefile(filename), "r") as fp: @@ -1083,7 +1094,7 @@ def get_pipe(command): data = "(...)" return data -class Web: +class Web(object): import urllib as One, urllib2 as Two @@ -1121,8 +1132,8 @@ class Web: else: raise SelfExc("no info about file's size") if not filename: - if info.has_key("Content-Disposition"): - disp = info.get("Content-Disposition") + disp = info.get("Content-Disposition") + if disp: comp = compile__("filename=[\"']+?(.+?)[\"']+?") disp = comp.search(disp) if disp: @@ -1163,7 +1174,7 @@ def get_text(body, s0, s2, s1 = "(?:.|\s)+"): body = (body.group(1)).strip() return body -def sub_desc(body, ls, sub = None): +def sub_desc(body, ls, sub = str()): if isinstance(ls, dict): for x, z in ls.items(): body = body.replace(x, z) @@ -1171,11 +1182,11 @@ def sub_desc(body, ls, sub = None): for x in ls: if isinstance(x, (list, tuple)): if len(x) >= 2: - body = body.replace(x[0], x[1]) + body = body.replace(*x[:2]) else: - body = body.replace(x[0], (sub if sub else "")) + body = body.replace(x[0], sub) else: - body = body.replace(x, (sub if sub else "")) + body = body.replace(x, sub) return body strfTime = lambda data = "%d.%m.%Y (%H:%M:%S)", local = True: time.strftime(data, time.localtime() if local else time.gmtime()) @@ -1208,7 +1219,7 @@ def Size2Text(Size): enumerated_list = lambda ls: str.join(chr(10), ["%d) %s" % (numb, line) for numb, line in enumerate(ls, 1)]) -isNumber = lambda obj: (not exec_(int, (obj,)) is None) +isNumber = lambda obj: (not apply(int, (obj,)) is None) isSource = lambda jid: isJID.match(jid) @@ -1223,16 +1234,17 @@ def calculate(Numb = int()): lines = get_pipe(sys_cmds[0] % (BsPid)).splitlines() if len(lines) >= 2: Numb = lines[1].strip() - return (int() if not isNumber(Numb) else int(Numb)) + return (0 if not isNumber(Numb) else int(Numb)) def check_copies(): Cache = Base = {"PID": BsPid, "up": Info["sess"], "alls": []} if os.path.isfile(PidFile): try: Cache = eval(get_file(PidFile)) - except: + except SyntaxError: del_file(PidFile) - Cache = Base + except: + pass else: try: if BsPid == Cache["PID"]: @@ -1243,21 +1255,21 @@ def check_copies(): os.kill(Cache["PID"], 9); raise SelfExc() except: Cache = Base - exec_(cat_file, (PidFile, str(Cache))) + apply(cat_file, (PidFile, str(Cache))) del Cache["PID"]; Info.update(Cache) def join_chats(): if initialize_file(ChatsFile): try: - Confs = eval(get_file(ChatsFile)) + try: + Confs = eval(get_file(ChatsFile)) + except SyntaxError: + Confs = eval(get_file(ChatsFileBackup)) except KeyboardInterrupt: raise KeyboardInterrupt("Interrupt (Ctrl+C)") - except SyntaxError: - del_file(ChatsFile); initialize_file(ChatsFile) - Confs = {} except: Confs = {} - Print("\n\nThere are %d rooms in list..." % len(Confs.keys()), color4) + Print("\n\nThere are %d rooms in the list..." % len(Confs.keys()), color4) for conf, desc in Confs.iteritems(): Chats[conf] = Chat = sConf(conf, added = True, **desc) Chat.load_all() @@ -1301,7 +1313,7 @@ def XmppPresenceCB(disp, stanza): elif ecode in (eCodes[5], eCodes[12]): Chat.IamHere = False TimerName = ejoinTimerName(conf) - if TimerName not in iThr.ThrNames(): + if TimerName not in iThr.getNames(): try: composeTimer(360, ejoinTimer, TimerName, (conf,)).start() except iThr.error: @@ -1582,7 +1594,7 @@ def connectAndDispatch(disp): delivery(AnsBase[28] % (disp)) def connect_clients(): - for Inctance, Attrs in InstansesDesc.items(): + for Inctance, Attrs in InstancesDesc.items(): conn = connect_client(Inctance, Attrs) if not conn[0]: if conn[1] and conn[1] == eCodes[2]: @@ -1592,7 +1604,7 @@ def connect_clients(): def ReverseDisp(disp, rejoin = True): Iters = itypes.Number() while 1440 > Iters.plus(): - if connect_client(disp, InstansesDesc[disp])[0]: + if connect_client(disp, InstancesDesc[disp])[0]: if rejoin: for conf in Chats.itervalues(): if disp == conf.disp: @@ -1653,15 +1665,15 @@ def load_mark2(): call_sfunctions("02si") for disp in Clients.keys(): ThrName = "%s-%s" % (Types[13], disp) - if ThrName not in iThr.ThrNames(): + if ThrName not in iThr.getNames(): composeThr(Dispatcher, ThrName, (disp,)).start() while VarCache["alive"]: sleep(180) Cls = itypes.Number() - for Name in iThr.ThrNames(): + for Name in iThr.getNames(): if Name.startswith(Types[13]): Cls.plus() - if Cls._int() == 0: + if not int(Cls): sys_exit("All of the clients now fallen!") sys.exc_clear() gc.collect() @@ -1671,7 +1683,7 @@ def load_mark2(): def sys_exit(exit_desclr = "Suicide!"): VarCache["alive"] = False Print("\n\n%s" % (exit_desclr), color2) - iThr.Threads_kill() + iThr.killAllThreads() for disp in Clients.keys(): if online(disp): sUnavailable(disp, exit_desclr) @@ -1,202 +1,202 @@ - Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright (2010-2012) Al Korgun [alkorgun@gmail.com]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright (2010-2013) Al Korgun [alkorgun@gmail.com]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
@@ -1,8 +1,8 @@ - BlackSmith mark.2 xmpp bot
- Copyright (2010-2012) Al Korgun [alkorgun@gmail.com]
+ BlackSmith mark.2 xmpp bot
+ Copyright (2010-2013) Al Korgun [alkorgun@gmail.com]
- Finnish localization
- Copyright (2012) novtux [novtux@gmail.com]
+ Finnish localization
+ Copyright (2012) novtux [novtux@gmail.com]
- This product based on Python Programming Language ( http://python.org/ ).
+ This product based on Python Programming Language ( http://python.org/ ).
@@ -4,7 +4,7 @@ This is BlackSmith mark.2 xmpp bot (the second generation of BlackSmith) To use Black-2 you will need:
1. OS: *nix or Microsoft Windows (FreeBSD amd64 recommended)
-2. Python 2.7.0 or higher (Python 3+ isn't required)
+2. Python 2.7 or higher (Python 3+ isn't required)
3. Python's sqlite lib. (Py-Sqlite3)
4. Subversion (or TortoiseSVN for Windows)
@@ -17,12 +17,12 @@ svn checkout http://blacksmith-2.googlecode.com/svn/trunk/ Black-2 3) The same actions with ./static/clients_.ini (optional)
-That is all! You can run -> BlackSmith.py
+That is all! You can run >> BlackSmith.py
Official GoogleCode page: http://code.google.com/p/blacksmith-2/
Official Jabber Conference: Witcher@conference.jabber.ru
Feedback:
- alkorgun@gmail.com - Developer
- novtux@gmail.com - Finnish localizer
+# alkorgun@gmail.com - Developer
+# novtux@gmail.com - Finnish localizer
diff --git a/expansions/alive_keeper/code.py b/expansions/alive_keeper/code.py index 7e6472a..af8c6ea 100644 --- a/expansions/alive_keeper/code.py +++ b/expansions/alive_keeper/code.py @@ -1,9 +1,9 @@ # coding: utf-8 # BlackSmith mark.2 -# exp_name = "alive_keeper" # /code.py v.x7 -# Id: 16~7c -# Code © (2011-2012) by WitcherGeralt [alkorgun@gmail.com] +# exp_name = "alive_keeper" # /code.py v.x8 +# Id: 16~8c +# Code © (2011-2013) by WitcherGeralt [alkorgun@gmail.com] class expansion_temp(expansion): @@ -18,7 +18,7 @@ class expansion_temp(expansion): while VarCache["alive"]: sleep(120) - ThrIds = iThr.ThrNames() + ThrIds = iThr.getNames() for disp_str, disp in Clients.iteritems(): if not hasattr(disp, "aKeeper"): disp.aKeeper = itypes.Number() @@ -27,7 +27,7 @@ class expansion_temp(expansion): ThrName = "%s-%s" % (Types[13], disp_str) if ThrName in ThrIds: for Thr in iThr.enumerate(): - if Thr._Thread__name == ThrName: + if ThrName == Thr.getName(): Thr.kill() try: composeThr(connectAndDispatch, ThrName, (disp_str,)).start() @@ -58,7 +58,7 @@ class expansion_temp(expansion): while VarCache["alive"]: sleep(360) - ThrIds = iThr.ThrNames() + ThrIds = iThr.getNames() for conf in Chats.itervalues(): if not (online(conf.disp) and conf.IamHere): continue @@ -89,8 +89,7 @@ class expansion_temp(expansion): Name1 = self.alive_keeper.func_name Name2 = self.conf_alive_keeper.func_name for Thr in iThr.enumerate(): - ThrName = Thr._Thread__name - if ThrName.startswith((Name1, Name2)): + if Thr.name.startswith((Name1, Name2)): Thr.kill() composeThr(self.alive_keeper, Name1).start() composeThr(self.conf_alive_keeper, Name2).start() diff --git a/expansions/allweb/code.py b/expansions/allweb/code.py index 0db0c16..b5f37be 100644 --- a/expansions/allweb/code.py +++ b/expansions/allweb/code.py @@ -1,8 +1,8 @@ # coding: utf-8 # BlackSmith mark.2 -# exp_name = "allweb" # /code.py v.x23 -# Id: 25~23c +# exp_name = "allweb" # /code.py v.x24 +# Id: 25~24c # Code © (2011-2013) by WitcherGeralt [alkorgun@gmail.com] class expansion_temp(expansion): @@ -272,7 +272,7 @@ class expansion_temp(expansion): c1st = (ls.pop(0)).lower() if c1st in ("top250", "топ250".decode("utf-8")): if ls: - limit = exec_(int, (ls.pop(0),)) + limit = apply(int, (ls.pop(0),)) if limit <= 5: limit = 5 else: @@ -294,11 +294,10 @@ class expansion_temp(expansion): '?<a href="/film/\d+?/votes/" class="continue">(.+?)</a> <span.*?>(.+?)</span>', 16) list = comp.findall(list) if list: - Number = itypes.Number() ls = ["\n[#] [Name, Year] [Rating] (Votes)"] - for Name, Numb, Numb_ in list: - ls.append("%d) %s - %s (%s)" % (Number.plus(), self.sub_ehtmls(Name), Numb, sub_desc(Numb, [" "]))) - if limit and limit <= Number._int(): + for Number, (Name, Numb, Count) in enumerate(list, 1): + ls.append("%d) %s - %s (%s)" % (Number, self.sub_ehtmls(Name), Numb, sub_desc(Count, [" "]))) + if limit and limit <= Number: break if not limit or limit > 25: if stype == Types[1]: @@ -312,7 +311,7 @@ class expansion_temp(expansion): else: answer = self.AnsBase[1] elif isNumber(body): - Opener = Web("http://m.kinopoisk.ru/movie/%s" % (body), headers = self.kinoHeaders.copy()) + Opener = Web("http://m.kinopoisk.ru/movie/%d" % int(body), headers = self.kinoHeaders.copy()) try: data = Opener.get_page(self.UserAgent_Moz) except Web.Two.HTTPError, exc: @@ -352,10 +351,9 @@ class expansion_temp(expansion): comp = compile__("<a href=\"http://m.kinopoisk.ru/movie/(\d+?)/\">(.+?)</a>") list = comp.findall(data) if list: - Number = itypes.Number() ls = ["\n[#] [Name, Year] (#id)"] - for Numb, Name in list: - ls.append("%d) %s (#%s)" % (Number.plus(), self.sub_ehtmls(Name), Numb)) + for Number, (Numb, Name) in enumerate(list, 1): + ls.append("%d) %s (#%s)" % (Number, self.sub_ehtmls(Name), Numb)) answer = str.join(chr(10), ls) elif data.count(self.C3oP): answer = self.AnsBase[-1] @@ -370,13 +368,25 @@ class expansion_temp(expansion): IMDbHeaders = {"Accept-Language": "%s,en" % UserAgents.get(DefLANG, "en-US")} + IMDbRequest = { # imdbapi.org + "type": "json", +# "id": "tt", # get info by ID +# "q": "any title", # for the search +# "limit": str(choice(range(1, 11))), # for the search + "plot": "none", # or "simple" or "full" + "episode": "0", # or "1" + "lang": UserAgents.get(DefLANG, "en-US"), + "aka": "simple", # or "full" + "release": "simple", # or "full" + } + def command_imdb(self, stype, source, body, disp): if body: ls = body.split() c1st = (ls.pop(0)).lower() if c1st in ("top250", "топ250".decode("utf-8")): if ls: - limit = exec_(int, (ls.pop(0),)) + limit = apply(int, (ls.pop(0),)) if limit <= 5: limit = 5 else: @@ -390,18 +400,17 @@ class expansion_temp(expansion): answer = self.AnsBase[0] else: data = data.decode("utf-8") - list = get_text(data, '<div id="main">', "</div>") - if list: + data = get_text(data, '<div id="main">', "</div>") + if data: comp = compile__('<td align="center">%s((?:\d\.\d)+|\d+?)</font></td><td>%s<a href="/title/tt\d+?/">' \ '(.+?)</a>(.+?)</font></td><td align="right">%s(.+?)</font>' \ '</td>' % (('<font face="Arial, Helvetica, sans-serif" size="-1">',)*3), 16) - list = comp.findall(list) - if list: - Number = itypes.Number() + data = comp.findall(data) + if data: ls = ["\n[#] [Name, Year] [Rating] (Votes)"] - for Numb, Name, Year, Numb_ in list: - ls.append("%s) %s %s - %s (%s)" % (Number.plus(), self.sub_ehtmls(Name), Year.strip(), Numb, Numb_)) - if limit and limit <= Number._int(): + for Number, (Numb, Name, Year, Count) in enumerate(data, 1): + ls.append("%s) %s %s - %s (%s)" % (Number, self.sub_ehtmls(Name), Year.strip(), Numb, Count)) + if limit and limit <= Number: break if not limit or limit > 25: if stype == Types[1]: @@ -413,7 +422,10 @@ class expansion_temp(expansion): else: answer = self.AnsBase[1] elif isNumber(body): - Opener = Web("http://www.imdb.com/title/tt%s/" % (body), headers = self.IMDbHeaders) + IMDbRequest = self.IMDbRequest.copy() + IMDbRequest["id"] = ("tt" + body) + IMDbRequest["plot"] = "full" + Opener = Web("http://imdbapi.org/?", IMDbRequest.iteritems()) try: data = Opener.get_page(self.UserAgent_Moz) except Web.Two.HTTPError, exc: @@ -421,42 +433,46 @@ class expansion_temp(expansion): except: answer = self.AnsBase[0] else: - data = data.decode("utf-8") - Name = get_text(data, '<h1 class="header" itemprop="name">', "<span.*?>") - if Name: + try: + data = self.json.loads(data) + except: + answer = self.AnsBase[1] + else: ls = ["\->"] - Year = get_text(data, '<a href="/year/\d+?/">', "</a>", "\d+") - if Year: - ls.append("%s (%s)" % (Name, Year)) - else: - ls.append(Name) - desc = get_text(data, '<p itemprop="description">', "</p>") - if desc: - ls.append(unichr(171) + self.decodeHTML(desc).strip() + unichr(187)) - for Title in ("Director", "Star", "Writer"): - list = get_text(data, "<h4 class=\"inline\">\s*?%s[s]?:\s*?</h4>" % Title, "(?:<span>|</div>)") - if list: - comp = compile__(">(.+?)</a>") - list = comp.findall(list) - if list: - ls.append("%ss: %s" % (Title, str.join(", ", list))) - rValue = get_text(data, '<span itemprop="ratingValue">', "</span>") - if rValue: - rCount = get_text(data, '<span itemprop="ratingCount">', "</span>") - if rCount: - rValue = "%s (Votes: %s)" % (rValue, rCount) - ls.append("Rating: %s" % rValue) - if len(ls) >= 2: - answer = self.decodeHTML(str.join(chr(10), ls)) + try: + + assert isinstance(data, dict) + + ls.append("%s, %s, %s." % (data["title"], data["year"], str.join(chr(32), data.get("runtime", ("??",))))) + ls.append(", ".join(data["genres"])) + ls.append(", ".join(data["country"])) + temp = data.get("directors") + if temp: + ls.append("Directors: " + ", ".join(temp[:3])) + temp = data.get("writers") + if temp: + ls.append("Writers: " + ", ".join(temp[:3])) + temp = data.get("actors") + if temp: + ls.append("Stars: " + ", ".join(temp[:5])) + temp = data.get("plot") or data.get("plot_simple") + if temp: + ls.append(unichr(171) + temp + unichr(187)) + temp = data.get("rating") + if temp: + ls.append("IMDb rating: %s (%s)" % (temp, data.get("rating_count", 0))) + except (AssertionError, TypeError, LookupError): + answer = self.AnsBase[5] else: - answer = self.AnsBase[1] - else: - answer = self.AnsBase[1] + answer = self.sub_ehtmls(str.join(chr(10), ls)) else: body = (body if chr(42) != c1st else body[2:].strip()) if body: body = body.encode("utf-8") - Opener = Web("http://www.imdb.com/find?", [("s", "tt"), ("q", body)], self.IMDbHeaders) + IMDbRequest = self.IMDbRequest.copy() + IMDbRequest["q"] = body + IMDbRequest["limit"] = "10" + Opener = Web("http://imdbapi.org/?", IMDbRequest.iteritems()) try: data = Opener.get_page(self.UserAgent_Moz) except Web.Two.HTTPError, exc: @@ -464,19 +480,26 @@ class expansion_temp(expansion): except: answer = self.AnsBase[0] else: - data = data.decode("utf-8") - list = get_text(data, "<table.*?>", "</table>") - if list: - comp = compile__("<td class=\"result_text\">\s<a href=\"/title/tt(\d+?)/\?ref_=fn_tt_tt_\d+?\">(.+?)</a>(.+?)</td>\s</tr>", 16) - list = comp.findall(list) - if list: - Number = itypes.Number() - ls = ["\n[#] [Name, Year] (#id)"] - for Numb, Name, Year in list[:20]: - ls.append("%d) %s %s (#%s)" % (Number.plus(), self.sub_ehtmls(Name), self.compile_st.sub("", Year.strip()), Numb)) - answer = str.join(chr(10), ls) + try: + data = self.json.loads(data) + except: + answer = self.AnsBase[1] else: - answer = self.AnsBase[5] + try: + + assert isinstance(data, list) + + data = sorted([(desc.get("rating"), + desc["title"], + desc["year"], + desc["imdb_id"][2:]) for desc in data], reverse = True) + except (AssertionError, TypeError, LookupError): + answer = self.AnsBase[5] + else: + ls = ["\n[#] [Name, Year] (#id)"] + for Number, (Numb, Name, Year, ID) in enumerate(data, 1): + ls.append("%d) %s, %s (#%s)" % (Number, Name, Year, ID)) + answer = self.sub_ehtmls(str.join(chr(10), ls)) else: answer = AnsBase[2] else: diff --git a/expansions/basic_control/code.py b/expansions/basic_control/code.py index b74a3b9..d5f4dd8 100644 --- a/expansions/basic_control/code.py +++ b/expansions/basic_control/code.py @@ -74,7 +74,7 @@ class expansion_temp(expansion): else: answer = self.AnsBase[3] % (conf) sleep(3.6) - if ejoinTimerName(conf) in iThr.ThrNames(): + if ejoinTimerName(conf) in iThr.getNames(): answer += self.AnsBase[13] else: answer = self.AnsBase[15] % (conf) @@ -135,20 +135,18 @@ class expansion_temp(expansion): Name = body.split()[0].lower() else: Name = get_disp(disp) - if InstansesDesc.has_key(Name): + if InstancesDesc.has_key(Name): ThrName = "%s-%s" % (Types[13], Name) if Clients.has_key(Name): - ThrIds = iThr.ThrNames() - if ThrName in ThrIds: - for Thr in iThr.enumerate(): - if Thr._Thread__name == ThrName: - Thr.kill() + for Thr in iThr.enumerate(): + if ThrName == Thr.getName(): + Thr.kill() if online(Name): try: Clients[Name].disconnect() except IOError: pass - if connect_client(Name, InstansesDesc[Name])[0]: + if connect_client(Name, InstancesDesc[Name])[0]: try: StartThr(composeThr(Dispatcher, ThrName, (Name,)), -1) except RuntimeError: @@ -173,7 +171,7 @@ class expansion_temp(expansion): Message(conf.name, exit_desclr, conf.disp) sleep(6) VarCache["alive"] = False - iThr.Threads_kill() + iThr.killAllThreads() for disp in Clients.keys(): if online(disp): sUnavailable(disp, exit_desclr) @@ -189,7 +187,7 @@ class expansion_temp(expansion): Message(conf.name, exit_desclr, conf.disp) sleep(6) VarCache["alive"] = False - iThr.Threads_kill() + iThr.killAllThreads() for disp in Clients.keys(): if online(disp): sUnavailable(disp, exit_desclr) diff --git a/expansions/basic_control/insc.py b/expansions/basic_control/insc.py index 41205cb..778fefb 100644 --- a/expansions/basic_control/insc.py +++ b/expansions/basic_control/insc.py @@ -28,7 +28,7 @@ else: "I have joined -> '%s'", # 2 "I can't join -> '%s'", # 3 "Attention! %s (%s) ordered me to leave -> '%s'", # 4 - "Chat is already in list.", # 5 + "Chat is already in the list.", # 5 "Apparently '%s' isn't a conference. I wouldn't join it.", # 6 "I'm %s -» XMPP BOT. Joined by order from %s", # 7 "Rejoin by command from %s", # 8 diff --git a/expansions/books/code.py b/expansions/books/code.py index 4b96ac7..9089aad 100644 --- a/expansions/books/code.py +++ b/expansions/books/code.py @@ -3,11 +3,12 @@ # BlackSmith mark.2 # exp_name = "books" # /code.py v.x8 # Id: 29~8c -# Code © (2011-2012) by WitcherGeralt [alkorgun@gmail.com] +# Code © (2011-2013) by WitcherGeralt [alkorgun@gmail.com] class expansion_temp(expansion): def __init__(self, name): + check_sqlite() expansion.__init__(self, name) import fb2 @@ -82,11 +83,11 @@ class expansion_temp(expansion): def command_get_books(self, stype, source, body, disp): if body: - list = body.split() - a1 = (list.pop(0)).lower() + args = body.split() + a1 = (args.pop(0)).lower() if a1 in ("show", "показать".decode("utf-8")): - if list: - a2 = (list.pop(0)).lower() + if args: + a2 = (args.pop(0)).lower() if a2 in ("names", "названия".decode("utf-8")): with database(self.BooksFile) as db: db("select name from books order by name") @@ -108,7 +109,7 @@ class expansion_temp(expansion): } if desc.has_key(a2): a2 = desc.get(a2, None) - if a2 in ls and list: + if a2 in ls and args: a3 = body[((body.lower()).find(a0) + len(a0)):].strip() if a2 in ("author", "genre"): with database(self.BooksFile) as db: @@ -148,7 +149,7 @@ class expansion_temp(expansion): else: answer = self.AnsBase[0] elif a1 in ("info", "инфо".decode("utf-8")): - if list: + if args: a2 = body[((body.lower()).find(a1) + len(a1)):].strip() a3 = self.getID(a2) with database(self.BooksFile) as db: @@ -184,8 +185,8 @@ class expansion_temp(expansion): answer = AnsBase[2] elif a1 in ("read", "читать".decode("utf-8")): jid = get_source(source[1], source[2]) - if list: - a2 = (list.pop(0)).lower() + if args: + a2 = (args.pop(0)).lower() if a2 in ("next", "далее".decode("utf-8")): if jid: with database(self.ReadersFile) as db: @@ -248,23 +249,23 @@ class expansion_temp(expansion): answer = AnsBase[2] else: with database(self.BooksFile) as db: - db("select id from books") - db_desc = db.fetchall() - if db_desc: - answer = self.AnsBase[8] % len(db_desc) + db("select count(id) from books") + count = db.fetchone() + if count[0]: + answer = self.AnsBase[8] % count else: answer = self.AnsBase[0] Answer(answer, stype, source, disp) def command_set_books(self, stype, source, body, disp): if body: - list = body.split() - if len(list) >= 2: - a1 = (list.pop(0)).lower() + args = body.split() + if len(args) >= 2: + a1 = (args.pop(0)).lower() if a1 in ("add", "добавить".decode("utf-8")): - a2 = (list.pop(0)).lower() + a2 = (args.pop(0)).lower() if a2 in ("file", "fb2", "файл".decode("utf-8")): - if list: + if args: Path = body[((body.lower()).find(a2) + len(a2)):].strip() if AsciiSys: Path = Path.encode("utf-8") @@ -299,12 +300,12 @@ class expansion_temp(expansion): else: answer = self.AnsBase[15] elif a1 in ("edit", "править".decode("utf-8")): - if len(list) >= 4: - a2 = self.getID(list.pop(0)) + if len(args) >= 4: + a2 = self.getID(args.pop(0)) if a2: - a3 = (list.pop(0)).lower() + a3 = (args.pop(0)).lower() if a3 in ("info", "инфо".decode("utf-8")): - a4 = (list.pop(0)).lower() + a4 = (args.pop(0)).lower() a0, ls = a4, "author;year;genre;seq1;seq2;cover;annotation;link;name;c0".split(";") desc = { "автор".decode("utf-8"): ls[0], @@ -322,7 +323,7 @@ class expansion_temp(expansion): if desc.has_key(a4): a4 = desc.get(a4, None) if a4 in ls: - a5 = (list.pop(0)).lower() + a5 = (args.pop(0)).lower() if a4 in (ls[1], ls[4]): if isNumber(a5): a5 = int(a5) @@ -354,7 +355,7 @@ class expansion_temp(expansion): db("select page from %s" % a2) lines = db.fetchall() llens = len(lines) - a4 = (list.pop(0)).lower() + a4 = (args.pop(0)).lower() if a4 in ("add", "добавить".decode("utf-8")): a5 = body[((body.lower()).find(a4) + len(a4)):].strip() if llens: @@ -366,9 +367,9 @@ class expansion_temp(expansion): db.commit() answer = AnsBase[4] elif a4 in ("delete", "удалить".decode("utf-8")): - a5 = (list.pop(0)).lower() - if list: - a6 = list.pop(0) + a5 = (args.pop(0)).lower() + if args: + a6 = args.pop(0) if isNumber(a6): a6 = int(a6) if a5 in ("before", "до".decode("utf-8")): @@ -436,7 +437,7 @@ class expansion_temp(expansion): else: answer = AnsBase[2] elif a1 in ("delete", "удалить".decode("utf-8")): - a2 = self.getID(list.pop(0)) + a2 = self.getID(args.pop(0)) if a2: with database(self.BooksFile) as db: db("select * from books where id=?", (a2,)) diff --git a/expansions/config/code.py b/expansions/config/code.py index d46b2f0..e76c4f3 100644 --- a/expansions/config/code.py +++ b/expansions/config/code.py @@ -71,12 +71,12 @@ class expansion_temp(expansion): def command_cls_config(self, stype, source, body, disp): if body: - list = body.split() - if len(list) >= 2: - body = (list.pop(0)).lower() + args = body.split() + if len(args) >= 2: + body = (args.pop(0)).lower() if body in ("del", "удалить".decode("utf-8")): - Name = (list.pop(0)).lower() - if InstansesDesc.has_key(Name): + Name = (args.pop(0)).lower() + if InstancesDesc.has_key(Name): clients = Clients.keys() if not Clients.has_key(Name) or len(clients) >= 2: if Name == GenDisp: @@ -99,12 +99,10 @@ class expansion_temp(expansion): if Gen == client_config(ConDisp, x)[0]: ConDisp.remove_section(x) if Clients.has_key(Name): - ThrIds = iThr.ThrNames() ThrName = "%s-%s" % (Types[13], Name) - if ThrName in ThrIds: - for Thr in iThr.enumerate(): - if Thr._Thread__name == ThrName: - Thr.kill() + for Thr in iThr.enumerate(): + if ThrName == Thr.getName(): + Thr.kill() for conf in Chats.itervalues(): if conf.disp == Name: if online(Name): @@ -122,7 +120,7 @@ class expansion_temp(expansion): pass if Flood.has_key(Name): del Flood[Name] - del InstansesDesc[Name] + del InstancesDesc[Name] for x in ConDisp.sections(): if Name == client_config(ConDisp, x)[0]: ConDisp.remove_section(x) @@ -135,22 +133,22 @@ class expansion_temp(expansion): else: answer = self.AnsBase[11] elif body in ("add", "добавить".decode("utf-8")): - if len(list) >= 3: - host = (list.pop(0)).lower() - user = (list.pop(0)).lower() - code = (list.pop(0)) - if list: - port = (list.pop(0)) + if len(args) >= 3: + host = (args.pop(0)).lower() + user = (args.pop(0)).lower() + code = (args.pop(0)) + if args: + port = (args.pop(0)) if not isNumber(port): port = "5222" else: port = "5222" jid = "%s@%s" % (user, host) serv = (host) - if list: - serv = (list.pop(0)).lower() + if args: + serv = (args.pop(0)).lower() if not Clients.has_key(jid): - if not InstansesDesc.has_key(jid): + if not InstancesDesc.has_key(jid): if connect_client(jid, (serv, port, host, user, code))[0]: Numb = itypes.Number() Name = "CLIENT%d" % (len(ConDisp.sections()) + Numb.plus()) @@ -163,7 +161,7 @@ class expansion_temp(expansion): ConDisp.set(Name, "user", user) ConDisp.set(Name, "pass", code) Instance, desc = client_config(ConDisp, Name) - InstansesDesc[Instance] = desc + InstancesDesc[Instance] = desc cat_file(ConDispFile, self.get_config(ConDisp)) try: StartThr(composeThr(Dispatcher, "%s-%s" % (Types[13], Instance), (Instance,)), -1) @@ -183,12 +181,12 @@ class expansion_temp(expansion): else: answer = AnsBase[2] elif body in ("password", "пароль".decode("utf-8")): - Name = (list.pop(0)).lower() - if InstansesDesc.has_key(Name): - if list: - code = (list.pop(0)) - if list: - if (list.pop(0)).lower() in ("set", "записать".decode("utf-8")): + Name = (args.pop(0)).lower() + if InstancesDesc.has_key(Name): + if args: + code = (args.pop(0)) + if args: + if (args.pop(0)).lower() in ("set", "записать".decode("utf-8")): changed = True else: code, symbols = "", "%s.%s_%s+(!}{#)" % (CharCase[0], CharCase[1], CharCase[2]) @@ -230,11 +228,11 @@ class expansion_temp(expansion): ConDisp.set(x, "pass", code) cat_file(ConDispFile, self.get_config(ConDisp)) break - serv = InstansesDesc[Name][0] - port = InstansesDesc[Name][1] - host = InstansesDesc[Name][2] - user = InstansesDesc[Name][3] - InstansesDesc[Name] = (serv, port, host, user, code) + serv = InstancesDesc[Name][0] + port = InstancesDesc[Name][1] + host = InstancesDesc[Name][2] + user = InstancesDesc[Name][3] + InstancesDesc[Name] = (serv, port, host, user, code) answer = AnsBase[4] else: answer = AnsBase[7] diff --git a/expansions/config/insc.py b/expansions/config/insc.py index 3b79a7a..d697573 100644 --- a/expansions/config/insc.py +++ b/expansions/config/insc.py @@ -28,7 +28,7 @@ else: "Forbidden!", # 7 "The system can not allocate resources to another client.", # 8 "No connection.", # 9 - "This jid is already in list.", # 10 + "This jid is already in the list.", # 10 "'%s' not in clients-list.", # 11 "'%s' is offline." # 12 )
\ No newline at end of file diff --git a/expansions/cron/code.py b/expansions/cron/code.py index c2e4608..b48f018 100644 --- a/expansions/cron/code.py +++ b/expansions/cron/code.py @@ -199,7 +199,7 @@ class expansion_temp(expansion): def start_cron(self): Name = self.def_cron.func_name for Thr in iThr.enumerate(): - if Thr._Thread__name.startswith(Name): + if Thr.name.startswith(Name): Thr.kill() if initialize_file(self.CronFile, "({}, 0)"): cdesc, ccnt = eval(get_file(self.CronFile)) diff --git a/expansions/info/code.py b/expansions/info/code.py index 374e7b7..b23f4ee 100644 --- a/expansions/info/code.py +++ b/expansions/info/code.py @@ -11,8 +11,8 @@ class expansion_temp(expansion): expansion.__init__(self, name) def command_online(self, stype, source, body, disp): - ls, ThrIds = self.AnsBase[7], iThr.ThrNames() - for numb, disp_ in enumerate(sorted(InstansesDesc.keys()), 1): + ls, ThrIds = self.AnsBase[7], iThr.getNames() + for numb, disp_ in enumerate(sorted(InstancesDesc.keys()), 1): alive = str("%s-%s" % (Types[13], disp_) in ThrIds) connect = online(disp_) if not connect: diff --git a/expansions/note/code.py b/expansions/note/code.py index 750efc1..ed2630f 100644 --- a/expansions/note/code.py +++ b/expansions/note/code.py @@ -1,13 +1,14 @@ # coding: utf-8 # BlackSmith mark.2 -# exp_name = "note" # /code.py v.x7 -# Id: 22~6c -# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com] +# exp_name = "note" # /code.py v.x8 +# Id: 22~7c +# Code © (2010-2013) by WitcherGeralt [alkorgun@gmail.com] class expansion_temp(expansion): def __init__(self, name): + check_sqlite() expansion.__init__(self, name) NoteFile = dynamic % ("notepad.db") diff --git a/expansions/talkers/code.py b/expansions/talkers/code.py index 110002a..34e96b6 100644 --- a/expansions/talkers/code.py +++ b/expansions/talkers/code.py @@ -1,19 +1,22 @@ # coding: utf-8 # BlackSmith mark.2 -# exp_name = "talkers" # /code.py v.x5 -# Id: 14~4c -# Code © (2010-2012) by WitcherGeralt [alkorgun@gmail.com] +# exp_name = "talkers" # /code.py v.x6 +# Id: 14~5c +# Code © (2010-2013) by WitcherGeralt [alkorgun@gmail.com] class expansion_temp(expansion): def __init__(self, name): + check_sqlite() expansion.__init__(self, name) TalkersFile = "talkers.db" TalkersDesc = {} + db = lambda self, conf: database(cefile(chat_file(conf, self.TalkersFile)), self.TalkersDesc[conf]) + def command_talkers(self, stype, source, body, disp): if Chats.has_key(source[1]): if body: @@ -29,11 +32,9 @@ class expansion_temp(expansion): else: Number = 0 if a2 in ("local", "локальный".decode("utf-8")): - filename = cefile(chat_file(source[1], self.TalkersFile)) - with self.TalkersDesc[source[1]]: - with database(filename) as db: - db("select * from talkers order by -msgs") - db_desc = db.fetchmany(Number if Number > 0 else 10) + with self.db(source[1]) as db: + db("select * from talkers order by -msgs") + db_desc = db.fetchmany(Number if Number > 0 else 10) if db_desc: answer, Numb = self.AnsBase[0], itypes.Number() for x in db_desc: @@ -43,11 +44,9 @@ class expansion_temp(expansion): elif a2 in ("global", "глобальный".decode("utf-8")): Glob_dbs = {} for conf in Chats.keys(): - filename = cefile(chat_file(conf, self.TalkersFile)) - with self.TalkersDesc[conf]: - with database(filename) as db: - db("select * from talkers order by -msgs") - db_desc = db.fetchmany(256) + with self.db(conf) as db: + db("select * from talkers order by -msgs") + db_desc = db.fetchmany(256) for x in db_desc: if Glob_dbs.has_key(x[0]): Glob_dbs[x[0]][2] += x[2] @@ -76,11 +75,9 @@ class expansion_temp(expansion): def get_talker_stats(source_): x, y = 0, 0 for conf in Chats.keys(): - filename = cefile(chat_file(conf, self.TalkersFile)) - with self.TalkersDesc[conf]: - with database(filename) as db: - db("select * from talkers where jid=?", (source_,)) - db_desc = db.fetchone() + with self.db(conf) as db: + db("select * from talkers where jid=?", (source_,)) + db_desc = db.fetchone() if db_desc: x += db_desc[2] y += db_desc[3] @@ -108,11 +105,9 @@ class expansion_temp(expansion): else: Glob_dbs = {} for conf in Chats.keys(): - filename = cefile(chat_file(conf, self.TalkersFile)) - with self.TalkersDesc[conf]: - with database(filename) as db: - db("select * from talkers where (jid like ? or lastnick like ?) order by -msgs", (a2, a2)) - db_desc = db.fetchmany(10) + with self.db(conf) as db: + db("select * from talkers where (jid like ? or lastnick like ?) order by -msgs", (a2, a2)) + db_desc = db.fetchmany(10) for x in db_desc: if Glob_dbs.has_key(x[0]): Glob_dbs[x[0]][2] += x[2] @@ -138,11 +133,9 @@ class expansion_temp(expansion): a2 = body[((body.lower()).find(a1) + len(a1)):].strip() def get_talker_stats(source_, conf): - filename = cefile(chat_file(conf, self.TalkersFile)) - with self.TalkersDesc[conf]: - with database(filename) as db: - db("select * from talkers where jid=?", (source_,)) - x = db.fetchone() + with self.db(conf) as db: + db("select * from talkers where jid=?", (source_,)) + x = db.fetchone() if x: answer = self.AnsBase[2] % (x[2], x[3], str(round((float(x[3]) / x[2]), 1))) else: @@ -165,11 +158,9 @@ class expansion_temp(expansion): if source_: answer = get_talker_stats(source_, source[1]) else: - filename = cefile(chat_file(source[1], self.TalkersFile)) - with self.TalkersDesc[source[1]]: - with database(filename) as db: - db("select * from talkers where (jid like ? or lastnick like ?) order by -msgs", (a2, a2)) - db_desc = db.fetchmany(10) + with self.db(source[1]) as db: + db("select * from talkers where (jid like ? or lastnick like ?) order by -msgs", (a2, a2)) + db_desc = db.fetchmany(10) if db_desc: answer, Numb = self.AnsBase[0], itypes.Number() for x in db_desc: @@ -192,16 +183,14 @@ class expansion_temp(expansion): source_ = get_source(source[1], source[2]) if source_: nick = source[2].strip() - filename = cefile(chat_file(source[1], self.TalkersFile)) - with self.TalkersDesc[source[1]]: - with database(filename) as db: - db("select * from talkers where jid=?", (source_,)) - db_desc = db.fetchone() - if db_desc: - db("update talkers set lastnick=?, msgs=?, words=? where jid=?", (nick, (db_desc[2] + 1), (db_desc[3] + len(body.split())), source_)) - else: - db("insert into talkers values (?,?,?,?)", (source_, nick, 1, len(body.split()))) - db.commit() + with self.db(source[1]) as db: + db("select * from talkers where jid=?", (source_,)) + db_desc = db.fetchone() + if db_desc: + db("update talkers set lastnick=?, msgs=?, words=? where jid=?", (nick, (db_desc[2] + 1), (db_desc[3] + len(body.split())), source_)) + else: + db("insert into talkers values (?,?,?,?)", (source_, nick, 1, len(body.split()))) + db.commit() def init_talkers_base(self, conf): filename = cefile(chat_file(conf, self.TalkersFile)) diff --git a/expansions/user_stats/code.py b/expansions/user_stats/code.py index 9b395f0..b454c0c 100644 --- a/expansions/user_stats/code.py +++ b/expansions/user_stats/code.py @@ -1,30 +1,31 @@ # coding: utf-8 # BlackSmith mark.2 -# exp_name = "user_stats" # /code.py v.x6 -# Id: 17~5c -# Code © (2010-2012) by WitcherGeralt [alkorgun@gmail.com] +# exp_name = "user_stats" # /code.py v.x7 +# Id: 17~6c +# Code © (2010-2013) by WitcherGeralt [alkorgun@gmail.com] class expansion_temp(expansion): def __init__(self, name): + check_sqlite() expansion.__init__(self, name) UstatsFile = "jstat.db" UstatsDesc = {} + db = lambda self, conf: database(cefile(chat_file(conf, self.UstatsFile)), self.UstatsDesc[conf]) + def command_user_stats(self, stype, source, body, disp): if Chats.has_key(source[1]): if not body: body = get_source(source[1], source[2]) elif Chats[source[1]].isHere(body): body = get_source(source[1], body) - filename = cefile(chat_file(source[1], self.UstatsFile)) - with self.UstatsDesc[source[1]]: - with database(filename) as db: - db("select * from stat where jid=?", (body,)) - db_desc = db.fetchone() + with self.db(source[1]) as db: + db("select * from stat where jid=?", (body,)) + db_desc = db.fetchone() if db_desc: answer = self.AnsBase[0] % (db_desc[3], db_desc[2], db_desc[1]) if db_desc[3] >= 2 and db_desc[4]: @@ -54,22 +55,21 @@ class expansion_temp(expansion): def calc_stat_04eh(self, conf, nick, instance, role, stanza, disp): if instance and nick != get_nick(conf): - date, filename = strfTime(local = False), cefile(chat_file(conf, self.UstatsFile)) - with self.UstatsDesc[conf]: - with database(filename) as db: - db("select * from stat where jid=?", (instance,)) - db_desc = db.fetchone() - if db_desc: - db("update stat set joined=?, joins=? where jid=?", (date, (db_desc[3] + 1), instance)) - if nick not in db_desc[6].split("-/-"): - db("update stat set nicks=? where jid=?", ("%s-/-%s" % (db_desc[6], nick), instance)) - arole = "%s/%s" % (role) - if db_desc[1] != arole: - db("update stat set arole=? where jid=?", (arole, instance)) - db.commit() - else: - db("insert into stat values (?,?,?,?,?,?,?)", (instance, "%s/%s" % (role), date, 1, "", "", nick)) - db.commit() + date = strfTime(local = False) + with self.db(conf) as db: + db("select * from stat where jid=?", (instance,)) + db_desc = db.fetchone() + if db_desc: + db("update stat set joined=?, joins=? where jid=?", (date, (db_desc[3] + 1), instance)) + if nick not in db_desc[6].split("-/-"): + db("update stat set nicks=? where jid=?", ("%s-/-%s" % (db_desc[6], nick), instance)) + arole = "%s/%s" % (role) + if db_desc[1] != arole: + db("update stat set arole=? where jid=?", (arole, instance)) + db.commit() + else: + db("insert into stat values (?,?,?,?,?,?,?)", (instance, "%s/%s" % (role), date, 1, "", "", nick)) + db.commit() def calc_stat_05eh(self, conf, nick, sbody, scode, disp): if nick != get_nick(conf): @@ -80,42 +80,37 @@ class expansion_temp(expansion): sbody = "banned:(%s)" % (sbody) elif scode == sCodes[2]: sbody = "kicked:(%s)" % (sbody) - date, filename = strfTime(local = False), cefile(chat_file(conf, self.UstatsFile)) - with self.UstatsDesc[conf]: - with database(filename) as db: - db("select * from stat where jid=?", (source_,)) - db_desc = db.fetchone() - if db_desc: - db("update stat set seen=?, leave=? where jid=?", (date, sbody, source_)) - db.commit() + date = strfTime(local = False) + with self.db(conf) as db: + db("select * from stat where jid=?", (source_,)) + db_desc = db.fetchone() + if db_desc: + db("update stat set seen=?, leave=? where jid=?", (date, sbody, source_)) + db.commit() def calc_stat_06eh(self, conf, old_nick, nick, disp): if nick != get_nick(conf): source_ = get_source(conf, nick) if source_: - filename = cefile(chat_file(conf, self.UstatsFile)) - with self.UstatsDesc[conf]: - with database(filename) as db: - db("select * from stat where jid=?", (source_,)) - db_desc = db.fetchone() - if db_desc and nick not in db_desc[6].split("-/-"): - db("update stat set nicks=? where jid=?", ("%s-/-%s" % (db_desc[6], nick), source_)) - db.commit() + with self.db(conf) as db: + db("select * from stat where jid=?", (source_,)) + db_desc = db.fetchone() + if db_desc and nick not in db_desc[6].split("-/-"): + db("update stat set nicks=? where jid=?", ("%s-/-%s" % (db_desc[6], nick), source_)) + db.commit() def calc_stat_07eh(self, conf, nick, role, disp): if nick != get_nick(conf): source_ = get_source(conf, nick) if source_: - filename = cefile(chat_file(conf, self.UstatsFile)) - with self.UstatsDesc[conf]: - with database(filename) as db: - db("select * from stat where jid=?", (source_,)) - db_desc = db.fetchone() - if db_desc: - arole = "%s/%s" % (role) - if db_desc[1] != arole: - db("update stat set arole=? where jid=?", (arole, source_)) - db.commit() + with self.db(conf) as db: + db("select * from stat where jid=?", (source_,)) + db_desc = db.fetchone() + if db_desc: + arole = "%s/%s" % (role) + if db_desc[1] != arole: + db("update stat set arole=? where jid=?", (arole, source_)) + db.commit() def init_stat_base(self, conf): filename = cefile(chat_file(conf, self.UstatsFile)) diff --git a/expansions/wtf/code.py b/expansions/wtf/code.py index efc5943..ab3575f 100644 --- a/expansions/wtf/code.py +++ b/expansions/wtf/code.py @@ -1,13 +1,14 @@ # coding: utf-8 # BlackSmith mark.2 -# exp_name = "wtf" # /code.py v.x3 -# Id: 28~3c -# Code © (2012) by WitcherGeralt [alkorgun@gmail.com] +# exp_name = "wtf" # /code.py v.x4 +# Id: 28~4c +# Code © (2012-2013) by WitcherGeralt [alkorgun@gmail.com] class expansion_temp(expansion): def __init__(self, name): + check_sqlite() expansion.__init__(self, name) Base = dynamic % ("wtf.db") diff --git a/expansions/wtf/insc.py b/expansions/wtf/insc.py index fa20ac0..8c8c750 100644 --- a/expansions/wtf/insc.py +++ b/expansions/wtf/insc.py @@ -4,7 +4,7 @@ if DefLANG in ("RU", "UA"): AnsBase_temp = tuple([line.decode("utf-8") for line in ( "Всего %d определений в глобальной базе:\n%s", # 0 "Всего %d определений в базе %s:\n%s", # 1 - "Базы пусты", # 2 + "Базы пусты.", # 2 "%s - %d соответствий.", # 3 "Нет соответсвий в базах.", # 4 "\->\n%s:\n\t%s\n\nDefined by %s (on %s)", # 5 diff --git a/librarys.zip b/librarys.zip Binary files differindex 95b5c91..5782594 100644 --- a/librarys.zip +++ b/librarys.zip |