def afterInit(self): # Set the text definitions separately. Since they require special indentation to match the # generated code and not the code in this class, it is much cleaner to define them # separately. self._defineTextBlocks() # Expression for substituing default parameters self.prmDefPat = re.compile(r"([^=]+)=?.*") # Added to ensure unique object names self._generatedNames = [""] # Holds the class file we will create in order to aid introspection try: self._classFileName = self.Application.getTempFile("py") except AttributeError: # No app object fd, self._classFileName = tempfile.mkstemp(suffix="py") os.close(fd) self._codeImportAs = "_daboCode" # Holds any import statements to apply to the class code. self._import = "" # RE pattern to extract the method signature. self._codeDefExtract = re.compile("(\s*)def ([^\(]+)\(([^\)]*)\):") # Counter for the suffix that is appended to each method. This is simpler # than tracking each method name and only adding if there is a conflict. self._methodNum = 0 # This is the text that will go into the temp .py file for executed code self._codeFileText = self._hdrText # Tracks the current sizer type self._sizerTypeStack = [] # Location of the cdxml source file, if any self._srcFile = None # Encoding to be used self._encoding = dabo.getEncoding()
def _getEncoding(self): """Get backend encoding.""" try: return self._encoding except AttributeError: self._encoding = dabo.getEncoding() return self._encoding
def _getEncoding(self): try: v = self._encoding except AttributeError: v = dabo.getEncoding() self._encoding = v return v
def getConnection(self, connectInfo, **kwargs): import MySQLdb as dbapi port = connectInfo.Port if not port: port = 3306 kwargs = {} # MySQLdb doesn't provide decimal converter by default, so we do it here from MySQLdb import converters from MySQLdb import constants DECIMAL = constants.FIELD_TYPE.DECIMAL conversions = converters.conversions.copy() conversions[DECIMAL] = decimal.Decimal def dec2str(dec, dic): return str(dec) conversions[decimal.Decimal] = dec2str kwargs["conv"] = conversions # Determine default charset charset = None db = connectInfo.Database if db: try: cn = dbapi.connect(host=connectInfo.Host, user=connectInfo.User, passwd=connectInfo.revealPW(), port=port) crs = cn.cursor() # Params don't work here; need direct string to execute crs.execute("show create database %s" % (db, )) charset = crs.fetchone()[1].split("DEFAULT CHARACTER SET")[1].split()[0] self.Encoding = charset except IndexError: pass if charset is None: # Use the default Dabo encoding charset = dabo.getEncoding() charset = charset.lower().replace("-", "") try: self._connection = dbapi.connect(host=connectInfo.Host, user = connectInfo.User, passwd = connectInfo.revealPW(), db=connectInfo.Database, port=port, charset=charset, **kwargs) except Exception as e: try: errMsg = ustr(e).decode(self.Encoding) except UnicodeError: errMsg = ustr(e) if "access denied" in errMsg.lower(): raise dException.DBNoAccessException(errMsg) else: raise dException.DatabaseException(errMsg) return self._connection
def safeLoad(val): try: ret = pickle.loads(val) except UnicodeEncodeError: for enctype in (dabo.getEncoding(), "utf-8", "iso8859-1"): try: ret = pickle.loads(val.encode(enctype)) except KeyError: continue break else: raise return ret
def jsonDecode(val): ret = None try: ret = jsonConverter.loads(val) except UnicodeDecodeError: # Try typical encodings, starting with the default. for enctype in (dabo.getEncoding(), "utf-8", "latin-1"): try: ret = jsonConverter.loads(val, enctype) break except UnicodeDecodeError: continue if ret is None: raise return ret
def __init__(self, encoding=None): self.root = None self.nodeStack = [] self.attsToSkip = [] self._inCode = False self._mthdName = "" self._mthdCode = "" self._codeDict = None self._inProp = False self._propName = "" self._propData = "" self._propDict = None self._currPropAtt = "" self._currPropDict = None if encoding is None: self._encoding = dabo.getEncoding() else: self._encoding = encoding
def dictStringify(dct): """ The ability to pass a properties dict to an object relies on the practice of passing '\*\*properties' to a function. Seems that Python requires that the keys in any dict being expanded like this be strings, not unicode. This method returns a dict with all unicode keys changed to strings. """ ret = {} for kk, vv in dct.items(): if isinstance(kk, unicode): try: ret[str(kk)] = vv except UnicodeEncodeError: kk = kk.encode(dabo.getEncoding()) ret[kk] = vv else: ret[kk] = vv return ret
def _getEncoding(self): try: return self._encoding except AttributeError: self._encoding = dabo.getEncoding() return self._encoding
def test_Encoding(self): biz = self.biz self.assertEqual(biz.Encoding, dabo.getEncoding()) biz.Encoding = "latin-1" self.assertEqual(biz.Encoding, "latin-1")
import sys import warnings import dabo _defaultLanguage, _defaultEncoding = locale.getdefaultlocale() if _defaultLanguage is None: _defaultLanguage = dabo.defaultLanguage if dabo.overrideLocaleLanguage: _defaultLanguage = dabo.defaultLanguage if _defaultEncoding is None: _defaultEncoding = dabo.getEncoding() _domains = {} _currentTrans = None _languageAliases = { "catalan": "ca", "català": "ca", "german": "de", "deutsch": "de", "greek": "el", "ελληνικά": "el", "english": "en", "english_united states": "en", "english (uk)": "en_gb", "english_uk": "en_gb",
def getEncodings(): encodings = (dabo.getEncoding(), getpreferredencoding(), "iso8859-1", "iso8859-15", "cp1252", "utf-8") for enc in encodings: yield enc
def getConnection(self, connectInfo, **kwargs): import MySQLdb as dbapi port = connectInfo.Port if not port: port = 3306 kwargs = {} # MySQLdb doesn't provide decimal converter by default, so we do it here from MySQLdb import converters from MySQLdb import constants DECIMAL = constants.FIELD_TYPE.DECIMAL conversions = converters.conversions.copy() conversions[DECIMAL] = decimal.Decimal def dec2str(dec, dic): return str(dec) conversions[decimal.Decimal] = dec2str kwargs["conv"] = conversions # Determine default charset charset = None db = connectInfo.Database if db: try: cn = dbapi.connect(host=connectInfo.Host, user=connectInfo.User, passwd=connectInfo.revealPW(), port=port) crs = cn.cursor() # Params don't work here; need direct string to execute crs.execute("show create database %s" % (db, )) charset = crs.fetchone()[1].split( "DEFAULT CHARACTER SET")[1].split()[0] self.Encoding = charset except IndexError: pass if charset is None: # Use the default Dabo encoding charset = dabo.getEncoding() charset = charset.lower().replace("-", "") try: self._connection = dbapi.connect(host=connectInfo.Host, user=connectInfo.User, passwd=connectInfo.revealPW(), db=connectInfo.Database, port=port, charset=charset, **kwargs) except Exception, e: try: errMsg = ustr(e).decode(self.Encoding) except UnicodeError: errMsg = ustr(e) if "access denied" in errMsg.lower(): raise dException.DBNoAccessException(errMsg) else: raise dException.DatabaseException(errMsg)
import os import sys import warnings import dabo _defaultLanguage, _defaultEncoding = locale.getdefaultlocale() if _defaultLanguage is None: _defaultLanguage = dabo.defaultLanguage if dabo.overrideLocaleLanguage: _defaultLanguage = dabo.defaultLanguage if _defaultEncoding is None: _defaultEncoding = dabo.getEncoding() _domains = {} _currentTrans = None _languageAliases = { "catalan": "ca", "català": "ca", "german": "de", "deutsch": "de", "greek": "el", "ελληνικά": "el", "english": "en", "english_united states": "en", "english (uk)": "en_gb", "english_uk": "en_gb",