Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'schema': 0.05; 'subject:Python': 0.06; 'column': 0.07; 'definitions': 0.07; 'element': 0.07; 'defines': 0.09; 'null,': 0.09; 'subset': 0.09; 'type,': 0.09; 'url:github': 0.09; 'python': 0.11; 'itself.': 0.14; "'title'": 0.16; 'burak': 0.16; 'columns': 0.16; 'from:addr:arskom.com.tr': 0.16; 'from:addr:burak.arslan': 0.16; 'from:name:burak arslan': 0.16; 'length,': 0.16; 'message- id:@arskom.com.tr': 0.16; 'received:arskomhosting.com': 0.16; 'wrote:': 0.18; 'app': 0.19; 'help.': 0.21; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'example.': 0.24; 'values': 0.27; 'header:In- Reply-To:1': 0.27; 'to:2**1': 0.27; 'wonder': 0.29; 'xml': 0.29; 'database,': 0.30; "skip:' 10": 0.31; 'that.': 0.31; 'etc.).': 0.31; 'class': 0.32; 'handled': 0.32; 'quite': 0.32; '(e.g.': 0.33; 'cases': 0.33; 'table': 0.34; 'problem': 0.35; "can't": 0.35; 'skip:u 20': 0.35; 'but': 0.35; 'false': 0.36; 'doing': 0.36; 'list': 0.37; 'level': 0.37; 'e.g.': 0.38; 'to:addr:python- list': 0.38; 'that,': 0.38; 'use.': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'easy': 0.60; 'hope': 0.61; 'conversion': 0.61; 'simple': 0.61; 'information': 0.63; 'such': 0.63; 'maximum': 0.63; 'more': 0.64; 'between': 0.67; 'frank': 0.68; 'you:': 0.81; 'allowable': 0.84; 'atomic': 0.84; 'choices.': 0.84; 'column.': 0.84; "it'd": 0.84; 'adopt': 0.91 Date: Fri, 24 Jan 2014 15:40:07 +0200 From: Burak Arslan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Frank Millman , python-list@python.org Subject: Re: Python declarative References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> In-Reply-To: X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1390571155 news.xs4all.nl 2940 [2001:888:2000:d::a6]:54316 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64682 On 01/24/14 11:21, Frank Millman wrote: > I store database metadata in the database itself. I have a table that > defines each table in the database, and I have a table that defines each > column. Column definitions include information such as data type, allow > null, allow amend, maximum length, etc. Some columns require that the value > is constrained to a subset of allowable values (e.g. 'title' must be one of > 'Mr', 'Mrs', etc.). I know that this can be handled by a 'check' constraint, > but I have added some additional features which can't be handled by that. So > I have a column in my column-definition table called 'choices', which > contains a JSON'd list of allowable choices. It is actually more complex > than that, but this will suffice for a simple example. I wonder whether your use cases can be fully handled by Xml Schema standard. It's quite robust and easy to use. You are already doing validation at the app level so I don't think it'd be much of a problem for you to adopt it. e.g. >>> from spyne.model import * >>> class C(ComplexModel): ... title = Unicode(values=['Mr', 'Mrs', 'Ms']) ... >>> from lxml import etree >>> from spyne.util.xml import get_validation_schema >>> schema = get_validation_schema([C], 'some_ns') >>> doc1 = etree.fromstring('Mr') >>> print schema.validate(doc1) True >>> doc2 = etree.fromstring('xyz') >>> print schema.validate(doc2) False >>> print schema.error_log :1:0:ERROR:SCHEMASV:SCHEMAV_CVC_ENUMERATION_VALID: Element '{some_ns}title': [facet 'enumeration'] The value 'xyz' is not an element of the set {'Mr', 'Mrs', 'Ms'}. :1:0:ERROR:SCHEMASV:SCHEMAV_CVC_DATATYPE_VALID_1_2_1: Element '{some_ns}title': 'xyz' is not a valid value of the atomic type '{some_ns}C_titleType'. >>> Also, if you need conversion between various serialization formats and Python object hierarchies, I put together an example for you: https://gist.github.com/plq/8596519 I hope these help. Best, Burak