Exemple #1
0
    def __init__(self, msg=None, errno=None, values=None, sqlstate=None):
        super(Error, self).__init__()
        self.msg = msg
        self._full_msg = self.msg
        self.errno = errno or -1
        self.sqlstate = sqlstate

        if not self.msg and (2000 <= self.errno < 3000):
            self.msg = get_client_error(self.errno)
            if values is not None:
                try:
                    self.msg = self.msg % values
                except TypeError as err:
                    self.msg = "{0} (Warning: {1})".format(self.msg, str(err))
        elif not self.msg:
            self._full_msg = self.msg = 'Unknown error'

        if self.msg and self.errno != -1:
            fields = {'errno': self.errno, 'msg': self.msg.encode('utf8')}
            if self.sqlstate:
                fmt = '{errno} ({state}): {msg}'
                fields['state'] = self.sqlstate
            else:
                fmt = '{errno}: {msg}'
            self._full_msg = fmt.format(**fields)

        self.args = (self.errno, self._full_msg, self.sqlstate)
Exemple #2
0
    def __init__(self, msg=None, errno=None, values=None, sqlstate=None):
        super(Error, self).__init__()
        self.msg = msg
        self._full_msg = self.msg
        self.errno = errno or -1
        self.sqlstate = sqlstate

        if not self.msg and (2000 <= self.errno < 3000):
            self.msg = get_client_error(self.errno)
            if values is not None:
                try:
                    self.msg = self.msg % values
                except TypeError as err:
                    self.msg = "{0} (Warning: {1})".format(self.msg, str(err))
        elif not self.msg:
            self._full_msg = self.msg = 'Unknown error'

        if self.msg and self.errno != -1:
            fields = {
                'errno': self.errno,
                'msg': self.msg.encode('utf8')
            }
            if self.sqlstate:
                fmt = '{errno} ({state}): {msg}'
                fields['state'] = self.sqlstate
            else:
                fmt = '{errno}: {msg}'
            self._full_msg = fmt.format(**fields)
Exemple #3
0
    def __init__(self, msg=None, errno=None, values=None, sqlstate=None):
        self.msg = msg
        self.errno = errno or -1
        self.sqlstate = sqlstate

        if not self.msg and (2000 <= self.errno < 3000):
            errmsg = get_client_error(self.errno)
            if values is not None:
                try:
                    errmsg = errmsg % values
                except TypeError, err:
                    errmsg = errmsg + " (Warning: %s)" % err
            self.msg = errmsg
 def __init__(self, msg=None, errno=None, values=None, sqlstate=None):
     self.msg = msg
     self.errno = errno or -1
     self.sqlstate = sqlstate
     
     if not self.msg and (2000 <= self.errno < 3000):
         errmsg = get_client_error(self.errno)
         if values is not None:
             try:
                 errmsg = errmsg % values
             except TypeError, err:
                 errmsg = errmsg + " (Warning: %s)" % err
         self.msg = errmsg
Exemple #5
0
    def test_get_client_error(self):
        try:
            locales.get_client_error(2000, language='spam')
        except ImportError as err:
            self.assertEqual("No localization support for language 'spam'",
                             str(err))
        else:
            self.fail("ImportError not raised")

        exp = "Unknown MySQL error"
        self.assertEqual(exp, locales.get_client_error(2000))
        self.assertEqual(exp, locales.get_client_error('CR_UNKNOWN_ERROR'))

        try:
            locales.get_client_error(tuple())
        except ValueError as err:
            self.assertEqual(
                "error argument needs to be either an integer or string",
                str(err))
        else:
            self.fail("ValueError not raised")
Exemple #6
0
	def test_get_client_error(self):
		try:
			locales.get_client_error(2000, language='spam')
		except ImportError as err:
			self.assertEqual("No localization support for language 'spam'",
							 str(err))
		else:
			self.fail("ImportError not raised")

		exp = "Unknown MySQL error"
		self.assertEqual(exp, locales.get_client_error(2000))
		self.assertEqual(exp, locales.get_client_error('CR_UNKNOWN_ERROR'))

		try:
			locales.get_client_error(tuple())
		except ValueError as err:
			self.assertEqual(
				"error argument needs to be either an integer or string",
				str(err))
		else:
			self.fail("ValueError not raised")
Exemple #7
0
	def test_get_client_error(self):
		try:
			locales.get_client_error(2000, language='spam')
		except ImportError, err:
			self.assertEqual("No localization support for language 'spam'",
							 str(err))
Exemple #8
0
		try:
			from mysql.connector.locales.eng import client_error
		except ImportError:
			self.fail("locales.eng.client_error could not be imported")

	def test_get_client_error(self):
		try:
			locales.get_client_error(2000, language='spam')
		except ImportError, err:
			self.assertEqual("No localization support for language 'spam'",
							 str(err))
		else:
			self.fail("ImportError not raised")

		exp = u"Unknown MySQL error"
		self.assertEqual(exp, locales.get_client_error(2000))
		self.assertEqual(exp, locales.get_client_error('CR_UNKNOWN_ERROR'))

		try:
			locales.get_client_error(tuple())
		except ValueError, err:
			self.assertEqual(
				"error argument needs to be either an integer or string",
				str(err))
		else:
			self.fail("ValueError not raised")

class LocalesEngClientErrorTests(tests.MySQLConnectorTests):
	"""Testing locales.eng.client_error"""
	def test__GENERATED_ON(self):
		try:
Exemple #9
0
 def test_get_client_error(self):
     try:
         locales.get_client_error(2000, language='spam')
     except ImportError, err:
         self.assertEqual("No localization support for language 'spam'",
                          str(err))
Exemple #10
0
        try:
            from mysql.connector.locales.eng import client_error
        except ImportError:
            self.fail("locales.eng.client_error could not be imported")

    def test_get_client_error(self):
        try:
            locales.get_client_error(2000, language='spam')
        except ImportError, err:
            self.assertEqual("No localization support for language 'spam'",
                             str(err))
        else:
            self.fail("ImportError not raised")

        exp = u"Unknown MySQL error"
        self.assertEqual(exp, locales.get_client_error(2000))
        self.assertEqual(exp, locales.get_client_error('CR_UNKNOWN_ERROR'))

        try:
            locales.get_client_error(tuple())
        except ValueError, err:
            self.assertEqual(
                "error argument needs to be either an integer or string",
                str(err))
        else:
            self.fail("ValueError not raised")


class LocalesEngClientErrorTests(tests.MySQLConnectorTests):
    """Testing locales.eng.client_error"""
    def test__GENERATED_ON(self):