Add proper error for FileNotFoundError in Python 2

This commit is contained in:
Sam Whited 2015-07-22 22:01:17 -05:00
parent 7f6be7e97a
commit 50f0a6fec6
1 changed files with 29 additions and 12 deletions

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