Selaa lähdekoodia

Lazy-importing of py-bcrypt and pycrypto; restructured deps in setup.

tags/v0.2
Ben Kurtovic 12 vuotta sitten
vanhempi
commit
655624c2cf
7 muutettua tiedostoa jossa 64 lisäystä ja 31 poistoa
  1. +10
    -1
      earwigbot/commands/crypt.py
  2. +1
    -1
      earwigbot/commands/time_command.py
  3. +4
    -2
      earwigbot/config/__init__.py
  4. +24
    -10
      earwigbot/config/script.py
  5. +2
    -2
      earwigbot/wiki/copyvios/__init__.py
  6. +1
    -1
      earwigbot/wiki/site.py
  7. +22
    -14
      setup.py

+ 10
- 1
earwigbot/commands/crypt.py Näytä tiedosto

@@ -24,8 +24,11 @@ import hashlib

from Crypto.Cipher import Blowfish

from earwigbot import importer
from earwigbot.commands import Command

Blowfish = importer.new("Crypto.Cipher.Blowfish")

class Crypt(Command):
"""Provides hash functions with !hash (!hash list for supported algorithms)
and Blowfish encryption with !encrypt and !decrypt."""
@@ -66,7 +69,13 @@ class Crypt(Command):
self.reply(data, msg.format(data.command))
return

cipher = Blowfish.new(hashlib.sha256(key).digest())
try:
cipher = Blowfish.new(hashlib.sha256(key).digest())
except ImportError:
msg = "This command requires the 'pycrypto' package: https://www.dlitz.net/software/pycrypto/"
self.reply(data, msg)
return

try:
if data.command == "encrypt":
if len(text) % 8:


+ 1
- 1
earwigbot/commands/time_command.py Näytä tiedosto

@@ -56,7 +56,7 @@ class Time(Command):
try:
tzinfo = pytz.timezone(timezone)
except ImportError:
msg = "This command requires the 'pytz' module: http://pytz.sourceforge.net/"
msg = "This command requires the 'pytz' package: http://pytz.sourceforge.net/"
self.reply(data, msg)
return
except pytz.exceptions.UnknownTimeZoneError:


+ 4
- 2
earwigbot/config/__init__.py Näytä tiedosto

@@ -28,10 +28,9 @@ import logging.handlers
from os import mkdir, path
import stat

from Crypto.Cipher import Blowfish
import bcrypt
import yaml

from earwigbot import importer
from earwigbot.config.formatter import BotFormatter
from earwigbot.config.node import ConfigNode
from earwigbot.config.ordered_yaml import OrderedLoader
@@ -39,6 +38,9 @@ from earwigbot.config.permissions import PermissionsDB
from earwigbot.config.script import ConfigScript
from earwigbot.exceptions import NoConfigError

Blowfish = importer.new("Crypto.Cipher.Blowfish")
bcrypt = importer.new("bcrypt")

__all__ = ["BotConfig"]

class BotConfig(object):


+ 24
- 10
earwigbot/config/script.py Näytä tiedosto

@@ -29,13 +29,14 @@ import stat
import sys
from textwrap import fill, wrap

from Crypto.Cipher import Blowfish
import bcrypt
import yaml

from earwigbot import exceptions
from earwigbot import exceptions, importer
from earwigbot.config.ordered_yaml import OrderedDumper

Blowfish = importer.new("Crypto.Cipher.Blowfish")
bcrypt = importer.new("bcrypt")

__all__ = ["ConfigScript"]

RULES_TEMPLATE = """# -*- coding: utf-8 -*-
@@ -145,17 +146,30 @@ class ConfigScript(object):
is to run on a public computer like the Toolserver, but
otherwise the need to enter a key everytime you start
the bot may be annoying.""")
self.data["metadata"]["encryptPasswords"] = False
if self._ask_bool("Encrypt stored passwords?"):
self.data["metadata"]["encryptPasswords"] = True
key = getpass(self.PROMPT + "Enter an encryption key: ")
msg = "Running {0} rounds of bcrypt...".format(self.BCRYPT_ROUNDS)
self._print_no_nl(msg)
signature = bcrypt.hashpw(key, bcrypt.gensalt(self.BCRYPT_ROUNDS))
self.data["metadata"]["signature"] = signature
self._cipher = Blowfish.new(sha256(key).digest())
print " done."
else:
self.data["metadata"]["encryptPasswords"] = False
try:
salt = bcrypt.gensalt(self.BCRYPT_ROUNDS)
signature = bcrypt.hashpw(key, salt)
self._cipher = Blowfish.new(sha256(key).digest())
except ImportError:
print " error!"
self._print("""Encryption requires the 'py-bcrypt' and
'pycrypto' packages:""")
strt, end = " * \x1b[36m", "\x1b[0m"
print strt + "http://www.mindrot.org/projects/py-bcrypt/" + end
print strt + "https://www.dlitz.net/software/pycrypto/" + end
self._print("""I will disable encryption for now; restart
configuration after installing these packages if
you want it.""")
self._pause()
else:
self.data["metadata"]["encryptPasswords"] = True
self.data["metadata"]["signature"] = signature
print " done."

print
self._print("""The bot can temporarily store its logs in the logs/


+ 2
- 2
earwigbot/wiki/copyvios/__init__.py Näytä tiedosto

@@ -95,8 +95,8 @@ class CopyvioMixIn(object):
if engine == "Yahoo! BOSS":
try:
oauth.__version__ # Force-load the lazy module
except (ImportError, AttributeError):
e = "The package 'oauth2' could not be imported"
except ImportError:
e = "Yahoo! BOSS requires the 'oauth2' package: https://github.com/simplegeo/python-oauth2"
raise exceptions.UnsupportedSearchEngineError(e)
return YahooBOSSSearchEngine(credentials)



+ 1
- 1
earwigbot/wiki/site.py Näytä tiedosto

@@ -530,7 +530,7 @@ class Site(object):
try:
self._sql_conn = oursql.connect(**args)
except ImportError:
e = "Module 'oursql' is required for SQL queries."
e = "SQL querying requires the 'oursql' package: http://packages.python.org/oursql/"
raise exceptions.SQLError(e)

def _get_service_order(self):


+ 22
- 14
setup.py Näytä tiedosto

@@ -25,24 +25,32 @@ from setuptools import setup, find_packages

from earwigbot import __version__

# Not all of these dependencies are required, particularly the copyvio-specific
# ones (bs4, lxml, nltk, and oauth2) and the command-specific one (pytz). The
# bot should run fine without them, but will raise an exception if you try to
# detect copyvios or run a command that requries one.

dependencies = [
required_deps = [
"PyYAML >= 3.10", # Parsing config files
"beautifulsoup4 >= 4.1.1", # Parsing/scraping HTML for copyvios
"lxml >= 2.3.5", # Faster parser for BeautifulSoup
"mwparserfromhell >= 0.1", # Parsing wikicode for manipulation
"nltk >= 2.0.2", # Parsing sentences to split article content for copyvios
"oauth2 >= 1.5.211", # Interfacing with Yahoo! BOSS Search for copyvios
"oursql >= 0.9.3.1", # Interfacing with MediaWiki databases
"py-bcrypt >= 0.2", # Hashing the bot key in the config file
"pycrypto >= 2.6", # Storing bot passwords and keys in the config file
"pytz >= 2012d", # Handling timezones for the !time IRC command
]

extra_deps = {
"crypto": [
"py-bcrypt >= 0.2", # Hashing the bot key in the config file
"pycrypto >= 2.6", # Storing bot passwords and keys in the config file
],
"sql": [
"oursql >= 0.9.3.1", # Interfacing with MediaWiki databases
],
"copyvios": [
"beautifulsoup4 >= 4.1.1", # Parsing/scraping HTML
"lxml >= 2.3.5", # Faster parser for BeautifulSoup
"nltk >= 2.0.2", # Parsing sentences to split article content
"oauth2 >= 1.5.211", # Interfacing with Yahoo! BOSS Search
],
"time": [
"pytz >= 2012d", # Handling timezones for the !time IRC command
],
}

dependencies = required_deps + sum(extra_deps.values(), [])

with open("README.rst") as fp:
long_docs = fp.read()



Ladataan…
Peruuta
Tallenna