mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 02:49:27 +01:00
utils: Remove dependency on parent package.
This commit is contained in:
parent
0c6a88c4ca
commit
c01a956a8b
@ -32,6 +32,7 @@ import time
|
||||
import socket
|
||||
import telnetlib
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.utils as utils
|
||||
from supybot.commands import *
|
||||
from supybot.utils.iter import any
|
||||
@ -88,7 +89,10 @@ class Internet(callbacks.Plugin):
|
||||
irc.errorInvalid(_('domain'))
|
||||
return
|
||||
try:
|
||||
sock = utils.net.getSocket('%s.whois-servers.net' % usertld)
|
||||
sock = utils.net.getSocket('%s.whois-servers.net' % usertld,
|
||||
vhost=conf.supybot.protocols.irc.vhost(),
|
||||
vhostv6=conf.supybot.protocols.irc.vhostv6(),
|
||||
)
|
||||
sock.connect(('%s.whois-servers.net' % usertld, 43))
|
||||
except socket.error as e:
|
||||
irc.error(str(e))
|
||||
|
2
setup.py
2
setup.py
@ -74,7 +74,9 @@ try:
|
||||
except OSError: # Does not exist
|
||||
pass
|
||||
fd = open(os.path.join('src', 'version.py'), 'a')
|
||||
fd.write('import supybot.utils.python\n')
|
||||
fd.write("version = '0.83.4.1+limnoria %s'\n" % version)
|
||||
fd.write('supybot.utils.python._debug_software_version = version\n')
|
||||
fd.close()
|
||||
|
||||
if sys.version_info < (2, 6, 0):
|
||||
|
@ -30,7 +30,12 @@
|
||||
|
||||
from . import dynamicScope
|
||||
|
||||
from . import i18n
|
||||
|
||||
builtins = (__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)
|
||||
builtins['supybotInternationalization'] = i18n.PluginInternationalization()
|
||||
from . import utils
|
||||
del builtins['supybotInternationalization']
|
||||
|
||||
(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['format'] = utils.str.format
|
||||
|
||||
|
@ -370,6 +370,12 @@ registerGroup(supybot, 'reply')
|
||||
registerGroup(supybot.reply, 'format')
|
||||
registerChannelValue(supybot.reply.format, 'url',
|
||||
registry.String('<%s>', _("""Determines how urls should be formatted.""")))
|
||||
def url(s):
|
||||
if s:
|
||||
return supybot.reply.format.url() % s
|
||||
else:
|
||||
return ''
|
||||
utils.str.url = url
|
||||
registerChannelValue(supybot.reply.format, 'time',
|
||||
registry.String('%Y-%m-%dT%H:%M:%S%z', _("""Determines how timestamps
|
||||
printed for human reading should be formatted. Refer to the Python
|
||||
|
@ -263,7 +263,10 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
|
||||
drivers.log.connect(self.currentServer)
|
||||
try:
|
||||
self.conn = utils.net.getSocket(address, port=port,
|
||||
socks_proxy=socks_proxy)
|
||||
socks_proxy=socks_proxy,
|
||||
vhost=conf.supybot.protocols.irc.vhost(),
|
||||
vhostv6=conf.supybot.protocols.irc.vhostv6(),
|
||||
)
|
||||
except socket.error as e:
|
||||
drivers.log.connectError(self.currentServer, e)
|
||||
self.scheduleReconnect()
|
||||
|
@ -48,13 +48,17 @@ def split(s):
|
||||
csv.join = join
|
||||
csv.split = split
|
||||
|
||||
builtins = (__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)
|
||||
|
||||
# We use this often enough that we're going to stick it in builtins.
|
||||
def force(x):
|
||||
if callable(x):
|
||||
return x()
|
||||
else:
|
||||
return x
|
||||
(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['force'] = force
|
||||
builtins['force'] = force
|
||||
|
||||
internationalization = builtins.get('supybotInternationalization', None)
|
||||
|
||||
# These imports need to happen below the block above, so things get put into
|
||||
# __builtins__ appropriately.
|
||||
|
@ -47,9 +47,7 @@ from .str import format
|
||||
from .file import mktemp
|
||||
from .iter import imap
|
||||
from . import minisix
|
||||
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization()
|
||||
from . import internationalization as _
|
||||
|
||||
def warn_non_constant_time(f):
|
||||
@functools.wraps(f)
|
||||
|
@ -32,6 +32,7 @@
|
||||
from __future__ import division
|
||||
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
PY2 = False
|
||||
@ -85,8 +86,7 @@ else:
|
||||
L = lambda x:long(x)
|
||||
|
||||
def make_datetime_utc(dt):
|
||||
from .. import log
|
||||
log.warning('Timezones are not available on this version of '
|
||||
warnings.warn('Timezones are not available on this version of '
|
||||
'Python and may lead to incorrect results. You should '
|
||||
'consider upgrading to Python 3.')
|
||||
return dt.replace(tzinfo=None)
|
||||
@ -98,9 +98,8 @@ else:
|
||||
return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
|
||||
|
||||
def datetime__timestamp(dt):
|
||||
from .. import log
|
||||
import datetime
|
||||
log.warning('Timezones are not available on this version of '
|
||||
warnings.warn('Timezones are not available on this version of '
|
||||
'Python and may lead to incorrect results. You should '
|
||||
'consider upgrading to Python 3.')
|
||||
return timedelta__totalseconds(dt - datetime.datetime(1970, 1, 1))
|
||||
|
@ -62,18 +62,13 @@ def getSocket(host, port=None, socks_proxy=None, vhost=None, vhostv6=None):
|
||||
s.setproxy(socks.PROXY_TYPE_SOCKS5, hostname, int(port),
|
||||
rdns=True)
|
||||
return s
|
||||
import supybot.conf as conf
|
||||
if isIPV4(host):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
if not vhost:
|
||||
vhost = conf.supybot.protocols.irc.vhost()
|
||||
if vhost:
|
||||
s.bind((vhost, 0))
|
||||
return s
|
||||
elif isIPV6(host):
|
||||
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||
if not vhostv6:
|
||||
vhostv6 = conf.supybot.protocols.irc.vhostv6()
|
||||
if vhostv6:
|
||||
s.bind((vhostv6, 0))
|
||||
return s
|
||||
|
@ -116,6 +116,8 @@ def glob2re(g):
|
||||
return fnmatch.translate(g)[:-7]
|
||||
|
||||
|
||||
_debug_software_name = 'Limnoria'
|
||||
_debug_software_version = None
|
||||
# From http://code.activestate.com/recipes/52215-get-more-information-from-tracebacks/
|
||||
def collect_extra_debug_data():
|
||||
"""
|
||||
@ -133,11 +135,11 @@ def collect_extra_debug_data():
|
||||
finally:
|
||||
del tb
|
||||
|
||||
try:
|
||||
from supybot.version import version
|
||||
data += 'Supybot version: %s\n\n' % version
|
||||
except:
|
||||
data += '(Cannot get Supybot version.)\n\n'
|
||||
if _debug_software_version:
|
||||
data += '%s version: %s\n\n' % \
|
||||
(_debug_software_name, _debug_software_version)
|
||||
else:
|
||||
data += '(Cannot get %s version.)\n\n' % _debug_software_name
|
||||
|
||||
data += 'Locals by frame, innermost last:\n'
|
||||
for frame in stack:
|
||||
|
@ -43,8 +43,7 @@ from . import minisix
|
||||
from .iter import all, any
|
||||
from .structures import TwoWayDictionary
|
||||
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization()
|
||||
from . import internationalization as _
|
||||
internationalizeFunction = _.internationalizeFunction
|
||||
|
||||
try:
|
||||
@ -480,6 +479,8 @@ def timestamp(t):
|
||||
if t is None:
|
||||
t = time.time()
|
||||
return time.ctime(t)
|
||||
def url(url):
|
||||
return url
|
||||
|
||||
_formatRe = re.compile('%((?:\d+)?\.\d+f|[bfhiLnpqrsStTuv%])')
|
||||
def format(s, *args, **kwargs):
|
||||
@ -578,12 +579,7 @@ def format(s, *args, **kwargs):
|
||||
from .gen import timeElapsed
|
||||
return timeElapsed(args.pop())
|
||||
elif char == 'u':
|
||||
import supybot.conf as conf
|
||||
url = args.pop()
|
||||
if url:
|
||||
return conf.supybot.reply.format.url() % url
|
||||
else:
|
||||
return ''
|
||||
return url(args.pop())
|
||||
elif char == 'v':
|
||||
args.pop()
|
||||
return ''
|
||||
|
Loading…
Reference in New Issue
Block a user