Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'string.': 0.04; 'subject:Python': 0.05; 'attribute': 0.05; 'elements.': 0.05; 'float': 0.05; 'explanation': 0.09; 'object)': 0.09; 'to:addr:comp.lang.python': 0.09; 'type)': 0.09; 'cc:addr :python-list': 0.10; '(!)': 0.16; '(more': 0.16; 'doc)': 0.16; 'element.': 0.16; 'integers,': 0.16; 'unsupported': 0.16; 'wrappers': 0.16; 'string': 0.17; 'copied': 0.17; 'element': 0.17; 'instance': 0.17; 'integer': 0.17; 'pointed': 0.17; 'doc': 0.22; 'latter': 0.22; 'cc:2**0': 0.23; 'elements': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:[ 10': 0.26; 'implemented': 0.27; 'chris': 0.28; 'container': 0.29; 'document,': 0.29; 'dom': 0.29; 'parent': 0.29; 'represented': 0.29; 'strings,': 0.29; 'handled': 0.29; 'objects': 0.29; 'class': 0.29; 'classes': 0.30; 'keyword': 0.30; 'returned': 0.30; 'instances': 0.33; 'received:google.com': 0.34; 'or,': 0.34; 'list': 0.35; 'adds': 0.35; 'received:209.85': 0.35; 'child': 0.36; 'method': 0.36; 'possible': 0.37; 'itself': 0.37; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:$ 10': 0.66 Newsgroups: comp.lang.python Date: Fri, 21 Dec 2012 23:57:01 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=193.49.124.107; posting-account=cEyVOAoAAAAQ26Zg5AgQClqyybEKp-yz References: <50D256B3.4070709@udel.edu> <96edb672-dabd-4ab8-9e7c-3fa7f4a91437@googlegroups.com> <44335f22-555a-4806-b24a-7d4cb1d8e529@googlegroups.com> <4ddee631-b5b5-4cb4-82b0-00ca403b773e@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 193.49.124.107 MIME-Version: 1.0 Subject: Re: Brython - Python in the browser From: Pierre Quentel To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org 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: , Message-ID: Lines: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356163526 news.xs4all.nl 6962 [2001:888:2000:d::a6]:50131 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35343 I was over-simplifying - or, to put is less diplomatically, I screwed up - when I answered that the addition returned a string. As Chris pointed out, it made the explanation very confusing. My apologies The objects handled by + and <= can be : - strings, integers, floats - instances of $TagClass instances (more precisely, of classes copied from $TagClass, one for each HTML tag) : they are wrappers around a DOM element. The DOM element itself is the attribute "elt" of the $TagClass instance - the document, represented by the keyword doc. Its attribute "elt" is the document (top of the DOM tree) - instances of $AbstractClass, a container with a list of DOM elements. This list is the attribute "children" of the $TagClass instance Depending of the objects types, a+b returns the following objects : string + string : string (!) string + $TagClass : $AbstractTag with children [textNode(a),b.elt] string + $AbstractTag : $AbstractTag with [textNode(b)]+ b.children The 2 latter are implemented by the method __radd__ of $TagClass and $AbstractTag, invoqued by the method __add__ of the string class $TagClass + string : $AbstractTag with [a.elt,textNode(b)] $TagClass + $TagClass : $AbstractTag with [a.elt,b.elt] $TagClass + $AbstractTag : $AbstractTag with [a.elt]+b.children $AbstractTag + string : $AbstractTag with a.children+[textNode(b)] $AbstractTag + $TagClass : $AbstractTag with a.children + [b.elt] $AbstractTag + $AbstractTag : $AbstractTag with a.children + b.children (any type) + doc : unsupported doc + (any type) : unsupported The operation x <= y does the following : string <= (any object) : comparison, if possible ($TagClass | doc) <= string | integer | float : adds textNode(str(y)) to x.elt ($TagClass | doc) <= $TagClass : adds child y.elt to parent x.elt ($TagClass | doc) <= $AbstractTag : adds DOM elements in y.children to x.elt $AbstractClass <= (any type) : unsupported - Pierre