aboutsummaryrefslogtreecommitdiff
path: root/rpki/mysql_import.py
diff options
context:
space:
mode:
Diffstat (limited to 'rpki/mysql_import.py')
-rw-r--r--rpki/mysql_import.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/rpki/mysql_import.py b/rpki/mysql_import.py
new file mode 100644
index 00000000..88d30357
--- /dev/null
+++ b/rpki/mysql_import.py
@@ -0,0 +1,65 @@
+# $Id$
+#
+# Copyright (C) 2011-2012 Internet Systems Consortium ("ISC")
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+#
+# Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+"""
+Import wrapper for MySQLdb.
+
+MySQLdb is an independent package, not part of Python, and has some
+minor version skew issues with respect to Python itself, which we want
+to suppress so that they don't annoy the user. None of this is
+particularly hard, but the maze of whacky incantations required to do
+this in multiple version of Python on multiple platforms is somewhat
+tedious, and turns out to cause other problems when combined with the
+way we construct executable Python scripts containing a standard
+header indicating the location of our config file.
+
+So it turns out to be easier just to put all of the import voodoo
+here, and have other modules that need MySQLdb import the MySQL module
+object from this module. Looks kind of strange, but seems to work.
+"""
+
+# pylint: disable=W0611
+
+from __future__ import with_statement
+
+import warnings
+
+if hasattr(warnings, "catch_warnings"):
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ import MySQLdb
+else:
+ import MySQLdb
+
+import _mysql_exceptions
+
+warnings.simplefilter("error", _mysql_exceptions.Warning)
+
+import MySQLdb.converters