mirror of
https://github.com/jlu5/PyLink.git
synced 2025-02-17 05:51:00 +01:00
core: Replace imp (deprecated) with importlib, reword some docs & remove unneeded imports
This commit is contained in:
parent
adfa114c4b
commit
197532c1be
1
pylink
1
pylink
@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import imp
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
22
utils.py
22
utils.py
@ -1,12 +1,12 @@
|
|||||||
import string
|
import string
|
||||||
import re
|
import re
|
||||||
import inspect
|
import inspect
|
||||||
import imp
|
import importlib
|
||||||
|
import os
|
||||||
|
|
||||||
from log import log
|
from log import log
|
||||||
import world
|
import world
|
||||||
|
|
||||||
# This is separate from classes.py to prevent import loops.
|
|
||||||
class NotAuthenticatedError(Exception):
|
class NotAuthenticatedError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ class TS6SIDGenerator():
|
|||||||
return sid
|
return sid
|
||||||
|
|
||||||
def add_cmd(func, name=None):
|
def add_cmd(func, name=None):
|
||||||
"""Binds a command to the given command name."""
|
"""Binds an IRC command function to the given command name."""
|
||||||
if name is None:
|
if name is None:
|
||||||
name = func.__name__
|
name = func.__name__
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
@ -112,7 +112,7 @@ def add_cmd(func, name=None):
|
|||||||
return func
|
return func
|
||||||
|
|
||||||
def add_hook(func, command):
|
def add_hook(func, command):
|
||||||
"""Binds a hook function to the given command."""
|
"""Binds a hook function to the given command name."""
|
||||||
command = command.upper()
|
command = command.upper()
|
||||||
world.hooks[command].append(func)
|
world.hooks[command].append(func)
|
||||||
return func
|
return func
|
||||||
@ -142,21 +142,22 @@ def clientToServer(irc, numeric):
|
|||||||
|
|
||||||
_nickregex = r'^[A-Za-z\|\\_\[\]\{\}\^\`][A-Z0-9a-z\-\|\\_\[\]\{\}\^\`]*$'
|
_nickregex = r'^[A-Za-z\|\\_\[\]\{\}\^\`][A-Z0-9a-z\-\|\\_\[\]\{\}\^\`]*$'
|
||||||
def isNick(s, nicklen=None):
|
def isNick(s, nicklen=None):
|
||||||
"""Checks whether the string given is a valid nick."""
|
"""Returns whether the string given is a valid nick."""
|
||||||
if nicklen and len(s) > nicklen:
|
if nicklen and len(s) > nicklen:
|
||||||
return False
|
return False
|
||||||
return bool(re.match(_nickregex, s))
|
return bool(re.match(_nickregex, s))
|
||||||
|
|
||||||
def isChannel(s):
|
def isChannel(s):
|
||||||
"""Checks whether the string given is a valid channel name."""
|
"""Returns whether the string given is a valid channel name."""
|
||||||
return str(s).startswith('#')
|
return str(s).startswith('#')
|
||||||
|
|
||||||
def _isASCII(s):
|
def _isASCII(s):
|
||||||
|
"""Returns whether the string given is valid ASCII."""
|
||||||
chars = string.ascii_letters + string.digits + string.punctuation
|
chars = string.ascii_letters + string.digits + string.punctuation
|
||||||
return all(char in chars for char in s)
|
return all(char in chars for char in s)
|
||||||
|
|
||||||
def isServerName(s):
|
def isServerName(s):
|
||||||
"""Checks whether the string given is a server name."""
|
"""Returns whether the string given is a valid IRC server name."""
|
||||||
return _isASCII(s) and '.' in s and not s.startswith('.')
|
return _isASCII(s) and '.' in s and not s.startswith('.')
|
||||||
|
|
||||||
hostmaskRe = re.compile(r'^\S+!\S+@\S+$')
|
hostmaskRe = re.compile(r'^\S+!\S+@\S+$')
|
||||||
@ -504,9 +505,10 @@ def getHostmask(irc, user):
|
|||||||
return '%s!%s@%s' % (nick, ident, host)
|
return '%s!%s@%s' % (nick, ident, host)
|
||||||
|
|
||||||
def loadModuleFromFolder(name, folder):
|
def loadModuleFromFolder(name, folder):
|
||||||
"""Attempts an import of name from a specific folder, returning the resulting module."""
|
"""Attempts and returns an import of the given module name from a specific
|
||||||
moduleinfo = imp.find_module(name, folder)
|
folder."""
|
||||||
m = imp.load_source(name, moduleinfo[1])
|
fullpath = os.path.join(folder, '%s.py' % name)
|
||||||
|
m = importlib.machinery.SourceFileLoader(name, fullpath).load_module()
|
||||||
return m
|
return m
|
||||||
|
|
||||||
def getProtoModule(protoname):
|
def getProtoModule(protoname):
|
||||||
|
4
world.py
4
world.py
@ -19,8 +19,8 @@ plugins = {}
|
|||||||
whois_handlers = []
|
whois_handlers = []
|
||||||
started = threading.Event()
|
started = threading.Event()
|
||||||
|
|
||||||
plugins_folder = [os.path.join(os.getcwd(), 'plugins')]
|
plugins_folder = os.path.join(os.getcwd(), 'plugins')
|
||||||
protocols_folder = [os.path.join(os.getcwd(), 'protocols')]
|
protocols_folder = os.path.join(os.getcwd(), 'protocols')
|
||||||
|
|
||||||
version = "<unknown>"
|
version = "<unknown>"
|
||||||
source = "https://github.com/GLolol/PyLink" # CHANGE THIS IF YOU'RE FORKING!!
|
source = "https://github.com/GLolol/PyLink" # CHANGE THIS IF YOU'RE FORKING!!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user