Merge pull request #12 from SamWhited/better_file_not_found_error

Add proper error for FileNotFoundError in Python 2
This commit is contained in:
Daniel Gultsch 2015-07-23 10:01:19 +02:00
commit 958aec3da6

View File

@ -1,18 +1,24 @@
#!/usr/bin/env python #!/usr/bin/env python
import yaml import argparse
import sys import errno
import hashlib
import logging
import mimetypes
import os
import random
import shutil import shutil
import signal import signal
import logging import sleekxmpp
import string
import hashlib
import random
import os
import ssl import ssl
import argparse import string
from threading import Thread import sys
import yaml
from sleekxmpp.componentxmpp import ComponentXMPP
from threading import Lock from threading import Lock
from threading import Thread
try: try:
# Python 3 # Python 3
from http.server import HTTPServer, BaseHTTPRequestHandler from http.server import HTTPServer, BaseHTTPRequestHandler
@ -21,9 +27,20 @@ except ImportError:
# Python 2 # Python 2
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from SocketServer import ThreadingMixIn from SocketServer import ThreadingMixIn
FileNotFoundError = IOError
import sleekxmpp try:
from sleekxmpp.componentxmpp import ComponentXMPP FileNotFoundError
except NameError:
# Python 2
class FileNotFoundError(IOError):
def __init__(self, message=None, *args):
super(FileNotFoundError, self).__init__(args)
self.message = message
self.errno = errno.ENOENT
def __str__(self):
return self.message or os.strerror(self.errno)
LOGLEVEL=logging.DEBUG LOGLEVEL=logging.DEBUG