INSTRUCTION
stringlengths
1
8.43k
RESPONSE
stringlengths
75
104k
passed a version: this version don t exists in the database and is younger than the last version - > do migrations up until this version this version don t exists in the database and is older than the last version - > do nothing is a unpredictable behavior this version exists in the database and is older than the last ...
def _execute_migrations(self, current_version, destination_version): """ passed a version: this version don't exists in the database and is younger than the last version -> do migrations up until this version this version don't exists in the database and is older than the last ve...
Generate a token string from bytes arrays. The token in the session is user specific.
def csrf_token(): """ Generate a token string from bytes arrays. The token in the session is user specific. """ if "_csrf_token" not in session: session["_csrf_token"] = os.urandom(128) return hmac.new(app.secret_key, session["_csrf_token"], digestmod=sha1).hexdigest()
Checks that token is correct aborting if not
def check_csrf_token(): """Checks that token is correct, aborting if not""" if request.method in ("GET",): # not exhaustive list return token = request.form.get("csrf_token") if token is None: app.logger.warning("Expected CSRF Token: not present") abort(400) if not safe_str_c...
Get the HTTPRequest object from thread storage or from a callee by searching each frame in the call stack.
def get_request(cls): """ Get the HTTPRequest object from thread storage or from a callee by searching each frame in the call stack. """ request = cls.get_global('request') if request: return request try: stack = inspect.stack() exc...
An alternative to: meth: flask. Flask. route or: meth: flask. Blueprint. route that always adds the POST method to the allowed endpoint request methods.
def route(app_or_blueprint, rule, **options): """An alternative to :meth:`flask.Flask.route` or :meth:`flask.Blueprint.route` that always adds the ``POST`` method to the allowed endpoint request methods. You should use this for all your view functions that would need to use Sijax. We're doing this bec...
Takes a Sijax response object and returns a valid Flask response object.
def _make_response(sijax_response): """Takes a Sijax response object and returns a valid Flask response object.""" from types import GeneratorType if isinstance(sijax_response, GeneratorType): # Streaming response using a generator (non-JSON response). # Upon returning a response, Flask...
Registers a single Comet callback function ( see: ref: comet - plugin ).
def register_comet_callback(self, *args, **kwargs): """Registers a single Comet callback function (see :ref:`comet-plugin`). Refer to :func:`sijax.plugin.comet.register_comet_callback` for more details - its signature differs slightly. This method's signature is the same, excep...
Registers all functions from the object as Comet functions ( see: ref: comet - plugin ).
def register_comet_object(self, *args, **kwargs): """Registers all functions from the object as Comet functions (see :ref:`comet-plugin`). This makes mass registration of functions a lot easier. Refer to :func:`sijax.plugin.comet.register_comet_object` for more details -ts sign...
Registers an Upload function ( see: ref: upload - plugin ) to handle a certain form.
def register_upload_callback(self, *args, **kwargs): """Registers an Upload function (see :ref:`upload-plugin`) to handle a certain form. Refer to :func:`sijax.plugin.upload.register_upload_callback` for more details. This method passes some additional arguments to your handler...
Executes a callback and returns the proper response.
def execute_callback(self, *args, **kwargs): """Executes a callback and returns the proper response. Refer to :meth:`sijax.Sijax.execute_callback` for more details. """ response = self._sijax.execute_callback(*args, **kwargs) return _make_response(response)
Returns True if the given HttpRequest has permission to view * at least one * page in the admin site.
def has_permission(self, request, extra_permission=None): """ Returns True if the given HttpRequest has permission to view *at least one* page in the admin site. """ permission = request.user.is_active and request.user.is_staff if extra_permission: permission ...
Wraps a view in authentication/ caching logic
def as_view(self, view, cacheable=False, extra_permission=None): """ Wraps a view in authentication/caching logic extra_permission can be used to require an extra permission for this view, such as a module permission """ def inner(request, *args, **kwargs): if not se...
Serve static files below a given point in the directory structure.
def media(self, request, module, path): """ Serve static files below a given point in the directory structure. """ if module == 'nexus': document_root = os.path.join(NEXUS_ROOT, 'media') else: document_root = self.get_module(module).media_root pat...
Login form
def login(self, request, form_class=None): "Login form" from django.contrib.auth import login as login_ from django.contrib.auth.forms import AuthenticationForm if form_class is None: form_class = AuthenticationForm if request.POST: form = form_class(req...
Logs out user and redirects them to Nexus home
def logout(self, request): "Logs out user and redirects them to Nexus home" from django.contrib.auth import logout logout(request) return HttpResponseRedirect(reverse('nexus:index', current_app=self.name))
Basic dashboard panel
def dashboard(self, request): "Basic dashboard panel" # TODO: these should be ajax module_set = [] for namespace, module in self.get_modules(): home_url = module.get_home_url(request) if hasattr(module, 'render_on_dashboard'): # Show by default, u...
Displays the row of buttons for delete and save.
def submit_row(context): """ Displays the row of buttons for delete and save. """ opts = context['opts'] change = context['change'] is_popup = context['is_popup'] save_as = context['save_as'] return { 'onclick_attrib': (opts.get_ordered_objects() and change ...
Auto - discover INSTALLED_APPS nexus. py modules and fail silently when not present. This forces an import on them to register any api bits they may want.
def autodiscover(site=None): """ Auto-discover INSTALLED_APPS nexus.py modules and fail silently when not present. This forces an import on them to register any api bits they may want. Specifying ``site`` will register all auto discovered modules with the new site. """ # Bail out if autodis...
Internal for parsing
def handle_starttag(self, tagName, attributeList, isSelfClosing=False): ''' Internal for parsing ''' tagName = tagName.lower() inTag = self._inTag if isSelfClosing is False and tagName in IMPLICIT_SELF_CLOSING_TAGS: isSelfClosing = True newTag = ...
Internal for parsing
def handle_endtag(self, tagName): ''' Internal for parsing ''' try: foundIt = False inTag = self._inTag for i in range(len(inTag)): if inTag[i].tagName == tagName: foundIt = True break ...
Internal for parsing
def handle_data(self, data): ''' Internal for parsing ''' if data: inTag = self._inTag if len(inTag) > 0: inTag[-1].appendText(data) elif data.strip(): #and not self.getRoot(): # Must be text prior to or after root n...
Internal for parsing
def handle_entityref(self, entity): ''' Internal for parsing ''' inTag = self._inTag if len(inTag) > 0: inTag[-1].appendText('&%s;' %(entity,)) else: raise MultipleRootNodeException()
Internal for parsing
def handle_charref(self, charRef): ''' Internal for parsing ''' inTag = self._inTag if len(inTag) > 0: inTag[-1].appendText('&#%s;' %(charRef,)) else: raise MultipleRootNodeException()
Internal for parsing
def handle_comment(self, comment): ''' Internal for parsing ''' inTag = self._inTag if len(inTag) > 0: inTag[-1].appendText('<!-- %s -->' %(comment,)) else: raise MultipleRootNodeException()
getRootNodes - Gets all objects at the root ( first level ; no parent ). Use this if you may have multiple roots ( not children of <html > ) Use this method to get objects for example in an AJAX request where <html > may not be your root.
def getRootNodes(self): ''' getRootNodes - Gets all objects at the "root" (first level; no parent). Use this if you may have multiple roots (not children of <html>) Use this method to get objects, for example, in an AJAX request where <html> may not be your root. Not...
getAllNodes - Get every element
def getAllNodes(self): ''' getAllNodes - Get every element @return TagCollection<AdvancedTag> ''' ret = TagCollection() for rootNode in self.getRootNodes(): ret.append(rootNode) ret += rootNode.getAllChildNodes() return ret
getElementsByTagName - Searches and returns all elements with a specific tag name.
def getElementsByTagName(self, tagName, root='root'): ''' getElementsByTagName - Searches and returns all elements with a specific tag name. @param tagName <lowercase str> - A lowercase string of the tag name. @param root <AdvancedTag/'root'> - Search...
getElementsByName - Searches and returns all elements with a specific name.
def getElementsByName(self, name, root='root'): ''' getElementsByName - Searches and returns all elements with a specific name. @param name <str> - A string of the name attribute @param root <AdvancedTag/'root'> - Search starting at a specific node, if...
getElementById - Searches and returns the first ( should only be one ) element with the given ID.
def getElementById(self, _id, root='root'): ''' getElementById - Searches and returns the first (should only be one) element with the given ID. @param id <str> - A string of the id attribute. @param root <AdvancedTag/'root'> - Search starting at a spec...
getElementsByClassName - Searches and returns all elements containing a given class name.
def getElementsByClassName(self, className, root='root'): ''' getElementsByClassName - Searches and returns all elements containing a given class name. @param className <str> - A one-word class name @param root <AdvancedTag/'root'> - Search starting at...
getElementsByAttr - Searches the full tree for elements with a given attribute name and value combination. This is always a full scan.
def getElementsByAttr(self, attrName, attrValue, root='root'): ''' getElementsByAttr - Searches the full tree for elements with a given attribute name and value combination. This is always a full scan. @param attrName <lowercase str> - A lowercase attribute name ...
getElementsWithAttrValues - Returns elements with an attribute named by #attrName contains one of the values in the list #values
def getElementsWithAttrValues(self, attrName, attrValues, root='root'): ''' getElementsWithAttrValues - Returns elements with an attribute, named by #attrName contains one of the values in the list, #values @param attrName <lowercase str> - A lowercase attribute name @param ...
getElementsCustomFilter - Scan elements using a provided function
def getElementsCustomFilter(self, filterFunc, root='root'): ''' getElementsCustomFilter - Scan elements using a provided function @param filterFunc <function>(node) - A function that takes an AdvancedTag as an argument, and returns True if some arbitrary criteria is met @re...
getFirstElementCustomFilter - Scan elements using a provided function stop and return the first match.
def getFirstElementCustomFilter(self, filterFunc, root='root'): ''' getFirstElementCustomFilter - Scan elements using a provided function, stop and return the first match. @see getElementsCustomFilter to match multiple elements @param filterFunc <function>(node) - A fun...
Checks if #em is found anywhere within this element tree
def contains(self, em): ''' Checks if #em is found anywhere within this element tree @param em <AdvancedTag> - Tag of interest @return <bool> - If element #em is within this tree ''' for rootNode in self.getRootNodes(): if rootNode.contains(em): ...
Check if #uid is found anywhere within this element tree
def containsUid(self, uid): ''' Check if #uid is found anywhere within this element tree @param uid <uuid.UUID> - Uid @return <bool> - If #uid is found within this tree ''' for rootNode in self.getRootNodes(): if rootNode.containsUid(uid): ...
find - Perform a search of elements using attributes as keys and potential values as values ( i. e. parser. find ( name = blah tagname = span ) will return all elements in this document with the name blah of the tag type span )
def find(self, **kwargs): ''' find - Perform a search of elements using attributes as keys and potential values as values (i.e. parser.find(name='blah', tagname='span') will return all elements in this document with the name "blah" of the tag type "span...
getHTML - Get the full HTML as contained within this tree.
def getHTML(self): ''' getHTML - Get the full HTML as contained within this tree. If parsed from a document, this will contain the original whitespacing. @returns - <str> of html @see getFormattedHTML @see getMiniHTML ...
getFormattedHTML - Get formatted and xhtml of this document replacing the original whitespace with a pretty - printed version
def getFormattedHTML(self, indent=' '): ''' getFormattedHTML - Get formatted and xhtml of this document, replacing the original whitespace with a pretty-printed version @param indent - space/tab/newline of each level of indent, or integer for how many spaces per level ...
getMiniHTML - Gets the HTML representation of this document without any pretty formatting and disregarding original whitespace beyond the functional.
def getMiniHTML(self): ''' getMiniHTML - Gets the HTML representation of this document without any pretty formatting and disregarding original whitespace beyond the functional. @return <str> - HTML with only functional whitespace present ''' from .For...
_reset - reset this object. Assigned to. reset after __init__ call.
def _reset(self): ''' _reset - reset this object. Assigned to .reset after __init__ call. ''' HTMLParser.reset(self) self.root = None self.doctype = None self._inTag = []
feed - Feed contents. Use parseStr or parseFile instead.
def feed(self, contents): ''' feed - Feed contents. Use parseStr or parseFile instead. @param contents - Contents ''' contents = stripIEConditionals(contents) try: HTMLParser.feed(self, contents) except MultipleRootNodeException: ...
parseFile - Parses a file and creates the DOM tree and indexes
def parseFile(self, filename): ''' parseFile - Parses a file and creates the DOM tree and indexes @param filename <str/file> - A string to a filename or a file object. If file object, it will not be closed, you must close. ''' self.reset() if isinstance(...
parseStr - Parses a string and creates the DOM tree and indexes.
def parseStr(self, html): ''' parseStr - Parses a string and creates the DOM tree and indexes. @param html <str> - valid HTML ''' self.reset() if isinstance(html, bytes): self.feed(html.decode(self.encoding)) else: self.feed(h...
createElementFromHTML - Creates an element from a string of HTML.
def createElementFromHTML(cls, html, encoding='utf-8'): ''' createElementFromHTML - Creates an element from a string of HTML. If this could create multiple root-level elements (children are okay), you must use #createElementsFromHTML which returns a list of element...
createElementsFromHTML - Creates elements from provided html and returns a list of the root - level elements children of these root - level nodes are accessable via the usual means.
def createElementsFromHTML(cls, html, encoding='utf-8'): ''' createElementsFromHTML - Creates elements from provided html, and returns a list of the root-level elements children of these root-level nodes are accessable via the usual means. @param html <str> - Some html d...
createBlocksFromHTML - Returns the root level node ( unless multiple nodes ) and a list of blocks added ( text and nodes ).
def createBlocksFromHTML(cls, html, encoding='utf-8'): ''' createBlocksFromHTML - Returns the root level node (unless multiple nodes), and a list of "blocks" added (text and nodes). @return list< str/AdvancedTag > - List of blocks created. May be strings (text nodes) or...
internal for parsing
def handle_starttag(self, tagName, attributeList, isSelfClosing=False): ''' internal for parsing ''' newTag = AdvancedHTMLParser.handle_starttag(self, tagName, attributeList, isSelfClosing) self._indexTag(newTag) return newTag
reindex - reindex the tree. Optionally change what fields are indexed.
def reindex(self, newIndexIDs=None, newIndexNames=None, newIndexClassNames=None, newIndexTagNames=None): ''' reindex - reindex the tree. Optionally, change what fields are indexed. @param newIndexIDs <bool/None> - None to leave same, otherwise new value to index IDs ...
disableIndexing - Disables indexing. Consider using plain AdvancedHTMLParser class. Maybe useful in some scenarios where you want to parse add a ton of elements then index and do a bunch of searching.
def disableIndexing(self): ''' disableIndexing - Disables indexing. Consider using plain AdvancedHTMLParser class. Maybe useful in some scenarios where you want to parse, add a ton of elements, then index and do a bunch of searching. ''' self.indexIDs = se...
addIndexOnAttribute - Add an index for an arbitrary attribute. This will be used by the getElementsByAttr function. You should do this prior to parsing or call reindex. Otherwise it will be blank. name and id will have no effect.
def addIndexOnAttribute(self, attributeName): ''' addIndexOnAttribute - Add an index for an arbitrary attribute. This will be used by the getElementsByAttr function. You should do this prior to parsing, or call reindex. Otherwise it will be blank. "name" and "id" will have no effect....
removeIndexOnAttribute - Remove an attribute from indexing ( for getElementsByAttr function ) and remove indexed data.
def removeIndexOnAttribute(self, attributeName): ''' removeIndexOnAttribute - Remove an attribute from indexing (for getElementsByAttr function) and remove indexed data. @param attributeName <lowercase str> - An attribute name. Will be lowercased. "name" and "id" will have no effect. ...
getElementsByTagName - Searches and returns all elements with a specific tag name.
def getElementsByTagName(self, tagName, root='root', useIndex=True): ''' getElementsByTagName - Searches and returns all elements with a specific tag name. @param tagName <lowercase str> - A lowercase string of the tag name. @param root <AdvancedTag/'...
getElementsByName - Searches and returns all elements with a specific name.
def getElementsByName(self, name, root='root', useIndex=True): ''' getElementsByName - Searches and returns all elements with a specific name. @param name <str> - A string of the name attribute @param root <AdvancedTag/'root'> - Search starting at a sp...
getElementById - Searches and returns the first ( should only be one ) element with the given ID.
def getElementById(self, _id, root='root', useIndex=True): ''' getElementById - Searches and returns the first (should only be one) element with the given ID. @param id <str> - A string of the id attribute. @param root <AdvancedTag/'root'> - Search sta...
getElementsByClassName - Searches and returns all elements containing a given class name.
def getElementsByClassName(self, className, root='root', useIndex=True): ''' getElementsByClassName - Searches and returns all elements containing a given class name. @param className <str> - A one-word class name @param root <AdvancedTag/'root'> - Sea...
getElementsByAttr - Searches the full tree for elements with a given attribute name and value combination. If you want multiple potential values see getElementsWithAttrValues If you want an index on a random attribute use the addIndexOnAttribute function.
def getElementsByAttr(self, attrName, attrValue, root='root', useIndex=True): ''' getElementsByAttr - Searches the full tree for elements with a given attribute name and value combination. If you want multiple potential values, see getElementsWithAttrValues If you want an index on a r...
getElementsWithAttrValues - Returns elements with an attribute matching one of several values. For a single name/ value combination see getElementsByAttr
def getElementsWithAttrValues(self, attrName, values, root='root', useIndex=True): ''' getElementsWithAttrValues - Returns elements with an attribute matching one of several values. For a single name/value combination, see getElementsByAttr @param attrName <lowercase str> - A lowerc...
uniqueTags - Returns the unique tags in tagList.
def uniqueTags(tagList): ''' uniqueTags - Returns the unique tags in tagList. @param tagList list<AdvancedTag> : A list of tag objects. ''' ret = [] alreadyAdded = set() for tag in tagList: myUid = tag.getUid() if myUid in alreadyAdded: contin...
toggleAttributesDOM - Toggle if the old DOM tag. attributes NamedNodeMap model should be used for the. attributes method versus
def toggleAttributesDOM(isEnabled): ''' toggleAttributesDOM - Toggle if the old DOM tag.attributes NamedNodeMap model should be used for the .attributes method, versus a more sane direct dict implementation. The DOM version is always accessable as AdvancedTag.attributesDOM ...
cloneNode - Clone this node ( tag name and attributes ). Does not clone children.
def cloneNode(self): ''' cloneNode - Clone this node (tag name and attributes). Does not clone children. Tags will be equal according to isTagEqual method, but will contain a different internal unique id such tag origTag != origTag.cloneNode() , as is the case in JS DOM. ...
appendText - append some inner text
def appendText(self, text): ''' appendText - append some inner text ''' # self.text is just raw string of the text self.text += text self.isSelfClosing = False # inner text means it can't self close anymo # self.blocks is either text or tags, in order of appea...
removeText - Removes the first occurace of given text in a text node ( i. e. not part of a tag )
def removeText(self, text): ''' removeText - Removes the first occurace of given text in a text node (i.e. not part of a tag) @param text <str> - text to remove @return text <str/None> - The text in that block (text node) after remove, or None if not found NOTE...
removeTextAll - Removes ALL occuraces of given text in a text node ( i. e. not part of a tag )
def removeTextAll(self, text): ''' removeTextAll - Removes ALL occuraces of given text in a text node (i.e. not part of a tag) @param text <str> - text to remove @return list <str> - All text node containing #text BEFORE the text was removed. Empty list if n...
remove - Will remove this node from its parent if it has a parent ( thus taking it out of the HTML tree )
def remove(self): ''' remove - Will remove this node from its parent, if it has a parent (thus taking it out of the HTML tree) NOTE: If you are using an IndexedAdvancedHTMLParser, calling this will NOT update the index. You MUST call reindex method manually. ...
removeBlock - Removes a list of blocks ( the first occurance of each ) from the direct children of this node.
def removeBlocks(self, blocks): ''' removeBlock - Removes a list of blocks (the first occurance of each) from the direct children of this node. @param blocks list<str/AdvancedTag> - List of AdvancedTags for tag nodes, else strings for text nodes @return The removed blocks ...
appendChild - Append a child to this element.
def appendChild(self, child): ''' appendChild - Append a child to this element. @param child <AdvancedTag> - Append a child element to this element ''' # Associate parentNode of #child to this tag child.parentNode = self # Associate owner document to ch...
append/ appendBlock - Append a block to this element. A block can be a string ( text node ) or an AdvancedTag ( tag node )
def appendBlock(self, block): ''' append / appendBlock - Append a block to this element. A block can be a string (text node), or an AdvancedTag (tag node) @param <str/AdvancedTag> - block to add @return - #block NOTE: To add multiple blocks, @see appendBlocks ...
appendBlocks - Append blocks to this element. A block can be a string ( text node ) or an AdvancedTag ( tag node )
def appendBlocks(self, blocks): ''' appendBlocks - Append blocks to this element. A block can be a string (text node), or an AdvancedTag (tag node) @param blocks list<str/AdvancedTag> - A list, in order to append, of blocks to add. @return - #blocks NOTE: To ad...
appendInnerHTML - Appends nodes from arbitrary HTML as if doing element. innerHTML + = someHTML in javascript.
def appendInnerHTML(self, html): ''' appendInnerHTML - Appends nodes from arbitrary HTML as if doing element.innerHTML += 'someHTML' in javascript. @param html <str> - Some HTML NOTE: If associated with a document ( AdvancedHTMLParser ), the html will use the encoding assoc...
removeChild - Remove a child tag if present.
def removeChild(self, child): ''' removeChild - Remove a child tag, if present. @param child <AdvancedTag> - The child to remove @return - The child [with parentNode cleared] if removed, otherwise None. NOTE: This removes a tag. If removing a text b...
removeChildren - Remove multiple child AdvancedTags.
def removeChildren(self, children): ''' removeChildren - Remove multiple child AdvancedTags. @see removeChild @return list<AdvancedTag/None> - A list of all tags removed in same order as passed. Item is "None" if it was not attached to this node, and thus wa...
removeBlock - Removes a single block ( text node or AdvancedTag ) which is a child of this object.
def removeBlock(self, block): ''' removeBlock - Removes a single block (text node or AdvancedTag) which is a child of this object. @param block <str/AdvancedTag> - The block (text node or AdvancedTag) to remove. @return Returns the removed block if one was remov...
insertBefore - Inserts a child before #beforeChild
def insertBefore(self, child, beforeChild): ''' insertBefore - Inserts a child before #beforeChild @param child <AdvancedTag/str> - Child block to insert @param beforeChild <AdvancedTag/str> - Child block to insert before. if None, will be appended @r...
insertAfter - Inserts a child after #afterChild
def insertAfter(self, child, afterChild): ''' insertAfter - Inserts a child after #afterChild @param child <AdvancedTag/str> - Child block to insert @param afterChild <AdvancedTag/str> - Child block to insert after. if None, will be appended @return -...
firstChild - property Get the first child block text or tag.
def firstChild(self): ''' firstChild - property, Get the first child block, text or tag. @return <str/AdvancedTag/None> - The first child block, or None if no child blocks ''' blocks = object.__getattribute__(self, 'blocks') # First block is empty string for ...
lastChild - property Get the last child block text or tag
def lastChild(self): ''' lastChild - property, Get the last child block, text or tag @return <str/AdvancedTag/None> - The last child block, or None if no child blocks ''' blocks = object.__getattribute__(self, 'blocks') # First block is empty string for inden...
nextSibling - Returns the next sibling. This is the child following this node in the parent s list of children.
def nextSibling(self): ''' nextSibling - Returns the next sibling. This is the child following this node in the parent's list of children. This could be text or an element. use nextSiblingElement to ensure element @return <None/str/AdvancedTag> - None if there a...
nextElementSibling - Returns the next sibling that is an element. This is the tag node following this node in the parent s list of children
def nextElementSibling(self): ''' nextElementSibling - Returns the next sibling that is an element. This is the tag node following this node in the parent's list of children @return <None/AdvancedTag> - None if there are no children (tag) in the parent after this nod...
previousSibling - Returns the previous sibling. This would be the previous node ( text or tag ) in the parent s list This could be text or an element. use previousSiblingElement to ensure element
def previousSibling(self): ''' previousSibling - Returns the previous sibling. This would be the previous node (text or tag) in the parent's list This could be text or an element. use previousSiblingElement to ensure element @return <None/str/AdvancedTa...
previousElementSibling - Returns the previous sibling that is an element.
def previousElementSibling(self): ''' previousElementSibling - Returns the previous sibling that is an element. This is the previous tag node in the parent's list of children @return <None/AdvancedTag> - None if there are no children (tag...
tagBlocks - Property. Returns all the blocks which are direct children of this node where that block is a tag ( not text )
def tagBlocks(self): ''' tagBlocks - Property. Returns all the blocks which are direct children of this node, where that block is a tag (not text) NOTE: This is similar to .children , and you should probably use .children instead except within this class its...
getBlocksTags - Returns a list of tuples referencing the blocks which are direct children of this node and the block is an AdvancedTag.
def getBlocksTags(self): ''' getBlocksTags - Returns a list of tuples referencing the blocks which are direct children of this node, and the block is an AdvancedTag. The tuples are ( block, blockIdx ) where "blockIdx" is the index of self.blocks wherein the tag resides. ...
textBlocks - Property. Returns all the blocks which are direct children of this node where that block is a text ( not a tag )
def textBlocks(self): ''' textBlocks - Property. Returns all the blocks which are direct children of this node, where that block is a text (not a tag) @return list<AdvancedTag> - A list of direct children which are text. ''' myBlocks = self.b...
textContent - property gets the text of this node and all inner nodes.
def textContent(self): ''' textContent - property, gets the text of this node and all inner nodes. Use .innerText for just this node's text @return <str> - The text of all nodes at this level or lower ''' def _collateText(curNode): ''' ...
containsUid - Check if the uid ( unique internal ID ) appears anywhere as a direct child to this node or the node itself.
def containsUid(self, uid): ''' containsUid - Check if the uid (unique internal ID) appears anywhere as a direct child to this node, or the node itself. @param uid <uuid.UUID> - uuid to check @return <bool> - True if #uid is this node's uid, or is the uid of any childre...
getAllChildNodes - Gets all the children and their children and their children and so on all the way to the end as a TagCollection. Use. childNodes for a regular list
def getAllChildNodes(self): ''' getAllChildNodes - Gets all the children, and their children, and their children, and so on, all the way to the end as a TagCollection. Use .childNodes for a regular list @return TagCollection<AdvancedTag> - ...
getAllChildNodeUids - Returns all the unique internal IDs for all children and there children so on and so forth until the end.
def getAllChildNodeUids(self): ''' getAllChildNodeUids - Returns all the unique internal IDs for all children, and there children, so on and so forth until the end. For performing "contains node" kind of logic, this is more efficent than copying the entire nodeset ...
getAllNodeUids - Returns all the unique internal IDs from getAllChildNodeUids but also includes this tag s uid
def getAllNodeUids(self): ''' getAllNodeUids - Returns all the unique internal IDs from getAllChildNodeUids, but also includes this tag's uid @return set<uuid.UUID> A set of uuid objects ''' # Start with a set including this tag's uuid ret = { self.uid } ...
getPeers - Get elements who share a parent with this element
def getPeers(self): ''' getPeers - Get elements who share a parent with this element @return - TagCollection of elements ''' parentNode = self.parentNode # If no parent, no peers if not parentNode: return None peers = parentNode.child...
getStartTag - Returns the start tag represented as HTML
def getStartTag(self): ''' getStartTag - Returns the start tag represented as HTML @return - String of start tag with attributes ''' attributeStrings = [] # Get all attributes as a tuple (name<str>, value<str>) for name, val in self._attributes.items(): ...
getEndTag - returns the end tag representation as HTML string
def getEndTag(self): ''' getEndTag - returns the end tag representation as HTML string @return - String of end tag ''' # If this is a self-closing tag, we have no end tag (opens and closes in the start) if self.isSelfClosing is True: return '' ...
innerHTML - Returns an HTML string of the inner contents of this tag including children.
def innerHTML(self): ''' innerHTML - Returns an HTML string of the inner contents of this tag, including children. @return - String of inner contents HTML ''' # If a self-closing tag, there are no contents if self.isSelfClosing is True: return '' ...
getAttribute - Gets an attribute on this tag. Be wary using this for classname maybe use addClass/ removeClass. Attribute names are all lowercase.
def getAttribute(self, attrName, defaultValue=None): ''' getAttribute - Gets an attribute on this tag. Be wary using this for classname, maybe use addClass/removeClass. Attribute names are all lowercase. @return - The attribute value, or None if none exists. ''' if a...
getAttributesList - Get a copy of all attributes as a list of tuples ( name value )
def getAttributesList(self): ''' getAttributesList - Get a copy of all attributes as a list of tuples (name, value) ALL values are converted to string and copied, so modifications will not affect the original attributes. If you want types like "style" to work as before...
getAttributesDict - Get a copy of all attributes as a dict map of name - > value
def getAttributesDict(self): ''' getAttributesDict - Get a copy of all attributes as a dict map of name -> value ALL values are converted to string and copied, so modifications will not affect the original attributes. If you want types like "style" to work as before, y...
hasAttribute - Checks for the existance of an attribute. Attribute names are all lowercase.
def hasAttribute(self, attrName): ''' hasAttribute - Checks for the existance of an attribute. Attribute names are all lowercase. @param attrName <str> - The attribute name @return <bool> - True or False if attribute exists by that name ''...
removeAttribute - Removes an attribute by name. @param attrName <str > - The attribute name
def removeAttribute(self, attrName): ''' removeAttribute - Removes an attribute, by name. @param attrName <str> - The attribute name ''' attrName = attrName.lower() # Delete provided attribute name ( #attrName ) from attributes map try: ...
addClass - append a class name to the end of the class attribute if not present
def addClass(self, className): ''' addClass - append a class name to the end of the "class" attribute, if not present @param className <str> - The name of the class to add ''' className = stripWordsOnly(className) if not className: return None ...
removeClass - remove a class name if present. Returns the class name if removed otherwise None.
def removeClass(self, className): ''' removeClass - remove a class name if present. Returns the class name if removed, otherwise None. @param className <str> - The name of the class to remove @return <str> - The class name removed if one was removed, otherwise None...