<s> """<STR_LIT>""" <EOL> import re <EOL> import types <EOL> import os <EOL> import inspect <EOL> import sys <EOL> import textwrap <EOL> import time <EOL> import traceback <EOL> from operator import itemgetter <EOL> import maya . cmds as cmds <EOL> import maya . mel as mm <EOL> import pymel . api as api <EOL> import pymel . util as util <EOL> from pymel . util . conditions import Always , Condition <EOL> import pymel . versions as versions <EOL> from . import apicache <EOL> from . import cmdcache <EOL> from . import plogging <EOL> from . import pmcmds <EOL> _logger = plogging . getLogger ( __name__ ) <EOL> apiTypesToApiEnums = None <EOL> apiEnumsToApiTypes = None <EOL> mayaTypesToApiTypes = None <EOL> apiTypesToApiClasses = None <EOL> apiClassInfo = None <EOL> mayaTypesToApiEnums = None <EOL> apiToMelData = None <EOL> apiClassOverrides = None <EOL> cmdlist = None <EOL> nodeHierarchy = None <EOL> uiClassList = None <EOL> nodeCommandList = None <EOL> moduleCmds = None <EOL> def loadApiCache ( ) : <EOL> _logger . debug ( "<STR_LIT>" ) <EOL> _start = time . time ( ) <EOL> global _apiCacheInst <EOL> global _apiMelBridgeCacheInst <EOL> _apiCacheInst = apicache . ApiCache ( ) <EOL> _apiCacheInst . build ( ) <EOL> _apiMelBridgeCacheInst = apicache . ApiMelBridgeCache ( ) <EOL> _apiMelBridgeCacheInst . build ( ) <EOL> _setApiCacheGlobals ( ) <EOL> _elapsed = time . time ( ) - _start <EOL> _logger . debug ( "<STR_LIT>" % _elapsed ) <EOL> def _setApiCacheGlobals ( ) : <EOL> global _apiCacheInst <EOL> global _apiMelBridgeCacheInst <EOL> for names , values in [ ( _apiCacheInst . cacheNames ( ) , <EOL> _apiCacheInst . contents ( ) ) , <EOL> ( _apiMelBridgeCacheInst . cacheNames ( ) , <EOL> _apiMelBridgeCacheInst . contents ( ) ) , <EOL> ( _apiCacheInst . EXTRA_GLOBAL_NAMES , <EOL> _apiCacheInst . extraDicts ( ) ) ] : <EOL> for name , val in zip ( names , values ) : <EOL> globals ( ) [ name ] = val <EOL> def loadCmdCache ( ) : <EOL> _logger . debug ( "<STR_LIT>" ) <EOL> _start = time . time ( ) <EOL> global _cmdCacheInst <EOL> global cmdlist , nodeHierarchy , uiClassList , nodeCommandList , moduleCmds <EOL> _cmdCacheInst = cmdcache . CmdCache ( ) <EOL> _cmdCacheInst . build ( ) <EOL> _setCmdCacheGlobals ( ) <EOL> _elapsed = time . time ( ) - _start <EOL> _logger . debug ( "<STR_LIT>" % _elapsed ) <EOL> def _setCmdCacheGlobals ( ) : <EOL> global _cmdCacheInst <EOL> for name , val in zip ( _cmdCacheInst . cacheNames ( ) , _cmdCacheInst . contents ( ) ) : <EOL> globals ( ) [ name ] = val <EOL> def saveApiCache ( ) : <EOL> global _apiCacheInst <EOL> _apiCacheInst . save ( globals ( ) ) <EOL> def saveApiMelBridgeCache ( ) : <EOL> global _apiMelBridgeCacheInst <EOL> _apiMelBridgeCacheInst . save ( globals ( ) ) <EOL> def mergeApiClassOverrides ( ) : <EOL> global _apiCacheInst <EOL> global _apiMelBridgeCacheInst <EOL> _apiCacheInst . update ( globals ( ) ) <EOL> _apiMelBridgeCacheInst . update ( globals ( ) ) <EOL> _apiCacheInst . _mergeClassOverrides ( _apiMelBridgeCacheInst ) <EOL> _setApiCacheGlobals ( ) <EOL> loadApiCache ( ) <EOL> loadCmdCache ( ) <EOL> DOC_WIDTH = <NUM_LIT> <EOL> EXCLUDE_METHODS = [ '<STR_LIT:type>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' ] <EOL> includeDocExamples = bool ( os . environ . get ( '<STR_LIT>' , False ) ) <EOL> pyNodeNamesToPyNodes = { } <EOL> apiClassNamesToPyNodeNames = { } <EOL> apiEnumsToPyComponents = { } <EOL> pyNodeTypesHierarchy = { } <EOL> nodeTypeToInfoCommand = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def toPyNode ( res ) : <EOL> "<STR_LIT>" <EOL> if res is not None and res != '<STR_LIT>' : <EOL> import pymel . core . general <EOL> return pymel . core . general . PyNode ( res ) <EOL> def unwrapToPyNode ( res ) : <EOL> "<STR_LIT>" <EOL> if res is not None and res [ <NUM_LIT:0> ] : <EOL> import pymel . core . general <EOL> return pymel . core . general . PyNode ( res [ <NUM_LIT:0> ] ) <EOL> def toPyUI ( res ) : <EOL> "<STR_LIT>" <EOL> if res is not None : <EOL> import pymel . core . uitypes <EOL> return pymel . core . uitypes . PyUI ( res ) <EOL> def toPyType ( moduleName , objectName ) : <EOL> """<STR_LIT>""" <EOL> def toGivenClass ( res ) : <EOL> module = __import__ ( moduleName , globals ( ) , locals ( ) , [ objectName ] , - <NUM_LIT:1> ) <EOL> cls = getattr ( module , objectName ) <EOL> if res is not None : <EOL> return cls ( res ) <EOL> toGivenClass . __name__ = '<STR_LIT>' % util . capitalize ( objectName ) <EOL> toGivenClass . __doc__ = "<STR_LIT>" % objectName <EOL> return toGivenClass <EOL> def toPyNodeList ( res ) : <EOL> "<STR_LIT>" <EOL> if res is None : <EOL> return [ ] <EOL> import pymel . core . general <EOL> return [ pymel . core . general . PyNode ( x ) for x in res ] <EOL> def splitToPyNodeList ( res ) : <EOL> "<STR_LIT>" <EOL> return toPyNodeList ( res . split ( ) ) <EOL> def toPyUIList ( res ) : <EOL> "<STR_LIT>" <EOL> if res is None : <EOL> return [ ] <EOL> import pymel . core . uitypes <EOL> return [ pymel . core . uitypes . PyUI ( x ) for x in res ] <EOL> def toPyTypeList ( moduleName , objectName ) : <EOL> """<STR_LIT>""" <EOL> def toGivenClassList ( res ) : <EOL> module = __import__ ( moduleName , globals ( ) , locals ( ) , [ objectName ] , - <NUM_LIT:1> ) <EOL> cls = getattr ( module , objectName ) <EOL> if res is None : <EOL> return [ ] <EOL> return [ cls ( x ) for x in res ] <EOL> toGivenClassList . __name__ = '<STR_LIT>' % util . capitalize ( objectName ) <EOL> toGivenClassList . __doc__ = "<STR_LIT>" % objectName <EOL> return toGivenClassList <EOL> def raiseError ( typ , * args ) : <EOL> def f ( res ) : <EOL> raise typ ( * args ) <EOL> return f <EOL> class Flag ( Condition ) : <EOL> def __init__ ( self , longName , shortName , truthValue = True ) : <EOL> """<STR_LIT>""" <EOL> self . shortName = shortName <EOL> self . longName = longName <EOL> self . truthValue = truthValue <EOL> def eval ( self , kwargs ) : <EOL> for arg in ( self . shortName , self . longName ) : <EOL> if arg in kwargs : <EOL> if self . truthValue is None or bool ( kwargs [ arg ] ) == self . truthValue : <EOL> return True <EOL> return False <EOL> def __str__ ( self ) : <EOL> return self . longName <EOL> simpleCommandWraps = { <EOL> '<STR_LIT>' : [ ( toPyNode , Always ) ] , <EOL> '<STR_LIT>' : [ ( toPyNode , Always ) ] , <EOL> '<STR_LIT>' : [ ( toPyNode , Always ) ] , <EOL> '<STR_LIT>' : [ ( util . listForNone , Always ) ] , <EOL> '<STR_LIT>' : [ ( toPyNodeList , Always ) ] , <EOL> '<STR_LIT>' : [ ( toPyType ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:c>' , None ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( toPyTypeList ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ~ Flag ( '<STR_LIT>' , '<STR_LIT:to>' , None ) ) <EOL> ] , <EOL> '<STR_LIT>' : [ ( util . listForNone , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> ( Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> ] , <EOL> '<STR_LIT>' : [ ( util . listForNone , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> ( Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> ] , <EOL> '<STR_LIT>' : [ ( util . listForNone , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> ( Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> ] , <EOL> '<STR_LIT>' : [ ( toPyNode , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ] , <EOL> '<STR_LIT>' : [ ( toPyNode , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( toPyNodeList , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ] , <EOL> '<STR_LIT>' : [ ( toPyNodeList , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> ( Flag ( '<STR_LIT>' , '<STR_LIT:g>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) ) , <EOL> ] , <EOL> '<STR_LIT>' : [ ( toPyNodeList , Always ) ] , <EOL> '<STR_LIT>' : [ ( toPyNodeList , Always ) ] , <EOL> '<STR_LIT>' : [ ( toPyNode , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> ( Flag ( '<STR_LIT:root>' , '<STR_LIT:r>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:p>' ) ) ) , <EOL> ( toPyNodeList , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> ( Flag ( '<STR_LIT>' , '<STR_LIT:c>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:p>' ) ) ) <EOL> ] , <EOL> '<STR_LIT>' : [ ( lambda res : toPyNode ( res . strip ( ) ) , Always ) ] , <EOL> '<STR_LIT>' : [ ( toPyNode , Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) ] , <EOL> '<STR_LIT>' : [ ( splitToPyNodeList , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> ( Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> ] , <EOL> '<STR_LIT>' : [ ( splitToPyNodeList , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ] , <EOL> '<STR_LIT>' : [ ( toPyNodeList , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> ( Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) ) , <EOL> ( toPyNode , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> ( Flag ( '<STR_LIT>' , '<STR_LIT>' ) | <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:a>' ) ) ) , <EOL> ( lambda res : [ ( toPyNode ( res [ i ] ) , res [ i + <NUM_LIT:1> ] ) for i in range ( <NUM_LIT:0> , len ( res ) , <NUM_LIT:2> ) ] , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) & ~ ( Flag ( '<STR_LIT>' , '<STR_LIT>' ) | Flag ( '<STR_LIT>' , '<STR_LIT>' ) | Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) ) , <EOL> ( raiseError ( ValueError , '<STR_LIT>' ) , <EOL> Flag ( '<STR_LIT>' , '<STR_LIT:q>' ) & <EOL> Flag ( '<STR_LIT>' , '<STR_LIT>' ) & ~ ( Flag ( '<STR_LIT>' , '<STR_LIT>' ) | Flag ( '<STR_LIT>' , '<STR_LIT>' ) | Flag ( '<STR_LIT>' , '<STR_LIT>' ) ) ) , <EOL> ] , <EOL> } <EOL> if includeDocExamples : <EOL> examples = cmdcache . CmdProcessedExamplesCache ( ) . read ( ) <EOL> for cmd , example in examples . iteritems ( ) : <EOL> try : <EOL> cmdlist [ cmd ] [ '<STR_LIT>' ] = example <EOL> except KeyError : <EOL> print "<STR_LIT>" , cmd <EOL> pass <EOL> classToMelMap = util . defaultdict ( list ) <EOL> def _getApiOverrideNameAndData ( classname , pymelName ) : <EOL> if apiToMelData . has_key ( ( classname , pymelName ) ) : <EOL> data = apiToMelData [ ( classname , pymelName ) ] <EOL> try : <EOL> nameType = data [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> nameType = '<STR_LIT>' <EOL> if nameType == '<STR_LIT>' : <EOL> pass <EOL> elif nameType == '<STR_LIT>' : <EOL> pymelName = data [ '<STR_LIT>' ] <EOL> else : <EOL> pymelName = nameType <EOL> else : <EOL> data = { '<STR_LIT>' : pymelName not in EXCLUDE_METHODS } <EOL> apiToMelData [ ( classname , pymelName ) ] = data <EOL> return pymelName , data <EOL> def getUncachedCmds ( ) : <EOL> return list ( set ( map ( itemgetter ( <NUM_LIT:0> ) , inspect . getmembers ( cmds , callable ) ) ) . difference ( cmdlist . keys ( ) ) ) <EOL> docCacheLoaded = False <EOL> def loadCmdDocCache ( ) : <EOL> global docCacheLoaded <EOL> if docCacheLoaded : <EOL> return <EOL> data = cmdcache . CmdDocsCache ( ) . read ( ) <EOL> util . mergeCascadingDicts ( data , cmdlist ) <EOL> docCacheLoaded = True <EOL> def _addCmdDocs ( func , cmdName ) : <EOL> if cmdlist [ cmdName ] [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> return func <EOL> if func . __doc__ : <EOL> docstring = func . __doc__ + '<STR_LIT>' <EOL> else : <EOL> docstring = '<STR_LIT>' <EOL> util . addLazyDocString ( func , addCmdDocsCallback , cmdName , docstring ) <EOL> return func <EOL> def addCmdDocsCallback ( cmdName , docstring = '<STR_LIT>' ) : <EOL> loadCmdDocCache ( ) <EOL> cmdInfo = cmdlist [ cmdName ] <EOL> docstring = '<STR_LIT:\n>' . join ( textwrap . wrap ( cmdInfo [ '<STR_LIT:description>' ] , DOC_WIDTH ) ) + '<STR_LIT>' + docstring . strip ( ) <EOL> docstring = docstring . rstrip ( ) + '<STR_LIT>' <EOL> flagDocs = cmdInfo [ '<STR_LIT>' ] <EOL> if flagDocs and sorted ( flagDocs . keys ( ) ) != [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> widths = [ <NUM_LIT:3> , <NUM_LIT:100> , <NUM_LIT:32> , <NUM_LIT:32> ] <EOL> altwidths = [ widths [ <NUM_LIT:0> ] + widths [ <NUM_LIT:1> ] ] + widths [ <NUM_LIT:2> : ] <EOL> rowsep = '<STR_LIT>' + '<STR_LIT:+>' . join ( [ '<STR_LIT:->' * ( w - <NUM_LIT:1> ) for w in widths ] ) + '<STR_LIT>' <EOL> headersep = '<STR_LIT>' + '<STR_LIT:+>' . join ( [ '<STR_LIT:=>' * ( w - <NUM_LIT:1> ) for w in widths ] ) + '<STR_LIT>' <EOL> def makerow ( items , widths ) : <EOL> return '<STR_LIT>' + '<STR_LIT:|>' . join ( '<STR_LIT:U+0020>' + i . ljust ( w - <NUM_LIT:2> ) for i , w in zip ( items , widths ) ) + '<STR_LIT>' <EOL> docstring += '<STR_LIT>' <EOL> if includeDocExamples : <EOL> docstring += rowsep <EOL> docstring += makerow ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , altwidths ) <EOL> docstring += headersep <EOL> for flag in sorted ( flagDocs . keys ( ) ) : <EOL> if flag in [ '<STR_LIT>' , '<STR_LIT>' ] : continue <EOL> docs = flagDocs [ flag ] <EOL> try : <EOL> typ = docs [ '<STR_LIT:args>' ] <EOL> except KeyError , e : <EOL> raise KeyError ( "<STR_LIT>" % ( cmdName , flag , e ) ) <EOL> if isinstance ( typ , list ) : <EOL> try : <EOL> typ = [ x . __name__ for x in typ ] <EOL> except : <EOL> typ = [ str ( x ) for x in typ ] <EOL> typ = '<STR_LIT:U+002CU+0020>' . join ( typ ) <EOL> else : <EOL> try : <EOL> typ = typ . __name__ <EOL> except : pass <EOL> descr = docs . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> tmpmodes = docs . get ( '<STR_LIT>' , [ ] ) <EOL> modes = [ ] <EOL> if '<STR_LIT>' in tmpmodes : modes . append ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in tmpmodes : modes . append ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in tmpmodes : modes . append ( '<STR_LIT>' ) <EOL> if includeDocExamples : <EOL> for data in util . izip_longest ( [ '<STR_LIT>' % ( flag , docs [ '<STR_LIT>' ] ) ] , <EOL> textwrap . wrap ( '<STR_LIT>' % typ , widths [ <NUM_LIT:2> ] - <NUM_LIT:2> ) , <EOL> [ '<STR_LIT>' % m for m in modes ] , <EOL> fillvalue = '<STR_LIT>' ) : <EOL> docstring += makerow ( data , altwidths ) <EOL> docstring += rowsep <EOL> descr_widths = [ widths [ <NUM_LIT:0> ] , sum ( widths [ <NUM_LIT:1> : ] ) ] <EOL> if descr : <EOL> for line in textwrap . wrap ( descr . strip ( '<STR_LIT:|>' ) , sum ( widths [ <NUM_LIT:1> : ] ) - <NUM_LIT:2> ) : <EOL> docstring += makerow ( [ '<STR_LIT>' , line ] , descr_widths ) <EOL> docstring += makerow ( [ '<STR_LIT>' , '<STR_LIT>' ] , descr_widths ) <EOL> else : <EOL> docstring += makerow ( [ '<STR_LIT>' , '<STR_LIT>' ] , descr_widths ) <EOL> docstring += rowsep <EOL> else : <EOL> descr = '<STR_LIT:\n>' . join ( [ '<STR_LIT:U+0020>' + x for x in textwrap . wrap ( descr , DOC_WIDTH ) ] ) <EOL> descr = descr + '<STR_LIT:\n>' if descr else '<STR_LIT>' <EOL> docstring += '<STR_LIT>' % ( <EOL> ( flag + '<STR_LIT>' + docs [ '<STR_LIT>' ] ) . ljust ( <NUM_LIT:30> ) , <EOL> ( '<STR_LIT:(>' + typ + '<STR_LIT:)>' ) . ljust ( <NUM_LIT:15> ) , <EOL> '<STR_LIT:U+002C>' . join ( modes ) , <EOL> descr ) <EOL> docstring += '<STR_LIT>' % ( cmdName ) <EOL> if includeDocExamples and cmdInfo . get ( '<STR_LIT>' , None ) : <EOL> docstring += '<STR_LIT>' + cmdInfo [ '<STR_LIT>' ] <EOL> return docstring <EOL> def _addFlagCmdDocs ( func , cmdName , flag , docstring = '<STR_LIT>' ) : <EOL> util . addLazyDocString ( func , addFlagCmdDocsCallback , cmdName , flag , docstring ) <EOL> return func <EOL> def addFlagCmdDocsCallback ( cmdName , flag , docstring ) : <EOL> loadCmdDocCache ( ) <EOL> allFlagInfo = cmdlist [ cmdName ] [ '<STR_LIT>' ] <EOL> try : <EOL> flagInfo = allFlagInfo [ flag ] <EOL> except KeyError : <EOL> _logger . warn ( '<STR_LIT>' % flag ) <EOL> else : <EOL> if docstring : <EOL> docstring += '<STR_LIT>' <EOL> newdocs = flagInfo . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if newdocs : <EOL> docstring += newdocs + '<STR_LIT>' <EOL> if '<STR_LIT>' in flagInfo : <EOL> docstring += '<STR_LIT>' <EOL> for secondaryFlag in flagInfo [ '<STR_LIT>' ] : <EOL> flagdoc = allFlagInfo [ secondaryFlag ] [ '<STR_LIT>' ] <EOL> docstring += '<STR_LIT>' % ( secondaryFlag , <EOL> '<STR_LIT:\n>' . join ( [ '<STR_LIT:U+0020>' + x for x in textwrap . wrap ( flagdoc , DOC_WIDTH ) ] ) ) <EOL> docstring += '<STR_LIT>' % ( cmdName ) <EOL> return docstring <EOL> def _getTimeRangeFlags ( cmdName ) : <EOL> """<STR_LIT>""" <EOL> commandFlags = [ ] <EOL> try : <EOL> flagDocs = cmdlist [ cmdName ] [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> for flag , data in flagDocs . items ( ) : <EOL> if data [ '<STR_LIT:args>' ] == '<STR_LIT>' : <EOL> commandFlags += [ flag , data [ '<STR_LIT>' ] ] <EOL> return commandFlags <EOL> class Callback ( object ) : <EOL> """<STR_LIT>""" <EOL> MAX_RECENT_ERRORS = <NUM_LIT:10> <EOL> recentErrors = [ ] <EOL> CallbackErrorLog = util . namedtuple ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ classmethod <EOL> def logCallbackError ( cls , callback , exception = None , trace = None , <EOL> creationTrace = None ) : <EOL> if exception is None : <EOL> exception = sys . exc_value <EOL> if trace is None : <EOL> trace = traceback . format_exc ( ) <EOL> if creationTrace is None : <EOL> if isinstance ( callback , Callback ) : <EOL> creationTrace = '<STR_LIT>' . join ( callback . traceback ) <EOL> else : <EOL> creationTrace = '<STR_LIT>' <EOL> cls . recentErrors . insert ( <NUM_LIT:0> , cls . CallbackErrorLog ( callback , exception , <EOL> trace , creationTrace ) ) <EOL> if len ( cls . recentErrors ) > cls . MAX_RECENT_ERRORS : <EOL> del cls . recentErrors [ cls . MAX_RECENT_ERRORS : ] <EOL> @ classmethod <EOL> def formatRecentError ( cls , index = <NUM_LIT:0> ) : <EOL> info = cls . recentErrors [ index ] <EOL> msg = '''<STR_LIT>''' % ( info . callback , info . creationTrace , info . trace ) <EOL> return msg <EOL> @ classmethod <EOL> def printRecentError ( cls , index = <NUM_LIT:0> ) : <EOL> print cls . formatRecentError ( index = index ) <EOL> def __init__ ( self , func , * args , ** kwargs ) : <EOL> self . func = func <EOL> self . args = args <EOL> self . kwargs = kwargs <EOL> self . traceback = traceback . format_stack ( ) <EOL> def __call__ ( self , * args ) : <EOL> cmds . undoInfo ( openChunk = <NUM_LIT:1> ) <EOL> try : <EOL> try : <EOL> return self . func ( * self . args , ** self . kwargs ) <EOL> except Exception , e : <EOL> self . logCallbackError ( self ) <EOL> raise <EOL> finally : <EOL> cmds . undoInfo ( closeChunk = <NUM_LIT:1> ) <EOL> class CallbackWithArgs ( Callback ) : <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> kwargsFinal = self . kwargs . copy ( ) <EOL> kwargsFinal . update ( kwargs ) <EOL> cmds . undoInfo ( openChunk = <NUM_LIT:1> ) <EOL> try : <EOL> try : <EOL> return self . func ( * self . args + args , ** kwargsFinal ) <EOL> except Exception , e : <EOL> self . logCallbackError ( self ) <EOL> raise <EOL> finally : <EOL> cmds . undoInfo ( closeChunk = <NUM_LIT:1> ) <EOL> def fixCallbacks ( inFunc , commandFlags , funcName = None ) : <EOL> """<STR_LIT>""" <EOL> if not funcName : <EOL> funcName = pmcmds . getCmdName ( inFunc ) <EOL> if not commandFlags : <EOL> return inFunc <EOL> argCorrector = None <EOL> if versions . current ( ) < versions . v2011 : <EOL> if funcName . startswith ( '<STR_LIT:float>' ) : <EOL> argCorrector = float <EOL> elif funcName . startswith ( '<STR_LIT:int>' ) : <EOL> argCorrector = int <EOL> elif funcName . startswith ( '<STR_LIT>' ) or funcName . startswith ( '<STR_LIT>' ) : <EOL> argCorrector = lambda x : x == '<STR_LIT:true>' <EOL> beforeUiFunc = inFunc <EOL> def _makeCallback ( origCallback , args , doPassSelf ) : <EOL> """<STR_LIT>""" <EOL> creationTraceback = '<STR_LIT>' . join ( traceback . format_stack ( ) ) <EOL> def callback ( * cb_args ) : <EOL> if argCorrector : <EOL> newargs = [ argCorrector ( arg ) for arg in cb_args ] <EOL> else : <EOL> newargs = list ( cb_args ) <EOL> if doPassSelf : <EOL> newargs = [ args [ <NUM_LIT:0> ] ] + newargs <EOL> newargs = tuple ( newargs ) <EOL> try : <EOL> res = origCallback ( * newargs ) <EOL> except Exception , e : <EOL> if not isinstance ( origCallback , Callback ) : <EOL> Callback . logCallbackError ( origCallback , <EOL> creationTrace = creationTraceback ) <EOL> raise <EOL> if isinstance ( res , util . ProxyUnicode ) : <EOL> res = unicode ( res ) <EOL> return res <EOL> return callback <EOL> def newUiFunc ( * args , ** kwargs ) : <EOL> if len ( args ) : <EOL> doPassSelf = kwargs . pop ( '<STR_LIT>' , False ) <EOL> else : <EOL> doPassSelf = False <EOL> for key in commandFlags : <EOL> try : <EOL> cb = kwargs [ key ] <EOL> if callable ( cb ) : <EOL> kwargs [ key ] = _makeCallback ( cb , args , doPassSelf ) <EOL> except KeyError : pass <EOL> return beforeUiFunc ( * args , ** kwargs ) <EOL> newUiFunc . __name__ = funcName <EOL> newUiFunc . __module__ = inFunc . __module__ <EOL> newUiFunc . __doc__ = inFunc . __doc__ <EOL> return newUiFunc <EOL> def functionFactory ( funcNameOrObject , returnFunc = None , module = None , rename = None , uiWidget = False ) : <EOL> """<STR_LIT>""" <EOL> inFunc = None <EOL> if isinstance ( funcNameOrObject , basestring ) : <EOL> funcName = funcNameOrObject <EOL> if module and module != cmds : <EOL> try : <EOL> inFunc = getattr ( module , funcName ) <EOL> customFunc = True <EOL> except AttributeError : <EOL> pass <EOL> if not inFunc : <EOL> try : <EOL> inFunc = getattr ( pmcmds , funcName ) <EOL> customFunc = False <EOL> except AttributeError : <EOL> return <EOL> else : <EOL> funcName = pmcmds . getCmdName ( funcNameOrObject ) <EOL> inFunc = funcNameOrObject <EOL> customFunc = True <EOL> if not callable ( inFunc ) : <EOL> _logger . warn ( '<STR_LIT>' % funcNameOrObject ) <EOL> return <EOL> cmdInfo = cmdlist [ funcName ] <EOL> funcType = type ( inFunc ) <EOL> funcName = str ( funcName ) <EOL> if funcType == types . BuiltinFunctionType : <EOL> try : <EOL> newFuncName = inFunc . __name__ <EOL> if funcName != newFuncName : <EOL> _logger . warn ( "<STR_LIT>" % ( inFunc . __module__ , funcName , newFuncName , funcType == types . FunctionType and returnFunc is None ) ) <EOL> except AttributeError : <EOL> _logger . warn ( "<STR_LIT>" % inFunc ) <EOL> timeRangeFlags = _getTimeRangeFlags ( funcName ) <EOL> newFunc = inFunc <EOL> if returnFunc or timeRangeFlags : <EOL> beforeReturnFunc = newFunc <EOL> def newFuncWithReturnFunc ( * args , ** kwargs ) : <EOL> for flag in timeRangeFlags : <EOL> try : <EOL> val = kwargs [ flag ] <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> if isinstance ( val , slice ) : <EOL> val = [ val . start , val . stop ] <EOL> elif isinstance ( val , basestring ) and val . count ( '<STR_LIT::>' ) == <NUM_LIT:1> : <EOL> val = val . split ( '<STR_LIT::>' ) <EOL> for i , v in enumerate ( val ) : <EOL> if not v . strip ( ) : <EOL> val [ i ] = None <EOL> elif isinstance ( val , int ) : <EOL> val = ( val , val ) <EOL> if isinstance ( val , ( tuple , list ) ) : <EOL> val = list ( val ) <EOL> if len ( val ) == <NUM_LIT:2> : <EOL> if val [ <NUM_LIT:0> ] is None : <EOL> val [ <NUM_LIT:0> ] = cmds . findKeyframe ( which = '<STR_LIT>' ) <EOL> if val [ <NUM_LIT:1> ] is None : <EOL> val [ <NUM_LIT:1> ] = cmds . findKeyframe ( which = '<STR_LIT>' ) <EOL> elif len ( val ) == <NUM_LIT:1> : <EOL> val . append ( cmds . findKeyframe ( which = '<STR_LIT>' ) ) <EOL> kwargs [ flag ] = tuple ( val ) <EOL> res = beforeReturnFunc ( * args , ** kwargs ) <EOL> if not kwargs . get ( '<STR_LIT>' , kwargs . get ( '<STR_LIT:q>' , False ) ) : <EOL> if isinstance ( res , list ) : <EOL> if cmdInfo . get ( '<STR_LIT>' , False ) : <EOL> res = returnFunc ( res [ <NUM_LIT:0> ] ) <EOL> else : <EOL> try : <EOL> res = map ( returnFunc , res ) <EOL> except : pass <EOL> elif res : <EOL> try : <EOL> res = returnFunc ( res ) <EOL> except Exception , e : <EOL> pass <EOL> return res <EOL> newFunc = newFuncWithReturnFunc <EOL> if funcName in simpleCommandWraps : <EOL> wraps = simpleCommandWraps [ funcName ] <EOL> beforeSimpleWrap = newFunc <EOL> def simpleWrapFunc ( * args , ** kwargs ) : <EOL> res = beforeSimpleWrap ( * args , ** kwargs ) <EOL> for func , wrapCondition in wraps : <EOL> if wrapCondition . eval ( kwargs ) : <EOL> res = func ( res ) <EOL> break <EOL> return res <EOL> newFunc = simpleWrapFunc <EOL> doc = '<STR_LIT>' <EOL> for func , wrapCondition in wraps : <EOL> if wrapCondition != Always : <EOL> flags = '<STR_LIT>' + str ( wrapCondition ) <EOL> elif len ( wraps ) > <NUM_LIT:1> : <EOL> flags = '<STR_LIT>' <EOL> else : <EOL> flags = '<STR_LIT>' <EOL> if func . __doc__ : <EOL> funcString = func . __doc__ . strip ( ) <EOL> else : <EOL> funcString = pmcmds . getCmdName ( func ) + '<STR_LIT>' <EOL> doc += '<STR_LIT>' + funcString + flags + '<STR_LIT:\n>' <EOL> newFunc . __doc__ = doc <EOL> callbackFlags = cmdInfo . get ( '<STR_LIT>' , None ) <EOL> if callbackFlags : <EOL> newFunc = fixCallbacks ( newFunc , callbackFlags , funcName ) <EOL> if newFunc == inFunc and ( type ( newFunc ) == types . BuiltinFunctionType or rename ) : <EOL> def newFunc ( * args , ** kwargs ) : <EOL> return inFunc ( * args , ** kwargs ) <EOL> if customFunc : <EOL> if not newFunc . __doc__ : <EOL> newFunc . __doc__ = inFunc . __doc__ <EOL> elif inFunc . __doc__ : <EOL> newFunc . __doc__ = inFunc . __doc__ <EOL> _addCmdDocs ( newFunc , funcName ) <EOL> if rename : <EOL> newFunc . __name__ = rename <EOL> else : <EOL> newFunc . __name__ = funcName <EOL> return newFunc <EOL> def makeCreateFlagMethod ( inFunc , flag , newMethodName = None , docstring = '<STR_LIT>' , cmdName = None , returnFunc = None ) : <EOL> if cmdName is None : <EOL> cmdName = pmcmds . getCmdName ( inFunc ) <EOL> if returnFunc : <EOL> def wrappedMelFunc ( * args , ** kwargs ) : <EOL> if len ( args ) <= <NUM_LIT:1> : <EOL> kwargs [ flag ] = True <EOL> elif len ( args ) == <NUM_LIT:2> : <EOL> kwargs [ flag ] = args [ <NUM_LIT:1> ] <EOL> args = ( args [ <NUM_LIT:0> ] , ) <EOL> else : <EOL> kwargs [ flag ] = args [ <NUM_LIT:1> : ] <EOL> args = ( args [ <NUM_LIT:0> ] , ) <EOL> return returnFunc ( inFunc ( * args , ** kwargs ) ) <EOL> else : <EOL> def wrappedMelFunc ( * args , ** kwargs ) : <EOL> if len ( args ) <= <NUM_LIT:1> : <EOL> kwargs [ flag ] = True <EOL> elif len ( args ) == <NUM_LIT:2> : <EOL> kwargs [ flag ] = args [ <NUM_LIT:1> ] <EOL> args = ( args [ <NUM_LIT:0> ] , ) <EOL> else : <EOL> kwargs [ flag ] = args [ <NUM_LIT:1> : ] <EOL> args = ( args [ <NUM_LIT:0> ] , ) <EOL> return inFunc ( * args , ** kwargs ) <EOL> if newMethodName : <EOL> wrappedMelFunc . __name__ = newMethodName <EOL> else : <EOL> wrappedMelFunc . __name__ = flag <EOL> return _addFlagCmdDocs ( wrappedMelFunc , cmdName , flag , docstring ) <EOL> def createflag ( cmdName , flag ) : <EOL> """<STR_LIT>""" <EOL> def create_decorator ( method ) : <EOL> wrappedMelFunc = makeCreateFlagMethod ( method , flag , pmcmds . getCmdName ( method ) , cmdName = cmdName ) <EOL> wrappedMelFunc . __module__ = method . __module__ <EOL> return wrappedMelFunc <EOL> return create_decorator <EOL> '''<STR_LIT>''' <EOL> def makeQueryFlagMethod ( inFunc , flag , newMethodName = None , docstring = '<STR_LIT>' , cmdName = None , returnFunc = None ) : <EOL> if cmdName is None : <EOL> cmdName = pmcmds . getCmdName ( inFunc ) <EOL> if returnFunc : <EOL> def wrappedMelFunc ( self , ** kwargs ) : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> kwargs [ flag ] = True <EOL> return returnFunc ( inFunc ( self , ** kwargs ) ) <EOL> else : <EOL> def wrappedMelFunc ( self , ** kwargs ) : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> kwargs [ flag ] = True <EOL> return inFunc ( self , ** kwargs ) <EOL> if newMethodName : <EOL> wrappedMelFunc . __name__ = newMethodName <EOL> else : <EOL> wrappedMelFunc . __name__ = flag <EOL> return _addFlagCmdDocs ( wrappedMelFunc , cmdName , flag , docstring ) <EOL> def queryflag ( cmdName , flag ) : <EOL> """<STR_LIT>""" <EOL> def query_decorator ( method ) : <EOL> wrappedMelFunc = makeQueryFlagMethod ( method , flag , pmcmds . getCmdName ( method ) , cmdName = cmdName ) <EOL> wrappedMelFunc . __module__ = method . __module__ <EOL> return wrappedMelFunc <EOL> return query_decorator <EOL> def makeEditFlagMethod ( inFunc , flag , newMethodName = None , docstring = '<STR_LIT>' , cmdName = None ) : <EOL> if cmdName is None : <EOL> cmdName = pmcmds . getCmdName ( inFunc ) <EOL> def wrappedMelFunc ( self , val = True , ** kwargs ) : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> kwargs [ flag ] = val <EOL> try : <EOL> return inFunc ( self , ** kwargs ) <EOL> except TypeError : <EOL> kwargs . pop ( '<STR_LIT>' ) <EOL> return inFunc ( self , ** kwargs ) <EOL> if newMethodName : <EOL> wrappedMelFunc . __name__ = newMethodName <EOL> else : <EOL> wrappedMelFunc . __name__ = flag <EOL> return _addFlagCmdDocs ( wrappedMelFunc , cmdName , flag , docstring ) <EOL> def editflag ( cmdName , flag ) : <EOL> """<STR_LIT>""" <EOL> def edit_decorator ( method ) : <EOL> wrappedMelFunc = makeEditFlagMethod ( method , flag , pmcmds . getCmdName ( method ) , cmdName = cmdName ) <EOL> wrappedMelFunc . __module__ = method . __module__ <EOL> return wrappedMelFunc <EOL> return edit_decorator <EOL> def addMelDocs ( cmdName , flag = None ) : <EOL> """<STR_LIT>""" <EOL> if flag : <EOL> def doc_decorator ( method ) : <EOL> wrappedMelFunc = _addFlagCmdDocs ( method , cmdName , flag ) <EOL> wrappedMelFunc . __module__ = method . __module__ <EOL> return wrappedMelFunc <EOL> else : <EOL> def doc_decorator ( func ) : <EOL> try : <EOL> wrappedMelFunc = _addCmdDocs ( func , cmdName ) <EOL> wrappedMelFunc . __module__ = func . __module__ <EOL> except KeyError : <EOL> _logger . info ( ( "<STR_LIT>" % ( cmdName ) ) ) <EOL> wrappedMelFunc = func <EOL> return wrappedMelFunc <EOL> return doc_decorator <EOL> def listForNoneQuery ( res , kwargs , flags ) : <EOL> "<STR_LIT>" <EOL> if res is None and kwargs . get ( '<STR_LIT>' , kwargs . get ( '<STR_LIT:q>' , False ) ) and bool ( [ True for long , short in flags if kwargs . get ( long , kwargs . get ( short , False ) ) ] ) : <EOL> return [ ] <EOL> return res <EOL> def createFunctions ( moduleName , returnFunc = None ) : <EOL> module = sys . modules [ moduleName ] <EOL> moduleShortName = moduleName . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> for funcName in moduleCmds [ moduleShortName ] : <EOL> if funcName in nodeCommandList : <EOL> func = functionFactory ( funcName , returnFunc = returnFunc , module = module ) <EOL> else : <EOL> func = functionFactory ( funcName , returnFunc = None , module = module ) <EOL> if func : <EOL> func . __module__ = moduleName <EOL> setattr ( module , funcName , func ) <EOL> overrideMethods = { } <EOL> overrideMethods [ '<STR_LIT>' ] = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class ApiTypeRegister ( object ) : <EOL> """<STR_LIT>""" <EOL> types = { } <EOL> inCast = { } <EOL> outCast = { } <EOL> refInit = { } <EOL> refCast = { } <EOL> arrayItemTypes = { } <EOL> doc = { } <EOL> @ staticmethod <EOL> def _makeRefFunc ( capitalizedApiType , size = <NUM_LIT:1> , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def makeRef ( ) : <EOL> return api . SafeApiPtr ( capitalizedApiType , size = size , ** kwargs ) <EOL> return makeRef <EOL> @ staticmethod <EOL> def _makeApiArraySetter ( type , inCast ) : <EOL> iterable = hasattr ( inCast , '<STR_LIT>' ) <EOL> def setArray ( array ) : <EOL> arrayPtr = type ( ) <EOL> if iterable : <EOL> [ arrayPtr . append ( inCast ( * x ) ) for x in array ] <EOL> else : <EOL> [ arrayPtr . append ( inCast ( x ) ) for x in array ] <EOL> return arrayPtr <EOL> setArray . __name__ = '<STR_LIT>' + type . __name__ <EOL> return setArray <EOL> @ staticmethod <EOL> def _makeArraySetter ( apiTypeName , length , initFunc ) : <EOL> def setArray ( array ) : <EOL> if len ( array ) != length : <EOL> raise ValueError , '<STR_LIT>' % ( length , apiTypeName ) <EOL> safeArrayPtr = initFunc ( ) <EOL> for i , val in enumerate ( array ) : <EOL> safeArrayPtr [ i ] = val <EOL> return safeArrayPtr <EOL> setArray . __name__ = '<STR_LIT>' + apiTypeName + str ( length ) + '<STR_LIT>' <EOL> return setArray <EOL> @ staticmethod <EOL> def _makeArrayGetter ( apiTypeName , length ) : <EOL> def getArray ( safeArrayPtr ) : <EOL> return [ x for x in safeArrayPtr ] <EOL> getArray . __name__ = '<STR_LIT>' + apiTypeName + str ( length ) + '<STR_LIT>' <EOL> return getArray <EOL> @ classmethod <EOL> def getPymelType ( cls , apiType ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return cls . types [ apiType ] <EOL> except KeyError : <EOL> try : <EOL> buf = re . split ( '<STR_LIT>' , apiType ) <EOL> assert buf [ <NUM_LIT:1> ] <EOL> return buf [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> raise <EOL> @ classmethod <EOL> def isRegistered ( cls , apiTypeName ) : <EOL> return apiTypeName in cls . types <EOL> @ classmethod <EOL> def register ( cls , apiTypeName , pymelType , inCast = None , outCast = None , apiArrayItemType = None ) : <EOL> """<STR_LIT>""" <EOL> capType = util . capitalize ( apiTypeName ) <EOL> cls . types [ apiTypeName ] = pymelType . __name__ <EOL> if apiArrayItemType : <EOL> cls . arrayItemTypes [ apiTypeName ] = apiArrayItemType <EOL> if outCast : <EOL> cls . outCast [ apiTypeName ] = outCast <EOL> elif apiArrayItemType is not None : <EOL> pass <EOL> else : <EOL> cls . outCast [ apiTypeName ] = lambda self , x : pymelType ( x ) <EOL> if inCast : <EOL> cls . inCast [ apiTypeName ] = inCast <EOL> elif apiArrayItemType is not None : <EOL> pass <EOL> else : <EOL> cls . inCast [ apiTypeName ] = pymelType <EOL> if apiTypeName in [ '<STR_LIT:float>' , '<STR_LIT>' , '<STR_LIT:bool>' , '<STR_LIT:int>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> initFunc = cls . _makeRefFunc ( capType ) <EOL> getFunc = api . SafeApiPtr . get <EOL> cls . refInit [ apiTypeName ] = initFunc <EOL> cls . refCast [ apiTypeName ] = getFunc <EOL> for i in [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] : <EOL> iapiArrayTypename = apiTypeName + '<STR_LIT>' + str ( i ) <EOL> arrayInitFunc = cls . _makeRefFunc ( capType , size = i ) <EOL> cls . refInit [ iapiArrayTypename ] = arrayInitFunc <EOL> cls . inCast [ iapiArrayTypename ] = cls . _makeArraySetter ( apiTypeName , i , arrayInitFunc ) <EOL> cls . refCast [ iapiArrayTypename ] = cls . _makeArrayGetter ( apiTypeName , i ) <EOL> cls . types [ iapiArrayTypename ] = tuple ( [ pymelType . __name__ ] * i ) <EOL> apiTypeNameN = apiTypeName + str ( i ) <EOL> castNFuncName = '<STR_LIT>' + capType + str ( i ) + '<STR_LIT>' <EOL> if hasattr ( api . MScriptUtil , castNFuncName ) : <EOL> nInitFunc = cls . _makeRefFunc ( apiTypeName , size = i , asTypeNPtr = True ) <EOL> cls . refInit [ apiTypeNameN ] = nInitFunc <EOL> cls . inCast [ apiTypeNameN ] = cls . _makeArraySetter ( apiTypeName , i , nInitFunc ) <EOL> cls . refCast [ apiTypeNameN ] = cls . _makeArrayGetter ( apiTypeName , i ) <EOL> cls . types [ apiTypeNameN ] = tuple ( [ pymelType . __name__ ] * i ) <EOL> else : <EOL> try : <EOL> apiType = getattr ( api , apiTypeName ) <EOL> except AttributeError : <EOL> if apiArrayItemType : <EOL> cls . refInit [ apiTypeName ] = list <EOL> cls . inCast [ apiTypeName ] = lambda x : [ apiArrayItemType ( y ) for y in x ] <EOL> cls . refCast [ apiTypeName ] = None <EOL> cls . outCast [ apiTypeName ] = None <EOL> else : <EOL> if apiArrayItemType : <EOL> cls . refInit [ apiTypeName ] = apiType <EOL> cls . inCast [ apiTypeName ] = cls . _makeApiArraySetter ( apiType , apiArrayItemType ) <EOL> if apiType == api . MDagPathArray : <EOL> cls . refCast [ apiTypeName ] = lambda x : [ pymelType ( apiArrayItemType ( x [ i ] ) ) for i in range ( x . length ( ) ) ] <EOL> cls . outCast [ apiTypeName ] = lambda self , x : [ pymelType ( apiArrayItemType ( x [ i ] ) ) for i in range ( x . length ( ) ) ] <EOL> else : <EOL> cls . refCast [ apiTypeName ] = lambda x : [ pymelType ( x [ i ] ) for i in range ( x . length ( ) ) ] <EOL> cls . outCast [ apiTypeName ] = lambda self , x : [ pymelType ( x [ i ] ) for i in range ( x . length ( ) ) ] <EOL> else : <EOL> cls . refInit [ apiTypeName ] = apiType <EOL> cls . refCast [ apiTypeName ] = pymelType <EOL> try : <EOL> arrayTypename = apiTypeName + '<STR_LIT>' <EOL> apiArrayType = getattr ( api , arrayTypename ) <EOL> ApiTypeRegister . register ( arrayTypename , pymelType , apiArrayItemType = apiType ) <EOL> except AttributeError : <EOL> pass <EOL> ApiTypeRegister . register ( '<STR_LIT:float>' , float ) <EOL> ApiTypeRegister . register ( '<STR_LIT>' , float ) <EOL> ApiTypeRegister . register ( '<STR_LIT:bool>' , bool ) <EOL> ApiTypeRegister . register ( '<STR_LIT:int>' , int ) <EOL> ApiTypeRegister . register ( '<STR_LIT>' , int ) <EOL> ApiTypeRegister . register ( '<STR_LIT>' , int ) <EOL> ApiTypeRegister . register ( '<STR_LIT>' , int ) <EOL> ApiTypeRegister . register ( '<STR_LIT>' , unicode ) <EOL> ApiTypeRegister . register ( '<STR_LIT>' , list , apiArrayItemType = unicode ) <EOL> ApiTypeRegister . register ( '<STR_LIT>' , int , apiArrayItemType = int ) <EOL> ApiTypeRegister . register ( '<STR_LIT>' , float , apiArrayItemType = float ) <EOL> ApiTypeRegister . register ( '<STR_LIT>' , float , apiArrayItemType = float ) <EOL> class ApiArgUtil ( object ) : <EOL> def __init__ ( self , apiClassName , methodName , methodIndex = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . apiClassName = apiClassName <EOL> self . methodName = methodName <EOL> if methodIndex is None : <EOL> try : <EOL> methodInfoList = apiClassInfo [ apiClassName ] [ '<STR_LIT>' ] [ methodName ] <EOL> except KeyError : <EOL> raise TypeError , "<STR_LIT>" % ( methodName , apiClassName ) <EOL> else : <EOL> for i , methodInfo in enumerate ( methodInfoList ) : <EOL> argHelper = ApiArgUtil ( apiClassName , methodName , i ) <EOL> if argHelper . canBeWrapped ( ) : <EOL> methodIndex = i <EOL> break <EOL> if methodIndex is None : <EOL> raise TypeError , "<STR_LIT>" % ( methodName , apiClassName ) <EOL> self . methodInfo = apiClassInfo [ apiClassName ] [ '<STR_LIT>' ] [ methodName ] [ methodIndex ] <EOL> self . methodIndex = methodIndex <EOL> def iterArgs ( self , inputs = True , outputs = True , infoKeys = [ ] ) : <EOL> res = [ ] <EOL> for argname , argtype , direction in self . methodInfo [ '<STR_LIT:args>' ] : <EOL> if direction == '<STR_LIT>' : <EOL> if not inputs : <EOL> continue <EOL> else : <EOL> if not outputs : <EOL> continue <EOL> if infoKeys : <EOL> arg_res = [ argname ] <EOL> argInfo = self . methodInfo [ '<STR_LIT>' ] [ argname ] <EOL> for key in infoKeys : <EOL> arg_res . append ( argInfo [ key ] ) <EOL> else : <EOL> arg_res = argname <EOL> res . append ( arg_res ) <EOL> return res <EOL> def inArgs ( self ) : <EOL> return self . methodInfo [ '<STR_LIT>' ] <EOL> def outArgs ( self ) : <EOL> return self . methodInfo [ '<STR_LIT>' ] <EOL> def argList ( self ) : <EOL> return self . methodInfo [ '<STR_LIT:args>' ] <EOL> def argInfo ( self ) : <EOL> return self . methodInfo [ '<STR_LIT>' ] <EOL> def getGetterInfo ( self ) : <EOL> try : <EOL> inverse , isgetter = self . methodInfo [ '<STR_LIT>' ] <EOL> if isgetter : <EOL> if hasattr ( getattr ( api , self . apiClassName ) , inverse ) : <EOL> return ApiArgUtil ( self . apiClassName , inverse , self . methodIndex ) <EOL> except : <EOL> pass <EOL> @ staticmethod <EOL> def isValidEnum ( enumTuple ) : <EOL> if apiClassInfo . has_key ( enumTuple [ <NUM_LIT:0> ] ) and apiClassInfo [ enumTuple [ <NUM_LIT:0> ] ] [ '<STR_LIT>' ] . has_key ( enumTuple [ <NUM_LIT:1> ] ) : <EOL> return True <EOL> return False <EOL> def hasOutput ( self ) : <EOL> if self . methodInfo [ '<STR_LIT>' ] or self . methodInfo [ '<STR_LIT>' ] : <EOL> return True <EOL> return False <EOL> def canBeWrapped ( self ) : <EOL> defaults = self . methodInfo [ '<STR_LIT>' ] <EOL> returnType = self . methodInfo [ '<STR_LIT>' ] <EOL> try : <EOL> if returnType is not None : <EOL> if isinstance ( returnType , tuple ) : <EOL> assert self . isValidEnum ( returnType ) , '<STR_LIT>' % ( self . apiClassName , self . methodName , returnType ) <EOL> else : <EOL> if not self . apiClassName == '<STR_LIT>' and not returnType == '<STR_LIT>' : <EOL> assert returnType in ApiTypeRegister . outCast or returnType == self . apiClassName , '<STR_LIT>' % ( self . apiClassName , self . methodName , returnType ) <EOL> for argname , argtype , direction in self . methodInfo [ '<STR_LIT:args>' ] : <EOL> if isinstance ( argtype , tuple ) : <EOL> assert self . isValidEnum ( argtype ) , '<STR_LIT>' % ( self . apiClassName , self . methodName , argname , argtype ) <EOL> elif direction == '<STR_LIT>' : <EOL> if not self . apiClassName == '<STR_LIT>' : <EOL> assert argtype in ApiTypeRegister . inCast or defaults . has_key ( argname ) or argtype == self . apiClassName , '<STR_LIT>' % ( self . apiClassName , self . methodName , argname , argtype ) <EOL> elif direction == '<STR_LIT>' : <EOL> if not argtype == '<STR_LIT>' : <EOL> assert argtype in ApiTypeRegister . refInit and argtype in ApiTypeRegister . refCast , '<STR_LIT>' % ( self . apiClassName , self . methodName , argname , argtype ) <EOL> except AssertionError , msg : <EOL> return False <EOL> return True <EOL> def getInputTypes ( self ) : <EOL> inArgs = self . methodInfo [ '<STR_LIT>' ] <EOL> types = self . methodInfo [ '<STR_LIT>' ] <EOL> return [ str ( types [ x ] ) for x in inArgs ] <EOL> def getOutputTypes ( self ) : <EOL> ret = self . methodInfo [ '<STR_LIT>' ] <EOL> if ret is None : <EOL> ret = [ ] <EOL> else : <EOL> ret = [ str ( ret ) ] <EOL> outArgs = self . methodInfo [ '<STR_LIT>' ] <EOL> types = self . methodInfo [ '<STR_LIT>' ] <EOL> return ret + [ str ( types [ x ] ) for x in outArgs ] <EOL> def getReturnType ( self ) : <EOL> return self . methodInfo [ '<STR_LIT>' ] <EOL> def getPymelName ( self ) : <EOL> pymelName = self . methodInfo . get ( '<STR_LIT>' , self . methodName ) <EOL> try : <EOL> pymelClassName = apiClassNamesToPyNodeNames [ self . apiClassName ] <EOL> pymelName , data = _getApiOverrideNameAndData ( pymelClassName , pymelName ) <EOL> except KeyError : <EOL> pass <EOL> return pymelName <EOL> def getMethodDocs ( self ) : <EOL> return self . methodInfo [ '<STR_LIT>' ] <EOL> def getPrototype ( self , className = True , methodName = True , outputs = False , defaults = False ) : <EOL> inArgs = self . methodInfo [ '<STR_LIT>' ] <EOL> outArgs = self . methodInfo [ '<STR_LIT>' ] <EOL> returnType = self . methodInfo [ '<STR_LIT>' ] <EOL> types = self . methodInfo [ '<STR_LIT>' ] <EOL> args = [ ] <EOL> for x in inArgs : <EOL> arg = str ( types [ x ] ) + '<STR_LIT:U+0020>' + x <EOL> if defaults : <EOL> try : <EOL> arg += '<STR_LIT:=>' + str ( self . methodInfo [ '<STR_LIT>' ] [ x ] ) <EOL> except KeyError : pass <EOL> args . append ( arg ) <EOL> proto = "<STR_LIT>" % ( '<STR_LIT:U+002CU+0020>' . join ( args ) ) <EOL> if methodName : <EOL> proto = self . methodName + proto <EOL> if className : <EOL> proto = self . apiClassName + '<STR_LIT:.>' + proto <EOL> if outputs : <EOL> results = [ ] <EOL> if returnType : <EOL> results . append ( returnType ) <EOL> for x in outArgs : <EOL> results . append ( types [ x ] ) <EOL> if len ( results ) == <NUM_LIT:1> : <EOL> proto += '<STR_LIT>' + str ( results [ <NUM_LIT:0> ] ) <EOL> elif len ( results ) : <EOL> proto += '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( [ str ( x ) for x in results ] ) <EOL> return proto <EOL> def castInput ( self , argName , input , cls ) : <EOL> argtype = self . methodInfo [ '<STR_LIT>' ] [ argName ] <EOL> if isinstance ( argtype , tuple ) : <EOL> apiClassName , enumName = argtype <EOL> return self . castInputEnum ( apiClassName , enumName , input ) <EOL> elif input is not None : <EOL> f = ApiTypeRegister . inCast [ argtype ] <EOL> if f is None : <EOL> return input <EOL> input = self . toInternalUnits ( argName , input ) <EOL> return f ( input ) <EOL> @ classmethod <EOL> def castInputEnum ( cls , apiClassName , enumName , input ) : <EOL> try : <EOL> return apiClassInfo [ apiClassName ] [ '<STR_LIT>' ] [ enumName ] . getIndex ( input ) <EOL> except ValueError : <EOL> raise ValueError , "<STR_LIT>" % ( apiClassName , enumName , input ) <EOL> def fromInternalUnits ( self , result , instance = None ) : <EOL> unit = self . methodInfo [ '<STR_LIT>' ] . get ( '<STR_LIT>' , None ) <EOL> returnType = self . methodInfo [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] <EOL> if unit == '<STR_LIT>' or returnType == '<STR_LIT>' : <EOL> unitCast = ApiTypeRegister . outCast [ '<STR_LIT>' ] <EOL> if util . isIterable ( result ) : <EOL> result = [ unitCast ( instance , val ) for val in result ] <EOL> else : <EOL> result = unitCast ( instance , result ) <EOL> elif returnType == '<STR_LIT>' : <EOL> unitCast = ApiTypeRegister . outCast [ '<STR_LIT>' ] <EOL> result = [ unitCast ( instance , result [ <NUM_LIT:0> ] ) , unitCast ( instance , result [ <NUM_LIT:1> ] ) , unitCast ( instance , result [ <NUM_LIT:2> ] ) ] <EOL> elif unit == '<STR_LIT>' : <EOL> unitCast = ApiTypeRegister . outCast [ '<STR_LIT>' ] <EOL> if util . isIterable ( result ) : <EOL> result = [ unitCast ( instance , val ) for val in result ] <EOL> else : <EOL> result = unitCast ( instance , result ) <EOL> return result <EOL> def toInternalUnits ( self , arg , input ) : <EOL> info = self . methodInfo [ '<STR_LIT>' ] [ arg ] <EOL> unit = info . get ( '<STR_LIT>' , None ) <EOL> if unit == '<STR_LIT>' : <EOL> unitCast = ApiTypeRegister . inCast [ '<STR_LIT>' ] <EOL> if util . isIterable ( input ) : <EOL> input = [ unitCast ( val ) . asInternalUnit ( ) for val in input ] <EOL> else : <EOL> input = unitCast ( input ) . asInternalUnit ( ) <EOL> elif unit == '<STR_LIT>' : <EOL> unitCast = ApiTypeRegister . inCast [ '<STR_LIT>' ] <EOL> if util . isIterable ( input ) : <EOL> input = [ unitCast ( val ) . asInternalUnit ( ) for val in input ] <EOL> else : <EOL> input = unitCast ( input ) . asInternalUnit ( ) <EOL> return input <EOL> def castResult ( self , instance , result ) : <EOL> returnType = self . methodInfo [ '<STR_LIT>' ] <EOL> if returnType : <EOL> if isinstance ( returnType , tuple ) : <EOL> apiClassName , enumName = returnType <EOL> try : <EOL> return apiClassInfo [ apiClassName ] [ '<STR_LIT>' ] [ enumName ] [ result ] <EOL> except KeyError : <EOL> raise ValueError , "<STR_LIT>" % ( apiClassName , enumName ) <EOL> else : <EOL> f = ApiTypeRegister . outCast [ returnType ] <EOL> if f is None : <EOL> return result <EOL> result = self . fromInternalUnits ( result , instance ) <EOL> return f ( instance , result ) <EOL> def initReference ( self , argtype ) : <EOL> return ApiTypeRegister . refInit [ argtype ] ( ) <EOL> def castReferenceResult ( self , argtype , outArg ) : <EOL> f = ApiTypeRegister . refCast [ argtype ] <EOL> if f is None : <EOL> return outArg <EOL> result = self . fromInternalUnits ( outArg ) <EOL> return f ( result ) <EOL> def getDefaults ( self ) : <EOL> "<STR_LIT>" <EOL> defaults = [ ] <EOL> defaultInfo = self . methodInfo [ '<STR_LIT>' ] <EOL> inArgs = self . methodInfo [ '<STR_LIT>' ] <EOL> nargs = len ( inArgs ) <EOL> for i , arg in enumerate ( inArgs ) : <EOL> if arg in defaultInfo : <EOL> default = defaultInfo [ arg ] <EOL> else : <EOL> continue <EOL> if isinstance ( default , apicache . ApiEnum ) : <EOL> apiClassName , enumName , enumValue = default <EOL> try : <EOL> enumList = apiClassInfo [ apiClassName ] [ '<STR_LIT>' ] [ enumName ] [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> _logger . warning ( "<STR_LIT>" , default ) <EOL> else : <EOL> index = enumList . getIndex ( enumValue ) <EOL> default = apiClassInfo [ apiClassName ] [ '<STR_LIT>' ] [ enumName ] [ index ] <EOL> defaults . append ( default ) <EOL> return defaults <EOL> def isStatic ( self ) : <EOL> return self . methodInfo [ '<STR_LIT>' ] <EOL> def isDeprecated ( self ) : <EOL> return self . methodInfo . get ( '<STR_LIT>' , False ) <EOL> class ApiUndo : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = util . Singleton <EOL> def __init__ ( self ) : <EOL> self . node_name = '<STR_LIT>' <EOL> self . cb_enabled = True <EOL> self . undo_queue = [ ] <EOL> self . redo_queue = [ ] <EOL> def _attrChanged ( self , msg , plug , otherPlug , data ) : <EOL> if self . cb_enabled and ( msg & api . MNodeMessage . kAttributeSet != <NUM_LIT:0> ) and ( plug == self . cmdCountAttr ) : <EOL> if api . MGlobal . isUndoing ( ) : <EOL> self . cb_enabled = False <EOL> cmdObj = self . undo_queue . pop ( ) <EOL> cmdObj . undoIt ( ) <EOL> self . redo_queue . append ( cmdObj ) <EOL> self . cb_enabled = True <EOL> elif api . MGlobal . isRedoing ( ) : <EOL> self . cb_enabled = False <EOL> cmdObj = self . redo_queue . pop ( ) <EOL> cmdObj . redoIt ( ) <EOL> self . undo_queue . append ( cmdObj ) <EOL> self . cb_enabled = True <EOL> def _attrChanged_85 ( self ) : <EOL> print "<STR_LIT>" , self . cb_enabled , api . MGlobal . isUndoing ( ) <EOL> if self . cb_enabled : <EOL> if api . MGlobal . isUndoing ( ) : <EOL> cmdObj = self . undo_queue . pop ( ) <EOL> print "<STR_LIT>" <EOL> cmdObj . undoIt ( ) <EOL> self . redo_queue . append ( cmdObj ) <EOL> elif api . MGlobal . isRedoing ( ) : <EOL> cmdObj = self . redo_queue . pop ( ) <EOL> print "<STR_LIT>" <EOL> cmdObj . redoIt ( ) <EOL> self . undo_queue . append ( cmdObj ) <EOL> def _createNode ( self ) : <EOL> """<STR_LIT>""" <EOL> ns = api . MNamespace . currentNamespace ( ) <EOL> api . MNamespace . setCurrentNamespace ( '<STR_LIT::>' ) <EOL> self . flushUndo ( ) <EOL> dgmod = api . MDGModifier ( ) <EOL> self . undoNode = dgmod . createNode ( '<STR_LIT>' ) <EOL> dgmod . renameNode ( self . undoNode , self . node_name ) <EOL> dgmod . doIt ( ) <EOL> api . MNamespace . setCurrentNamespace ( ns ) <EOL> attrFn = api . MFnNumericAttribute ( ) <EOL> self . cmdCountAttr = attrFn . create ( '<STR_LIT>' , '<STR_LIT>' , <EOL> api . MFnNumericData . kInt <EOL> ) <EOL> nodeFn = api . MFnDependencyNode ( self . undoNode ) <EOL> self . node_name = nodeFn . name ( ) <EOL> nodeFn . addAttribute ( self . cmdCountAttr ) <EOL> nodeFn . setDoNotWrite ( True ) <EOL> nodeFn . setLocked ( True ) <EOL> try : <EOL> api . MMessage . removeCallback ( self . cbid ) <EOL> if hasattr ( self . cbid , '<STR_LIT>' ) : <EOL> self . cbid . disown ( ) <EOL> except : <EOL> pass <EOL> self . cbid = api . MNodeMessage . addAttributeChangedCallback ( self . undoNode , self . _attrChanged ) <EOL> def append ( self , cmdObj ) : <EOL> self . cb_enabled = False <EOL> try : <EOL> count = cmds . getAttr ( self . node_name + '<STR_LIT>' ) <EOL> except : <EOL> self . _createNode ( ) <EOL> count = cmds . getAttr ( self . node_name + '<STR_LIT>' ) <EOL> cmds . setAttr ( self . node_name + '<STR_LIT>' , count + <NUM_LIT:1> ) <EOL> self . undo_queue . append ( cmdObj ) <EOL> self . redo_queue = [ ] <EOL> self . cb_enabled = True <EOL> def execute ( self , cmdObj , args ) : <EOL> self . cb_enabled = False <EOL> if not cmds . objExists ( self . node_name ) : <EOL> self . _createNode ( ) <EOL> count = cmds . getAttr ( self . node_name + '<STR_LIT>' ) <EOL> cmds . setAttr ( self . node_name + '<STR_LIT>' , count + <NUM_LIT:1> ) <EOL> res = cmdObj . doIt ( args ) <EOL> self . undo_queue . append ( cmdObj ) <EOL> self . redo_queue = [ ] <EOL> self . cb_enabled = True <EOL> return res <EOL> def flushUndo ( self , * args ) : <EOL> self . undo_queue = [ ] <EOL> self . redo_queue = [ ] <EOL> apiUndo = ApiUndo ( ) <EOL> class ApiUndoItem ( object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def __init__ ( self , setter , redoArgs , undoArgs , redoKwargs = None , <EOL> undoKwargs = None ) : <EOL> self . _setter = setter <EOL> self . _redo_args = redoArgs <EOL> self . _undo_args = undoArgs <EOL> if redoKwargs is None : <EOL> redoKwargs = { } <EOL> self . _redo_kwargs = redoKwargs <EOL> if undoKwargs is None : <EOL> undoKwargs = { } <EOL> self . _undo_kwargs = undoKwargs <EOL> def redoIt ( self ) : <EOL> self . _setter ( * self . _redo_args , ** self . _redo_kwargs ) <EOL> def undoIt ( self ) : <EOL> self . _setter ( * self . _undo_args , ** self . _undo_kwargs ) <EOL> class ApiRedoUndoItem ( ApiUndoItem ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = [ '<STR_LIT>' ] <EOL> def __init__ ( self , redoer , redoArgs , undoer , undoArgs , redoKwargs = None , <EOL> undoKwargs = None ) : <EOL> super ( ApiRedoUndoItem , self ) . __init__ ( redoer , redoArgs , undoArgs , <EOL> redoKwargs = redoKwargs , <EOL> undoKwargs = undoKwargs ) <EOL> self . _undoer = undoer <EOL> def undoIt ( self ) : <EOL> self . _undoer ( * self . _undo_args , ** self . _undo_kwargs ) <EOL> def wrapApiMethod ( apiClass , methodName , newName = None , proxy = True , overloadIndex = None ) : <EOL> """<STR_LIT>""" <EOL> apiClassName = apiClass . __name__ <EOL> try : <EOL> method = getattr ( apiClass , methodName ) <EOL> except AttributeError : <EOL> return <EOL> argHelper = ApiArgUtil ( apiClassName , methodName , overloadIndex ) <EOL> undoable = True <EOL> if newName is None : <EOL> pymelName = argHelper . getPymelName ( ) <EOL> else : <EOL> pymelName = newName <EOL> if argHelper . canBeWrapped ( ) : <EOL> if argHelper . isDeprecated ( ) : <EOL> _logger . debug ( "<STR_LIT>" % ( apiClassName , methodName ) ) <EOL> inArgs = argHelper . inArgs ( ) <EOL> outArgs = argHelper . outArgs ( ) <EOL> argList = argHelper . argList ( ) <EOL> argInfo = argHelper . argInfo ( ) <EOL> getterArgHelper = argHelper . getGetterInfo ( ) <EOL> if argHelper . hasOutput ( ) : <EOL> getterInArgs = [ ] <EOL> else : <EOL> if getterArgHelper is None : <EOL> getterInArgs = [ ] <EOL> undoable = False <EOL> else : <EOL> getterInArgs = getterArgHelper . inArgs ( ) <EOL> def wrappedApiFunc ( self , * args ) : <EOL> do_args = [ ] <EOL> outTypeList = [ ] <EOL> undoEnabled = getterArgHelper is not None and cmds . undoInfo ( q = <NUM_LIT:1> , state = <NUM_LIT:1> ) and apiUndo . cb_enabled <EOL> if len ( args ) != len ( inArgs ) : <EOL> raise TypeError , "<STR_LIT>" % ( methodName , len ( inArgs ) , len ( args ) ) <EOL> if undoEnabled : <EOL> getterArgs = [ ] <EOL> undo_args = [ ] <EOL> missingUndoIndices = [ ] <EOL> inCount = <NUM_LIT:0> <EOL> for name , argtype , direction in argList : <EOL> if direction == '<STR_LIT>' : <EOL> arg = args [ inCount ] <EOL> undo_args . append ( arg ) <EOL> if name in getterInArgs : <EOL> getterArgs . append ( arg ) <EOL> else : <EOL> missingUndoIndices . append ( inCount ) <EOL> inCount += <NUM_LIT:1> <EOL> getter = getattr ( self , getterArgHelper . getPymelName ( ) ) <EOL> setter = getattr ( self , pymelName ) <EOL> try : <EOL> getterResult = getter ( * getterArgs ) <EOL> except RuntimeError : <EOL> _logger . error ( "<STR_LIT>" % getterArgs ) <EOL> raise <EOL> if not isinstance ( getterResult , tuple ) : <EOL> getterResult = ( getterResult , ) <EOL> for index , result in zip ( missingUndoIndices , getterResult ) : <EOL> undo_args [ index ] = result <EOL> inCount = totalCount = <NUM_LIT:0> <EOL> for name , argtype , direction in argList : <EOL> if direction == '<STR_LIT>' : <EOL> arg = args [ inCount ] <EOL> do_args . append ( argHelper . castInput ( name , arg , self . __class__ ) ) <EOL> inCount += <NUM_LIT:1> <EOL> else : <EOL> val = argHelper . initReference ( argtype ) <EOL> do_args . append ( val ) <EOL> outTypeList . append ( ( argtype , totalCount ) ) <EOL> totalCount += <NUM_LIT:1> <EOL> if undoEnabled : <EOL> undoItem = ApiUndoItem ( setter , do_args , undo_args ) <EOL> apiUndo . append ( undoItem ) <EOL> final_do_args = [ ] <EOL> for arg in do_args : <EOL> if isinstance ( arg , api . SafeApiPtr ) : <EOL> final_do_args . append ( arg ( ) ) <EOL> else : <EOL> final_do_args . append ( arg ) <EOL> if argHelper . isStatic ( ) : <EOL> result = method ( * final_do_args ) <EOL> else : <EOL> if proxy : <EOL> mfn = self . __apimfn__ ( ) <EOL> if not isinstance ( mfn , apiClass ) : <EOL> mfn = apiClass ( self . __apiobject__ ( ) ) <EOL> result = method ( mfn , * final_do_args ) <EOL> else : <EOL> result = method ( self , * final_do_args ) <EOL> result = argHelper . castResult ( self , result ) <EOL> if len ( outArgs ) : <EOL> if result is not None : <EOL> result = [ result ] <EOL> else : <EOL> result = [ ] <EOL> for outType , index in outTypeList : <EOL> outArgVal = do_args [ index ] <EOL> res = argHelper . castReferenceResult ( outType , outArgVal ) <EOL> result . append ( res ) <EOL> if len ( result ) == <NUM_LIT:1> : <EOL> result = result [ <NUM_LIT:0> ] <EOL> else : <EOL> result = tuple ( result ) <EOL> return result <EOL> wrappedApiFunc . __name__ = pymelName <EOL> _addApiDocs ( wrappedApiFunc , apiClass , methodName , overloadIndex , undoable ) <EOL> defaults = [ ] <EOL> for default in argHelper . getDefaults ( ) : <EOL> if isinstance ( default , util . EnumValue ) : <EOL> defaults . append ( str ( default ) ) <EOL> else : <EOL> defaults . append ( default ) <EOL> if defaults : <EOL> pass <EOL> wrappedApiFunc = util . interface_wrapper ( wrappedApiFunc , [ '<STR_LIT>' ] + inArgs , defaults = defaults ) <EOL> wrappedApiFunc . _argHelper = argHelper <EOL> if argHelper . isStatic ( ) : <EOL> wrappedApiFunc = classmethod ( wrappedApiFunc ) <EOL> return wrappedApiFunc <EOL> def addApiDocs ( apiClass , methodName , overloadIndex = None , undoable = True ) : <EOL> """<STR_LIT>""" <EOL> def doc_decorator ( func ) : <EOL> return _addApiDocs ( func , apiClass , methodName , overloadIndex , undoable ) <EOL> return doc_decorator <EOL> def _addApiDocs ( wrappedApiFunc , apiClass , methodName , overloadIndex = None , undoable = True ) : <EOL> util . addLazyDocString ( wrappedApiFunc , addApiDocsCallback , apiClass , methodName , overloadIndex , undoable , wrappedApiFunc . __doc__ ) <EOL> return wrappedApiFunc <EOL> def addApiDocsCallback ( apiClass , methodName , overloadIndex = None , undoable = True , origDocstring = '<STR_LIT>' ) : <EOL> apiClassName = apiClass . __name__ <EOL> argHelper = ApiArgUtil ( apiClassName , methodName , overloadIndex ) <EOL> inArgs = argHelper . inArgs ( ) <EOL> outArgs = argHelper . outArgs ( ) <EOL> argList = argHelper . argList ( ) <EOL> argInfo = argHelper . argInfo ( ) <EOL> def formatDocstring ( type ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( type , list ) : <EOL> pymelType = ApiTypeRegister . types . get ( type , type ) <EOL> else : <EOL> pymelType = type <EOL> if isinstance ( pymelType , apicache . ApiEnum ) : <EOL> pymelType = pymelType . pymelName ( ) <EOL> doc = repr ( pymelType ) . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) <EOL> if type in ApiTypeRegister . arrayItemTypes . keys ( ) : <EOL> doc += '<STR_LIT>' <EOL> return doc <EOL> docstring = argHelper . getMethodDocs ( ) <EOL> docstring = docstring . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> docstring = docstring . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> S = '<STR_LIT:U+0020>' <EOL> if len ( inArgs ) : <EOL> docstring += '<STR_LIT>' <EOL> for name in inArgs : <EOL> info = argInfo [ name ] <EOL> type = info [ '<STR_LIT:type>' ] <EOL> typeStr = formatDocstring ( type ) <EOL> docstring += S + '<STR_LIT>' % ( name , typeStr ) <EOL> docstring += S * <NUM_LIT:2> + '<STR_LIT>' % ( info [ '<STR_LIT>' ] ) <EOL> if isinstance ( type , apicache . ApiEnum ) : <EOL> apiClassName , enumName = type <EOL> enumValues = apiClassInfo [ apiClassName ] [ '<STR_LIT>' ] [ enumName ] . keys ( ) <EOL> docstring += '<STR_LIT:\n>' + S * <NUM_LIT:2> + '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' % x for x in enumValues if x not in [ '<STR_LIT>' , '<STR_LIT>' ] ] ) <EOL> results = [ ] <EOL> returnType = argHelper . getReturnType ( ) <EOL> if returnType : <EOL> rtype = formatDocstring ( returnType ) <EOL> results . append ( rtype ) <EOL> for argname in outArgs : <EOL> rtype = argInfo [ argname ] [ '<STR_LIT:type>' ] <EOL> rtype = formatDocstring ( rtype ) <EOL> results . append ( rtype ) <EOL> if len ( results ) == <NUM_LIT:1> : <EOL> results = results [ <NUM_LIT:0> ] <EOL> docstring += '<STR_LIT>' % results <EOL> elif results : <EOL> docstring += '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( results ) <EOL> docstring += '<STR_LIT>' % ( apiClass . __module__ , apiClassName , methodName ) <EOL> if not undoable : <EOL> docstring += '<STR_LIT>' <EOL> if origDocstring : <EOL> docstring = origDocstring + '<STR_LIT:\n>' + docstring <EOL> return docstring <EOL> class MetaMayaTypeWrapper ( util . metaReadOnlyAttr ) : <EOL> """<STR_LIT>""" <EOL> _originalApiSetAttrs = { } <EOL> class ClassConstant ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __module__ , self . __class__ . __name__ , repr ( self . value ) ) <EOL> def __str__ ( self ) : <EOL> return self . __repr__ ( ) <EOL> def __get__ ( self , instance , owner ) : <EOL> if instance is None : <EOL> return owner ( self . value ) <EOL> else : <EOL> raise AttributeError , "<STR_LIT>" % ( owner . __name__ ) <EOL> def __set__ ( self , instance , value ) : <EOL> raise AttributeError , "<STR_LIT>" <EOL> def __delete__ ( self , instance ) : <EOL> raise AttributeError , "<STR_LIT>" <EOL> def __new__ ( cls , classname , bases , classdict ) : <EOL> """<STR_LIT>""" <EOL> removeAttrs = [ ] <EOL> if '<STR_LIT>' not in classdict : <EOL> classdict [ '<STR_LIT>' ] = ( ) <EOL> try : <EOL> apicls = classdict [ '<STR_LIT>' ] <EOL> proxy = False <EOL> except KeyError : <EOL> try : <EOL> apicls = classdict [ '<STR_LIT>' ] <EOL> proxy = True <EOL> except KeyError : <EOL> apicls = None <EOL> if apicls is not None : <EOL> if apicls . __name__ not in apiClassNamesToPyNodeNames : <EOL> apiClassNamesToPyNodeNames [ apicls . __name__ ] = classname <EOL> if not proxy and apicls not in bases : <EOL> bases = bases + ( classdict [ '<STR_LIT>' ] , ) <EOL> try : <EOL> classInfo = apiClassInfo [ apicls . __name__ ] <EOL> except KeyError : <EOL> _logger . info ( "<STR_LIT>" % ( apicls . __name__ ) ) <EOL> else : <EOL> herited = { } <EOL> for base in bases : <EOL> if base is not apicls : <EOL> for attr in dir ( base ) : <EOL> if attr not in herited : <EOL> herited [ attr ] = base <EOL> for methodName , info in classInfo [ '<STR_LIT>' ] . items ( ) : <EOL> try : <EOL> pymelName = info [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> removeAttrs . append ( methodName ) <EOL> except KeyError : <EOL> pymelName = methodName <EOL> pymelName , data = _getApiOverrideNameAndData ( classname , pymelName ) <EOL> overloadIndex = data . get ( '<STR_LIT>' , None ) <EOL> assert isinstance ( pymelName , str ) , "<STR_LIT>" % ( classname , methodName , pymelName ) <EOL> if pymelName not in herited : <EOL> if overloadIndex is not None : <EOL> if data . get ( '<STR_LIT>' , True ) : <EOL> if pymelName not in classdict : <EOL> method = wrapApiMethod ( apicls , methodName , newName = pymelName , proxy = proxy , overloadIndex = overloadIndex ) <EOL> if method : <EOL> classdict [ pymelName ] = method <EOL> if '<STR_LIT>' in classInfo : <EOL> for enumName , enum in classInfo [ '<STR_LIT>' ] . items ( ) : <EOL> classdict [ enumName ] = enum <EOL> if not proxy : <EOL> def __getattribute__ ( self , name ) : <EOL> if name in removeAttrs and name not in EXCLUDE_METHODS : <EOL> raise AttributeError , "<STR_LIT:'>" + classname + "<STR_LIT>" + name + "<STR_LIT:'>" <EOL> return super ( newcls , self ) . __getattribute__ ( name ) <EOL> classdict [ '<STR_LIT>' ] = __getattribute__ <EOL> if cls . _hasApiSetAttrBug ( apicls ) : <EOL> origSetAttr = apicls . __setattr__ <EOL> cls . _originalApiSetAttrs [ apicls ] = origSetAttr <EOL> def apiSetAttrWrap ( self , name , value ) : <EOL> if hasattr ( self . __class__ , name ) : <EOL> if hasattr ( getattr ( self . __class__ , name ) , '<STR_LIT>' ) : <EOL> return super ( apicls , self ) . __setattr__ ( name , value ) <EOL> return origSetAttr ( self , name , value ) <EOL> apicls . __setattr__ = apiSetAttrWrap <EOL> newcls = super ( MetaMayaTypeWrapper , cls ) . __new__ ( cls , classname , bases , classdict ) <EOL> def makeClassConstant ( attr ) : <EOL> try : <EOL> return MetaMayaTypeWrapper . ClassConstant ( attr ) <EOL> except Exception , e : <EOL> _logger . warn ( "<STR_LIT>" % ( classname , attr , e ) ) <EOL> if hasattr ( newcls , '<STR_LIT>' ) : <EOL> apicls = newcls . apicls <EOL> if apicls is not None : <EOL> constant = { } <EOL> for name , attr in newcls . __dict__ . iteritems ( ) : <EOL> if isinstance ( attr , apicls ) : <EOL> if name not in constant : <EOL> constant [ name ] = makeClassConstant ( attr ) <EOL> apiDict = dict ( inspect . getmembers ( apicls ) ) <EOL> for name , attr in apiDict . iteritems ( ) : <EOL> if isinstance ( attr , apicls ) : <EOL> if name not in constant : <EOL> constant [ name ] = makeClassConstant ( attr ) <EOL> mro = inspect . getmro ( newcls ) <EOL> for parentCls in mro : <EOL> if isinstance ( parentCls , MetaMayaTypeWrapper ) : <EOL> for name , attr in parentCls . __dict__ . iteritems ( ) : <EOL> if isinstance ( attr , MetaMayaTypeWrapper . ClassConstant ) : <EOL> if not name in constant : <EOL> constant [ name ] = makeClassConstant ( attr . value ) <EOL> for name , attr in constant . iteritems ( ) : <EOL> type . __setattr__ ( newcls , name , attr ) <EOL> if hasattr ( newcls , '<STR_LIT>' ) and not ApiTypeRegister . isRegistered ( newcls . apicls . __name__ ) : <EOL> ApiTypeRegister . register ( newcls . apicls . __name__ , newcls ) <EOL> return newcls <EOL> @ classmethod <EOL> def _hasApiSetAttrBug ( cls , apiClass ) : <EOL> """<STR_LIT>""" <EOL> class MyClass1 ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _bar = '<STR_LIT>' <EOL> def _setBar ( self , val ) : <EOL> self . _bar = val <EOL> def _getBar ( self ) : <EOL> return self . _bar <EOL> bar = property ( _getBar , _setBar ) <EOL> class MyClass2 ( MyClass1 , apiClass ) : pass <EOL> foo2 = MyClass2 ( ) <EOL> foo2 . bar = <NUM_LIT:7> <EOL> return bool ( foo2 . bar != <NUM_LIT:7> ) <EOL> class _MetaMayaCommandWrapper ( MetaMayaTypeWrapper ) : <EOL> """<STR_LIT>""" <EOL> _classDictKeyForMelCmd = None <EOL> def __new__ ( cls , classname , bases , classdict ) : <EOL> newcls = super ( _MetaMayaCommandWrapper , cls ) . __new__ ( cls , classname , bases , classdict ) <EOL> melCmdName , infoCmd = cls . getMelCmd ( classdict ) <EOL> classdict = { } <EOL> try : <EOL> cmdInfo = cmdlist [ melCmdName ] <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> try : <EOL> cmdModule = __import__ ( '<STR_LIT>' + cmdInfo [ '<STR_LIT:type>' ] , globals ( ) , locals ( ) , [ '<STR_LIT>' ] ) <EOL> func = getattr ( cmdModule , melCmdName ) <EOL> except ( AttributeError , TypeError ) : <EOL> func = getattr ( pmcmds , melCmdName ) <EOL> classdict [ '<STR_LIT>' ] = util . LazyDocString ( ( newcls , cls . docstring , ( melCmdName , ) , { } ) ) <EOL> classdict [ '<STR_LIT>' ] = staticmethod ( func ) <EOL> classdict [ '<STR_LIT>' ] = melCmdName <EOL> classdict [ '<STR_LIT>' ] = infoCmd <EOL> filterAttrs = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] + classdict . keys ( ) <EOL> filterAttrs += overrideMethods . get ( bases [ <NUM_LIT:0> ] . __name__ , [ ] ) <EOL> parentClasses = [ x . __name__ for x in inspect . getmro ( newcls ) [ <NUM_LIT:1> : ] ] <EOL> for flag , flagInfo in cmdInfo [ '<STR_LIT>' ] . items ( ) : <EOL> if flag in [ '<STR_LIT>' , '<STR_LIT>' ] or '<STR_LIT>' in flagInfo : <EOL> continue <EOL> if flagInfo . has_key ( '<STR_LIT>' ) : <EOL> modes = flagInfo [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in modes : <EOL> methodName = '<STR_LIT>' + util . capitalize ( flag ) <EOL> classToMelMap [ classname ] . append ( methodName ) <EOL> if methodName not in filterAttrs and ( not hasattr ( newcls , methodName ) or cls . isMelMethod ( methodName , parentClasses ) ) : <EOL> if not apiToMelData . has_key ( ( classname , methodName ) ) or apiToMelData [ ( classname , methodName ) ] . get ( '<STR_LIT>' , False ) or not apiToMelData [ ( classname , methodName ) ] . get ( '<STR_LIT>' , True ) : <EOL> returnFunc = None <EOL> if flagInfo . get ( '<STR_LIT>' , False ) : <EOL> returnFunc = flagInfo [ '<STR_LIT:args>' ] <EOL> if flagInfo . get ( '<STR_LIT>' , False ) : <EOL> if returnFunc : <EOL> origReturnFunc = returnFunc <EOL> returnFunc = lambda x : origReturnFunc ( x [ <NUM_LIT:0> ] ) <EOL> else : <EOL> returnFunc = lambda x : x [ <NUM_LIT:0> ] <EOL> wrappedMelFunc = makeQueryFlagMethod ( func , flag , methodName , <EOL> returnFunc = returnFunc ) <EOL> classdict [ methodName ] = wrappedMelFunc <EOL> if '<STR_LIT>' in modes or ( infoCmd and '<STR_LIT>' in modes ) : <EOL> if '<STR_LIT>' in modes : <EOL> methodName = '<STR_LIT>' + util . capitalize ( flag ) <EOL> else : <EOL> methodName = flag <EOL> classToMelMap [ classname ] . append ( methodName ) <EOL> if methodName not in filterAttrs and ( not hasattr ( newcls , methodName ) or cls . isMelMethod ( methodName , parentClasses ) ) : <EOL> if not apiToMelData . has_key ( ( classname , methodName ) ) or apiToMelData [ ( classname , methodName ) ] . get ( '<STR_LIT>' , False ) or not apiToMelData [ ( classname , methodName ) ] . get ( '<STR_LIT>' , True ) : <EOL> fixedFunc = fixCallbacks ( func , melCmdName ) <EOL> wrappedMelFunc = makeEditFlagMethod ( fixedFunc , flag , methodName ) <EOL> classdict [ methodName ] = wrappedMelFunc <EOL> for name , attr in classdict . iteritems ( ) : <EOL> type . __setattr__ ( newcls , name , attr ) <EOL> return newcls <EOL> @ classmethod <EOL> def getMelCmd ( cls , classdict ) : <EOL> """<STR_LIT>""" <EOL> return util . uncapitalize ( cls . __name__ ) , False <EOL> @ classmethod <EOL> def isMelMethod ( cls , methodName , parentClassList ) : <EOL> """<STR_LIT>""" <EOL> for classname in parentClassList : <EOL> if methodName in classToMelMap [ classname ] : <EOL> return True <EOL> return False <EOL> @ classmethod <EOL> def docstring ( cls , melCmdName ) : <EOL> try : <EOL> cmdInfo = cmdlist [ melCmdName ] <EOL> except KeyError : <EOL> classdoc = '<STR_LIT>' <EOL> else : <EOL> loadCmdDocCache ( ) <EOL> classdoc = '<STR_LIT>' % ( melCmdName , cmdInfo [ '<STR_LIT:description>' ] ) <EOL> return classdoc <EOL> class MetaMayaNodeWrapper ( _MetaMayaCommandWrapper ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , classname , bases , classdict ) : <EOL> nodeType = classdict . setdefault ( '<STR_LIT>' , util . uncapitalize ( classname ) ) <EOL> addMayaType ( nodeType ) <EOL> apicls = toApiFunctionSet ( nodeType ) <EOL> if apicls is not None : <EOL> classdict [ '<STR_LIT>' ] = apicls <EOL> PyNodeType = super ( MetaMayaNodeWrapper , cls ) . __new__ ( cls , classname , bases , classdict ) <EOL> ParentPyNode = [ x for x in bases if issubclass ( x , util . ProxyUnicode ) ] <EOL> assert len ( ParentPyNode ) , "<STR_LIT>" % ( classname , ParentPyNode , bases ) <EOL> addPyNodeType ( PyNodeType , ParentPyNode ) <EOL> return PyNodeType <EOL> @ classmethod <EOL> def getMelCmd ( cls , classdict ) : <EOL> """<STR_LIT>""" <EOL> nodeType = classdict [ '<STR_LIT>' ] <EOL> infoCmd = False <EOL> try : <EOL> nodeCmd = cmdcache . nodeTypeToNodeCommand [ nodeType ] <EOL> except KeyError : <EOL> try : <EOL> nodeCmd = nodeTypeToInfoCommand [ nodeType ] <EOL> infoCmd = True <EOL> except KeyError : <EOL> nodeCmd = nodeType <EOL> return nodeCmd , infoCmd <EOL> class MetaMayaUIWrapper ( _MetaMayaCommandWrapper ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , classname , bases , classdict ) : <EOL> uiType = classdict . setdefault ( '<STR_LIT>' , util . uncapitalize ( classname ) ) <EOL> return super ( MetaMayaUIWrapper , cls ) . __new__ ( cls , classname , bases , classdict ) <EOL> @ classmethod <EOL> def getMelCmd ( cls , classdict ) : <EOL> return classdict [ '<STR_LIT>' ] , False <EOL> class MetaMayaComponentWrapper ( MetaMayaTypeWrapper ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , classname , bases , classdict ) : <EOL> newcls = super ( MetaMayaComponentWrapper , cls ) . __new__ ( cls , classname , bases , classdict ) <EOL> apienum = getattr ( newcls , '<STR_LIT>' , None ) <EOL> if apienum : <EOL> if apienum not in apiEnumsToPyComponents : <EOL> apiEnumsToPyComponents [ apienum ] = [ newcls ] <EOL> else : <EOL> oldEntries = apiEnumsToPyComponents [ apienum ] <EOL> newEntries = [ ] <EOL> for oldEntry in oldEntries : <EOL> for base in bases : <EOL> if issubclass ( base , oldEntry ) : <EOL> break <EOL> else : <EOL> newEntries . append ( oldEntry ) <EOL> newEntries . append ( newcls ) <EOL> apiEnumsToPyComponents [ apienum ] = newEntries <EOL> return newcls <EOL> def addPyNodeCallback ( dynModule , mayaType , pyNodeTypeName , parentPyNodeTypeName , extraAttrs = None ) : <EOL> try : <EOL> ParentPyNode = getattr ( dynModule , parentPyNodeTypeName ) <EOL> except AttributeError : <EOL> _logger . debug ( "<STR_LIT>" % ( pyNodeTypeName , parentPyNodeTypeName , dynModule . __name__ ) ) <EOL> return <EOL> classDict = { '<STR_LIT>' : mayaType } <EOL> if extraAttrs : <EOL> classDict . update ( extraAttrs ) <EOL> if pyNodeTypeName in pyNodeNamesToPyNodes : <EOL> PyNodeType = pyNodeNamesToPyNodes [ pyNodeTypeName ] <EOL> else : <EOL> try : <EOL> PyNodeType = MetaMayaNodeWrapper ( pyNodeTypeName , ( ParentPyNode , ) , classDict ) <EOL> except TypeError , msg : <EOL> _logger . error ( "<STR_LIT>" % ( pyNodeTypeName , ParentPyNode . __name__ , msg ) ) <EOL> import new <EOL> PyNodeType = new . classobj ( pyNodeTypeName , ( ParentPyNode , ) , { } ) <EOL> PyNodeType . __module__ = dynModule . __name__ <EOL> setattr ( dynModule , pyNodeTypeName , PyNodeType ) <EOL> return PyNodeType <EOL> def addCustomPyNode ( dynModule , mayaType , extraAttrs = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> inheritance = apicache . getInheritance ( mayaType ) <EOL> except apicache . ManipNodeTypeError : <EOL> return <EOL> except Exception : <EOL> import traceback <EOL> _logger . debug ( traceback . format_exc ( ) ) <EOL> inheritance = None <EOL> if not inheritance or not util . isIterable ( inheritance ) : <EOL> _logger . warn ( "<STR_LIT>" % mayaType ) <EOL> else : <EOL> parent = '<STR_LIT>' <EOL> for node in inheritance : <EOL> nodeName = addPyNode ( dynModule , node , parent , extraAttrs = extraAttrs ) <EOL> parent = node <EOL> if '<STR_LIT>' in sys . modules : <EOL> setattr ( sys . modules [ '<STR_LIT>' ] , nodeName , getattr ( dynModule , nodeName ) ) <EOL> def addPyNode ( dynModule , mayaType , parentMayaType , extraAttrs = None ) : <EOL> """<STR_LIT>""" <EOL> pyNodeTypeName = str ( util . capitalize ( mayaType ) ) <EOL> parentPyNodeTypeName = str ( util . capitalize ( parentMayaType ) ) <EOL> if '<STR_LIT>' in sys . modules : <EOL> newType = addPyNodeCallback ( dynModule , mayaType , pyNodeTypeName , parentPyNodeTypeName , extraAttrs ) <EOL> setattr ( sys . modules [ '<STR_LIT>' ] , pyNodeTypeName , newType ) <EOL> else : <EOL> try : <EOL> dynModule [ pyNodeTypeName ] <EOL> except KeyError : <EOL> dynModule [ pyNodeTypeName ] = ( addPyNodeCallback , <EOL> ( dynModule , mayaType , pyNodeTypeName , parentPyNodeTypeName , extraAttrs ) ) <EOL> return pyNodeTypeName <EOL> def removePyNode ( dynModule , mayaType ) : <EOL> pyNodeTypeName = str ( util . capitalize ( mayaType ) ) <EOL> removePyNodeType ( pyNodeTypeName ) <EOL> _logger . debug ( '<STR_LIT>' % ( pyNodeTypeName , dynModule . __name__ ) ) <EOL> dynModule . __dict__ . pop ( pyNodeTypeName , None ) <EOL> try : <EOL> delattr ( dynModule . __class__ , pyNodeTypeName ) <EOL> except Exception : <EOL> pass <EOL> if '<STR_LIT>' in sys . modules : <EOL> try : <EOL> delattr ( sys . modules [ '<STR_LIT>' ] , pyNodeTypeName ) <EOL> except AttributeError : <EOL> pass <EOL> removeMayaType ( mayaType ) <EOL> def addPyNodeType ( pyNodeType , parentPyNode ) : <EOL> pyNodeNamesToPyNodes [ pyNodeType . __name__ ] = pyNodeType <EOL> pyNodeTypesHierarchy [ pyNodeType ] = parentPyNode <EOL> def removePyNodeType ( pyNodeTypeName ) : <EOL> pyNodeType = pyNodeNamesToPyNodes . pop ( pyNodeTypeName , None ) <EOL> pyNodeTypesHierarchy . pop ( pyNodeType , None ) <EOL> def clearPyNodeTypes ( ) : <EOL> pyNodeNamesToPyNodes . clear ( ) <EOL> pyNodeTypesHierarchy . clear ( ) <EOL> def addMayaType ( mayaType , apiType = None ) : <EOL> """<STR_LIT>""" <EOL> if apiType is None : <EOL> apiType = mayaTypeToApiType ( mayaType ) <EOL> global _apiCacheInst <EOL> _apiCacheInst . addMayaType ( mayaType , apiType , globals ( ) ) <EOL> _setApiCacheGlobals ( ) <EOL> def removeMayaType ( mayaType ) : <EOL> """<STR_LIT>""" <EOL> global _apiCacheInst <EOL> _apiCacheInst . removeMayaType ( mayaType , globals ( ) ) <EOL> _setApiCacheGlobals ( ) <EOL> VirtualClassInfo = util . namedtuple ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> class VirtualClassError ( Exception ) : pass <EOL> class VirtualClassManager ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _byVirtualClass = { } <EOL> self . _byParentClass = util . defaultdict ( list ) <EOL> def register ( self , vclass , nameRequired = False , isVirtual = '<STR_LIT>' , <EOL> preCreate = '<STR_LIT>' , <EOL> create = '<STR_LIT>' , <EOL> postCreate = '<STR_LIT>' , ) : <EOL> """<STR_LIT>""" <EOL> validSpecialAttrs = set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if isinstance ( isVirtual , basestring ) : <EOL> isVirtual = getattr ( vclass , isVirtual , None ) <EOL> if isinstance ( preCreate , basestring ) : <EOL> preCreate = getattr ( vclass , preCreate , None ) <EOL> if isinstance ( create , basestring ) : <EOL> create = getattr ( vclass , create , None ) <EOL> if isinstance ( postCreate , basestring ) : <EOL> postCreate = getattr ( vclass , postCreate , None ) <EOL> parentCls = None <EOL> for each_cls in inspect . getmro ( vclass ) : <EOL> if each_cls . __module__ . startswith ( '<STR_LIT>' ) : <EOL> parentCls = each_cls <EOL> break <EOL> else : <EOL> specialAttrs = [ x for x in each_cls . __dict__ . keys ( ) if x . startswith ( '<STR_LIT>' ) and x . endswith ( '<STR_LIT>' ) ] <EOL> badAttrs = set ( specialAttrs ) . difference ( validSpecialAttrs ) <EOL> if badAttrs : <EOL> raise ValueError , '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( badAttrs ) <EOL> assert parentCls , "<STR_LIT>" <EOL> vclass . __melnode__ = parentCls . __melnode__ <EOL> for vClassInfo in self . _byParentClass [ parentCls ] : <EOL> otherVcls = vClassInfo . vclass <EOL> if otherVcls . __name__ == vclass . __name__ and otherVcls . __module__ == vclass . __module__ : <EOL> self . unregister ( otherVcls ) <EOL> vClassInfo = VirtualClassInfo ( vclass , parentCls , nameRequired , isVirtual , preCreate , create , postCreate ) <EOL> self . _byParentClass [ parentCls ] . append ( vClassInfo ) <EOL> self . _byVirtualClass [ vclass ] = vClassInfo <EOL> def unregister ( self , vcls ) : <EOL> try : <EOL> vClassInfo = self . _byVirtualClass . pop ( vcls ) <EOL> except KeyError : <EOL> raise VirtualClassError ( '<STR_LIT>' % vcls ) <EOL> self . _byParentClass [ vClassInfo . parent ] . remove ( vClassInfo ) <EOL> def getVirtualClass ( self , baseClass , obj , name = None , fnDepend = None ) : <EOL> '''<STR_LIT>''' <EOL> vClasses = self . _byParentClass . get ( baseClass ) <EOL> if not vClasses : <EOL> return baseClass <EOL> for vClassInfo in reversed ( vClasses ) : <EOL> if vClassInfo . nameRequired and name is None : <EOL> if fnDepend is None : <EOL> fnDepend = api . MFnDependencyNode ( obj ) <EOL> name = fnDepend . name ( ) <EOL> if vClassInfo . isVirtual ( obj , name ) : <EOL> return vClassInfo . vclass <EOL> return baseClass <EOL> def getVirtualClassInfo ( self , vclass ) : <EOL> '''<STR_LIT>''' <EOL> return self . _byVirtualClass . get ( vclass ) <EOL> virtualClasses = VirtualClassManager ( ) <EOL> registerVirtualClass = virtualClasses . register <EOL> def isValidPyNode ( arg ) : <EOL> return pyNodeTypesHierarchy . has_key ( arg ) <EOL> def isValidPyNodeName ( arg ) : <EOL> return pyNodeNamesToPyNodes . has_key ( arg ) <EOL> def toApiTypeStr ( obj , default = None ) : <EOL> if isinstance ( obj , int ) : <EOL> return apiEnumsToApiTypes . get ( obj , default ) <EOL> elif isinstance ( obj , basestring ) : <EOL> return mayaTypesToApiTypes . get ( obj , default ) <EOL> elif isinstance ( obj , util . ProxyUnicode ) : <EOL> mayaType = getattr ( obj , '<STR_LIT>' , None ) <EOL> return mayaTypesToApiTypes . get ( mayaType , default ) <EOL> def toApiTypeEnum ( obj , default = None ) : <EOL> if isinstance ( obj , util . ProxyUnicode ) : <EOL> obj = getattr ( obj , '<STR_LIT>' , default ) <EOL> try : <EOL> return apiTypesToApiEnums [ obj ] <EOL> except KeyError : <EOL> return mayaTypesToApiEnums . get ( obj , default ) <EOL> def toApiFunctionSet ( obj ) : <EOL> if isinstance ( obj , basestring ) : <EOL> try : <EOL> return apiTypesToApiClasses [ obj ] <EOL> except KeyError : <EOL> if obj in mayaTypesToApiTypes : <EOL> mayaType = obj <EOL> apiType = mayaTypesToApiTypes [ obj ] <EOL> return _apiCacheInst . _getOrSetApiClass ( apiType , mayaType ) <EOL> else : <EOL> return None <EOL> elif isinstance ( obj , int ) : <EOL> try : <EOL> return apiTypesToApiClasses [ apiEnumsToApiTypes [ obj ] ] <EOL> except KeyError : <EOL> return None <EOL> def apiClassNameToPymelClassName ( apiName , allowGuess = True ) : <EOL> '''<STR_LIT>''' <EOL> pymelName = apiClassNamesToPyNodeNames . get ( apiName , None ) <EOL> if pymelName is None : <EOL> if allowGuess : <EOL> try : <EOL> pymelName = ApiTypeRegister . getPymelType ( apiName ) <EOL> except Exception : <EOL> pass <EOL> else : <EOL> pymelName = ApiTypeRegister . types . get ( apiName , None ) <EOL> return pymelName <EOL> def mayaTypeToApiType ( mayaType ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return mayaTypesToApiTypes [ mayaType ] <EOL> except KeyError : <EOL> apiType = None <EOL> if versions . current ( ) >= versions . v2012 : <EOL> import pymel . api . plugins as plugins <EOL> try : <EOL> inheritance = apicache . getInheritance ( mayaType , <EOL> checkManip3D = False ) <EOL> except Exception : <EOL> inheritance = None <EOL> if inheritance : <EOL> for mayaType in reversed ( inheritance [ : - <NUM_LIT:1> ] ) : <EOL> apiType = mayaTypesToApiTypes . get ( mayaType ) <EOL> if apiType : <EOL> break <EOL> if not apiType : <EOL> apiType = '<STR_LIT>' <EOL> with apicache . _GhostObjMaker ( mayaType ) as obj : <EOL> if obj is not None and api . isValidMObject ( obj ) : <EOL> apiType = obj . apiTypeStr ( ) <EOL> mayaTypesToApiTypes [ mayaType ] = apiType <EOL> return apiType <EOL> def isMayaType ( mayaType ) : <EOL> '''<STR_LIT>''' <EOL> return bool ( cmds . objectType ( tagFromType = mayaType ) ) <EOL> def getComponentTypes ( ) : <EOL> mfnCompBase = api . MFnComponent ( ) <EOL> mfnCompTypes = ( api . MFnSingleIndexedComponent ( ) , <EOL> api . MFnDoubleIndexedComponent ( ) , <EOL> api . MFnTripleIndexedComponent ( ) ) <EOL> if hasattr ( api . MFn , '<STR_LIT>' ) : <EOL> mfnCompTypes += ( api . MFnUint64SingleIndexedComponent ( ) , ) <EOL> componentTypes = { } <EOL> for compType in mfnCompTypes + ( mfnCompBase , ) : <EOL> componentTypes [ compType . type ( ) ] = [ ] <EOL> for apiEnum in apiEnumsToApiTypes : <EOL> if mfnCompBase . hasObj ( apiEnum ) : <EOL> for compType in mfnCompTypes : <EOL> if compType . hasObj ( apiEnum ) : <EOL> break <EOL> else : <EOL> compType = mfnCompBase <EOL> componentTypes [ compType . type ( ) ] . append ( apiEnum ) <EOL> return componentTypes </s>
