# -*- coding: ascii -*-u"""====================================== Column inspection and representation======================================Column inspection and generation.:Copyright: Copyright 2010 - 2025 Andr\xe9 Malo or his licensors, as applicable:License: Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License."""__author__=u"Andr\xe9 Malo"importsqlalchemyas_safrom.import_typefrom.import_util
[docs]def__repr__(self):""" Make string representation Return: str: The string representation """identity=getattr(_sa,"Identity",None)ifidentityisnotNoneandisinstance(self._default,identity):return"%s.%s"%(self._symbols["sa"],_util.unicode(self._default),)ifself._default.for_update:for_update=", for_update=%r"%(True,)else:for_update=""return"%s(%r%s)"%(self._symbols["default"],_util.unicode(self._default.arg),for_update,)
[docs]classColumn(object):""" Column container Attributes: _name (unicode): Name _ctype (SA type): Column type _nullable (bool): Nullable? _primary_key (bool): Part of a primary key? _autoincrement (bool): Possible autoincrement? _server_default (Default clause): Default clause _symbols (Symbols): Symbol table """
[docs]def__init__(self,name,ctype,nullable,primary_key,autoincrement,server_default,symbols,):""" Initialization Parameters: name (unicode): Column name ctype (SA type): Column type nullable (bool): Nullable? primary_key (bool): Part of a primary key? autoincrement (bool): Possible autoincrement? server_default (Default clause): Default clause symbols (Symbols): Symbol table """self._name=nameself._ctype=ctypeself._nullable=nullableself._primary_key=primary_keyself._autoincrement=autoincrementself._server_default=server_defaultself._symbols=symbols
[docs]@classmethoddeffrom_sa(cls,column,symbols):""" Construct from SA column :Parameters: column (SA column): SA column symbols (Symbols): Symbol table Returns: Column: New column instance """returncls(column.name,_type.Type.by_column(column,symbols),nullable=column.nullable,primary_key=column.primary_key,autoincrement=column.autoincrement,server_default=column.server_default,symbols=symbols,)
[docs]def__repr__(self):""" Make string representation Returns: str: The string representation """params=list(map(repr,(self._name,self._ctype)))ifnotself._nullable:params.append("nullable=%r"%(False,))ifnotself._autoincrementandself._primary_key:params.append("autoincrement=%r"%(False,))ifself._server_defaultisnotNone:params.append("server_default=%r"%(ServerDefault(self._server_default,self._symbols),))return"%s(%s)"%(self._symbols["column"],", ".join(params))