<s> import re , os . path , platform <EOL> from HTMLParser import HTMLParser <EOL> import pymel . util as util <EOL> import pymel . versions as versions <EOL> import plogging <EOL> from pymel . mayautils import getMayaLocation <EOL> try : <EOL> from pymel . util . external . BeautifulSoup import BeautifulSoup , NavigableString <EOL> except ImportError : <EOL> from BeautifulSoup import BeautifulSoup , NavigableString <EOL> from keyword import iskeyword as _iskeyword <EOL> FLAGMODES = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> _logger = plogging . getLogger ( __name__ ) <EOL> def mayaIsRunning ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> from maya . cmds import about <EOL> about ( version = True ) <EOL> return True <EOL> except : <EOL> return False <EOL> def mayaDocsLocation ( version = None ) : <EOL> docLocation = os . environ . get ( '<STR_LIT>' ) <EOL> if ( not docLocation and ( version is None or version == versions . installName ( ) ) <EOL> and mayaIsRunning ( ) ) : <EOL> from maya . cmds import showHelp <EOL> docLocation = showHelp ( "<STR_LIT>" , q = True , docs = True ) <EOL> while docLocation != "<STR_LIT>" and os . path . basename ( docLocation ) == "<STR_LIT>" : <EOL> docLocation = os . path . dirname ( docLocation ) <EOL> if not docLocation or not os . path . isdir ( docLocation ) : <EOL> docBaseDir = os . environ . get ( '<STR_LIT>' ) <EOL> if not docBaseDir : <EOL> docBaseDir = getMayaLocation ( version ) <EOL> if docBaseDir is None and version is not None : <EOL> docBaseDir = getMayaLocation ( None ) <EOL> _logger . warning ( "<STR_LIT>" % ( version , docBaseDir ) ) <EOL> if platform . system ( ) == '<STR_LIT>' : <EOL> docBaseDir = os . path . dirname ( os . path . dirname ( docBaseDir ) ) <EOL> docBaseDir = os . path . join ( docBaseDir , '<STR_LIT>' ) <EOL> if version : <EOL> short_version = versions . parseVersionStr ( version , extension = False ) <EOL> else : <EOL> short_version = versions . shortName ( ) <EOL> docLocation = os . path . join ( docBaseDir , '<STR_LIT>' % short_version , '<STR_LIT>' ) <EOL> return os . path . realpath ( docLocation ) <EOL> class CommandDocParser ( HTMLParser ) : <EOL> def __init__ ( self , command ) : <EOL> self . command = command <EOL> self . flags = { } <EOL> self . currFlag = '<STR_LIT>' <EOL> self . iData = <NUM_LIT:0> <EOL> self . pcount = <NUM_LIT:0> <EOL> self . active = False <EOL> self . description = '<STR_LIT>' <EOL> self . example = '<STR_LIT>' <EOL> self . emptyModeFlags = [ ] <EOL> HTMLParser . __init__ ( self ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . command ) <EOL> def startFlag ( self , data ) : <EOL> self . iData = <NUM_LIT:0> <EOL> self . flags [ self . currFlag ] = { '<STR_LIT>' : self . currFlag , '<STR_LIT>' : None , '<STR_LIT:args>' : None , <EOL> '<STR_LIT>' : None , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ ] } <EOL> def addFlagData ( self , data ) : <EOL> data = data . decode ( '<STR_LIT:utf-8>' ) <EOL> data = data . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) <EOL> if self . iData == <NUM_LIT:0> : <EOL> self . flags [ self . currFlag ] [ '<STR_LIT>' ] = data . lstrip ( '<STR_LIT>' ) <EOL> elif self . iData == <NUM_LIT:1> : <EOL> typemap = { <EOL> '<STR_LIT:string>' : unicode , <EOL> '<STR_LIT:float>' : float , <EOL> '<STR_LIT>' : float , <EOL> '<STR_LIT>' : float , <EOL> '<STR_LIT>' : float , <EOL> '<STR_LIT:int>' : int , <EOL> '<STR_LIT>' : int , <EOL> '<STR_LIT>' : int , <EOL> '<STR_LIT:index>' : int , <EOL> '<STR_LIT>' : int , <EOL> '<STR_LIT>' : bool , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:time>' : '<STR_LIT:time>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> args = [ x . strip ( ) for x in data . replace ( '<STR_LIT:[>' , '<STR_LIT>' ) . replace ( '<STR_LIT:]>' , '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) if x . strip ( ) ] <EOL> for i , arg in enumerate ( args ) : <EOL> if arg not in typemap : <EOL> _logger . error ( "<STR_LIT>" % ( self , self . currFlag , arg ) ) <EOL> else : <EOL> args [ i ] = typemap [ arg ] <EOL> numArgs = len ( args ) <EOL> if numArgs == <NUM_LIT:0> : <EOL> args = bool <EOL> elif numArgs == <NUM_LIT:1> : <EOL> args = args [ <NUM_LIT:0> ] <EOL> self . flags [ self . currFlag ] [ '<STR_LIT:args>' ] = args <EOL> self . flags [ self . currFlag ] [ '<STR_LIT>' ] = numArgs <EOL> else : <EOL> data = data . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> data = data . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> data = data . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> data = data . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> data = data . replace ( '<STR_LIT:\r\n>' , '<STR_LIT:U+0020>' ) . lstrip ( ) <EOL> data = data . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) . lstrip ( ) <EOL> data = data . strip ( '<STR_LIT>' ) <EOL> data = data . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) <EOL> self . flags [ self . currFlag ] [ '<STR_LIT>' ] += data <EOL> self . iData += <NUM_LIT:1> <EOL> def endFlag ( self ) : <EOL> try : <EOL> if not self . flags [ self . currFlag ] [ '<STR_LIT>' ] : <EOL> self . emptyModeFlags . append ( self . currFlag ) <EOL> elif self . emptyModeFlags : <EOL> basename = re . match ( '<STR_LIT>' , self . currFlag ) . groups ( ) [ <NUM_LIT:0> ] <EOL> modes = self . flags [ self . currFlag ] [ '<STR_LIT>' ] <EOL> self . emptyModeFlags . reverse ( ) <EOL> for flag in self . emptyModeFlags : <EOL> if re . match ( '<STR_LIT>' , flag ) . groups ( ) [ <NUM_LIT:0> ] == basename : <EOL> self . flags [ flag ] [ '<STR_LIT>' ] = modes <EOL> else : <EOL> break <EOL> self . emptyModeFlags = [ ] <EOL> except KeyError , msg : <EOL> pass <EOL> def handle_starttag ( self , tag , attrs ) : <EOL> attrmap = dict ( attrs ) <EOL> if not self . active : <EOL> if tag == '<STR_LIT:a>' : <EOL> name = attrmap . get ( '<STR_LIT:name>' , None ) <EOL> if name == '<STR_LIT>' : <EOL> self . active = '<STR_LIT>' <EOL> elif name == '<STR_LIT>' : <EOL> self . active = '<STR_LIT>' <EOL> elif tag == '<STR_LIT:a>' and '<STR_LIT:name>' in attrmap : <EOL> self . endFlag ( ) <EOL> newFlag = attrmap [ '<STR_LIT:name>' ] [ <NUM_LIT:4> : ] <EOL> newFlag = newFlag . lstrip ( '<STR_LIT:->' ) <EOL> self . currFlag = newFlag <EOL> self . iData = <NUM_LIT:0> <EOL> elif tag == '<STR_LIT>' : <EOL> mode = attrmap . get ( '<STR_LIT:title>' , None ) <EOL> if mode in FLAGMODES : <EOL> self . flags [ self . currFlag ] [ '<STR_LIT>' ] . append ( mode ) <EOL> elif tag == '<STR_LIT>' : <EOL> self . active = False <EOL> def handle_endtag ( self , tag ) : <EOL> if not self . active : <EOL> if tag == '<STR_LIT:p>' : <EOL> if self . pcount == <NUM_LIT:3> : <EOL> self . active = '<STR_LIT>' <EOL> else : <EOL> self . pcount += <NUM_LIT:1> <EOL> elif self . active == '<STR_LIT>' and tag == '<STR_LIT>' : <EOL> self . active = False <EOL> def handle_entityref ( self , name ) : <EOL> if self . active == '<STR_LIT>' : <EOL> self . example += r'<STR_LIT:">' <EOL> def handle_data ( self , data ) : <EOL> if not self . active : <EOL> return <EOL> elif self . active == '<STR_LIT>' : <EOL> if self . currFlag : <EOL> stripped = data . strip ( ) <EOL> if stripped == '<STR_LIT>' : <EOL> self . active = False <EOL> return <EOL> if data and stripped and stripped not in [ '<STR_LIT:(>' , '<STR_LIT:)>' , '<STR_LIT:=>' , '<STR_LIT>' ] : <EOL> if self . currFlag in self . flags : <EOL> self . addFlagData ( data ) <EOL> else : <EOL> self . startFlag ( data ) <EOL> elif self . active == '<STR_LIT>' : <EOL> data = data . replace ( '<STR_LIT:\r\n>' , '<STR_LIT:U+0020>' ) <EOL> data = data . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) <EOL> data = data . lstrip ( ) <EOL> data = data . strip ( '<STR_LIT:{}>' ) <EOL> data = data . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) <EOL> if '<STR_LIT:{>' not in data and '<STR_LIT:}>' not in data : <EOL> self . description += data <EOL> elif self . active == '<STR_LIT>' and data != '<STR_LIT>' : <EOL> data = data . replace ( '<STR_LIT:\r\n>' , '<STR_LIT:\n>' ) <EOL> self . example += data <EOL> class NodeHierarchyDocParser ( HTMLParser ) : <EOL> def parse ( self ) : <EOL> docloc = mayaDocsLocation ( self . version ) <EOL> if not os . path . isdir ( docloc ) : <EOL> raise IOError , "<STR_LIT>" % docloc <EOL> f = open ( os . path . join ( docloc , '<STR_LIT>' ) ) <EOL> try : <EOL> rawdata = f . read ( ) <EOL> finally : <EOL> f . close ( ) <EOL> if versions . v2011 <= versions . current ( ) < versions . v2012 : <EOL> soup = BeautifulSoup ( rawdata , convertEntities = '<STR_LIT:html>' ) <EOL> for tag in soup . findAll ( [ '<STR_LIT>' , '<STR_LIT:a>' ] ) : <EOL> self . handle_starttag ( tag . name , tag . attrs ) <EOL> data = tag . string <EOL> if data is not None : <EOL> self . handle_data ( data ) <EOL> else : <EOL> self . feed ( rawdata ) <EOL> return self . tree <EOL> def __init__ ( self , version = None ) : <EOL> self . version = version <EOL> self . currentTag = None <EOL> self . depth = <NUM_LIT:0> <EOL> self . lastDepth = - <NUM_LIT:1> <EOL> self . tree = None <EOL> self . currentLeaves = [ ] <EOL> HTMLParser . __init__ ( self ) <EOL> def handle_starttag ( self , tag , attrs ) : <EOL> self . currentTag = tag <EOL> def handle_data ( self , data ) : <EOL> _logger . debug ( "<STR_LIT>" % data ) <EOL> if self . currentTag == '<STR_LIT>' : <EOL> self . depth = data . count ( '<STR_LIT:>>' ) <EOL> elif self . currentTag == '<STR_LIT:a>' : <EOL> data = data . lstrip ( ) <EOL> if self . depth == <NUM_LIT:0> : <EOL> if self . tree is None : <EOL> self . tree = [ data ] <EOL> else : <EOL> return <EOL> elif self . depth == self . lastDepth and self . depth > <NUM_LIT:0> : <EOL> self . tree [ self . depth ] . append ( data ) <EOL> elif self . depth > self . lastDepth : <EOL> self . tree . append ( [ data ] ) <EOL> elif self . depth < self . lastDepth : <EOL> for i in range ( <NUM_LIT:0> , self . lastDepth - self . depth ) : <EOL> branch = self . tree . pop ( ) <EOL> currTree = self . tree [ - <NUM_LIT:1> ] <EOL> currTree . append ( branch ) <EOL> self . tree [ self . depth ] . append ( data ) <EOL> else : <EOL> return <EOL> self . lastDepth = self . depth <EOL> self . depth = <NUM_LIT:0> <EOL> def printTree ( tree , depth = <NUM_LIT:0> ) : <EOL> for branch in tree : <EOL> if util . isIterable ( branch ) : <EOL> printTree ( branch , depth + <NUM_LIT:1> ) <EOL> else : <EOL> _logger . info ( '<STR_LIT>' % ( '<STR_LIT>' * depth , branch ) ) <EOL> class CommandModuleDocParser ( HTMLParser ) : <EOL> def parse ( self ) : <EOL> f = open ( os . path . join ( self . docloc , '<STR_LIT>' + self . category + '<STR_LIT>' ) ) <EOL> self . feed ( f . read ( ) ) <EOL> f . close ( ) <EOL> return self . cmdList <EOL> def __init__ ( self , category , version = None ) : <EOL> self . cmdList = [ ] <EOL> self . category = category <EOL> self . version = version <EOL> docloc = mayaDocsLocation ( '<STR_LIT>' if self . version == '<STR_LIT>' else self . version ) <EOL> self . docloc = docloc <EOL> HTMLParser . __init__ ( self ) <EOL> def handle_starttag ( self , tag , attrs ) : <EOL> try : <EOL> attrs = attrs [ <NUM_LIT:0> ] <EOL> if tag == '<STR_LIT:a>' and attrs [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> cmd = attrs [ <NUM_LIT:1> ] . split ( "<STR_LIT:'>" ) [ <NUM_LIT:1> ] . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> self . cmdList . append ( cmd ) <EOL> except IndexError : return <EOL> class ApiDocParser ( object ) : <EOL> OBSOLETE_MSG = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> DEPRECATED_MSG = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> PYMEL_ENUM_DEFAULTS = { '<STR_LIT>' : ( '<STR_LIT:object>' , ) } <EOL> def __init__ ( self , apiModule , version = None , verbose = False , enumClass = tuple , <EOL> docLocation = None ) : <EOL> self . version = versions . installName ( ) if version is None else version <EOL> self . apiModule = apiModule <EOL> self . verbose = verbose <EOL> if docLocation is None : <EOL> docLocation = mayaDocsLocation ( '<STR_LIT>' if self . version == '<STR_LIT>' else self . version ) <EOL> self . docloc = docLocation <EOL> self . enumClass = enumClass <EOL> if not os . path . isdir ( self . docloc ) : <EOL> raise IOError , "<STR_LIT>" % self . docloc <EOL> self . enums = { } <EOL> self . pymelEnums = { } <EOL> self . methods = util . defaultdict ( list ) <EOL> self . currentMethod = None <EOL> self . badEnums = [ ] <EOL> def formatMsg ( self , * args ) : <EOL> return self . apiClassName + '<STR_LIT:.>' + self . currentMethod + '<STR_LIT>' + '<STR_LIT:U+0020>' . join ( [ str ( x ) for x in args ] ) <EOL> def xprint ( self , * args ) : <EOL> if self . verbose : <EOL> print self . formatMsg ( * args ) <EOL> def getPymelMethodNames ( self ) : <EOL> setReg = re . compile ( '<STR_LIT>' ) <EOL> allFnMembers = self . methods . keys ( ) <EOL> pymelNames = { } <EOL> pairs = { } <EOL> pairsList = [ ] <EOL> def addSetGetPair ( setmethod , getMethod ) : <EOL> pairsList . append ( ( setMethod , getMethod ) ) <EOL> pairs [ setMethod ] = getMethod <EOL> for info in self . methods [ setMethod ] : <EOL> info [ '<STR_LIT>' ] = ( getMethod , True ) <EOL> pairs [ getMethod ] = setMethod <EOL> for info in self . methods [ getMethod ] : <EOL> info [ '<STR_LIT>' ] = ( setMethod , False ) <EOL> for member in allFnMembers : <EOL> m = setReg . match ( member ) <EOL> if m : <EOL> basename = m . group ( <NUM_LIT:1> ) <EOL> origGetMethod = util . uncapitalize ( basename ) <EOL> setMethod = member <EOL> if origGetMethod in allFnMembers : <EOL> if re . match ( '<STR_LIT>' , origGetMethod ) : <EOL> newSetMethod = '<STR_LIT>' + origGetMethod [ <NUM_LIT:2> : ] <EOL> pymelNames [ setMethod ] = newSetMethod <EOL> for info in self . methods [ setMethod ] : <EOL> info [ '<STR_LIT>' ] = newSetMethod <EOL> addSetGetPair ( setMethod , origGetMethod ) <EOL> else : <EOL> newGetMethod = '<STR_LIT:g>' + setMethod [ <NUM_LIT:1> : ] <EOL> pymelNames [ origGetMethod ] = newGetMethod <EOL> for info in self . methods [ origGetMethod ] : <EOL> info [ '<STR_LIT>' ] = newGetMethod <EOL> addSetGetPair ( setMethod , origGetMethod ) <EOL> else : <EOL> getMethod = '<STR_LIT>' + basename <EOL> isMethod = '<STR_LIT>' + basename <EOL> if getMethod in allFnMembers : <EOL> addSetGetPair ( setMethod , getMethod ) <EOL> elif isMethod in allFnMembers : <EOL> addSetGetPair ( setMethod , isMethod ) <EOL> return pymelNames , pairsList <EOL> def getClassFilename ( self ) : <EOL> filename = '<STR_LIT:class>' <EOL> for tok in re . split ( '<STR_LIT>' , self . apiClassName ) : <EOL> if tok : <EOL> if tok [ <NUM_LIT:0> ] . isupper ( ) : <EOL> filename += '<STR_LIT:_>' + tok . lower ( ) <EOL> else : <EOL> filename += tok <EOL> return filename <EOL> _capitalizedRe = re . compile ( '<STR_LIT>' ) <EOL> def _apiEnumNamesToPymelEnumNames ( self , apiEnumNames ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( apiEnumNames , util . Enum ) : <EOL> apiEnumNames = apiEnumNames . _keys . keys ( ) <EOL> if len ( apiEnumNames ) > <NUM_LIT:1> : <EOL> splitEnums = [ [ y for y in self . _capitalizedRe . split ( x ) if y ] for x in apiEnumNames ] <EOL> splitZip = zip ( * splitEnums ) <EOL> for partList in splitZip : <EOL> if tuple ( [ partList [ <NUM_LIT:0> ] ] * len ( partList ) ) == partList : <EOL> [ x . pop ( <NUM_LIT:0> ) for x in splitEnums ] <EOL> else : break <EOL> joinedEnums = [ util . uncapitalize ( '<STR_LIT>' . join ( x ) , preserveAcronymns = True ) for x in splitEnums ] <EOL> for i , enum in enumerate ( joinedEnums ) : <EOL> if _iskeyword ( enum ) : <EOL> joinedEnums [ i ] = enum + '<STR_LIT:_>' <EOL> self . xprint ( "<STR_LIT>" , enum ) <EOL> elif enum [ <NUM_LIT:0> ] . isdigit ( ) : <EOL> joinedEnums [ i ] = '<STR_LIT:k>' + enum <EOL> self . xprint ( "<STR_LIT>" , enum ) <EOL> return dict ( zip ( apiEnumNames , joinedEnums ) ) <EOL> else : <EOL> return dict ( ( name , name ) for name in apiEnumNames ) <EOL> def _apiEnumToPymelEnum ( self , apiEnum , apiToPymelNames = None ) : <EOL> defaultsSet = self . PYMEL_ENUM_DEFAULTS . get ( apiEnum . name , set ( ) ) <EOL> defaults = { } <EOL> if apiToPymelNames is None : <EOL> apiToPymelNames = self . _apiEnumNamesToPymelEnumNames ( apiEnum ) <EOL> pymelKeyDict = { } <EOL> docs = dict ( apiEnum . _docs ) <EOL> for apiName , val in apiEnum . _keys . iteritems ( ) : <EOL> pymelKeyDict [ apiName ] = val <EOL> pymelName = apiToPymelNames [ apiName ] <EOL> pymelKeyDict [ pymelName ] = val <EOL> doc = apiEnum . _docs . get ( apiName ) <EOL> if doc : <EOL> docs [ pymelName ] = doc <EOL> if ( pymelName in defaultsSet <EOL> or ( val not in defaults and apiName == apiEnum . getKey ( val ) ) ) : <EOL> defaults [ val ] = pymelName <EOL> return util . Enum ( apiEnum . name , pymelKeyDict , multiKeys = True , <EOL> defaultKeys = defaults ) <EOL> def handleEnums ( self , type ) : <EOL> missingTypes = [ '<STR_LIT>' ] <EOL> otherTypes = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:float>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:bool>' , <EOL> '<STR_LIT:int>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> notTypes = [ '<STR_LIT>' ] <EOL> if type is None : return type <EOL> if '<STR_LIT>' in type : <EOL> type = self . enumClass ( type . split ( '<STR_LIT>' ) ) <EOL> elif type in self . enums : <EOL> type = self . enumClass ( [ self . apiClassName , type ] ) <EOL> elif type [ <NUM_LIT:0> ] . isupper ( ) and '<STR_LIT>' not in type and not hasattr ( self . apiModule , type ) and type not in otherTypes + missingTypes + notTypes : <EOL> type = self . enumClass ( [ self . apiClassName , type ] ) <EOL> if type not in self . badEnums : <EOL> self . badEnums . append ( type ) <EOL> _logger . warn ( "<STR_LIT>" , type ) <EOL> else : <EOL> type = str ( type ) <EOL> return type <EOL> def handleEnumDefaults ( self , default , type ) : <EOL> if default is None : return default <EOL> if isinstance ( type , self . enumClass ) : <EOL> if '<STR_LIT>' in default : <EOL> apiClass , enumConst = default . split ( '<STR_LIT>' ) <EOL> assert apiClass == type [ <NUM_LIT:0> ] <EOL> else : <EOL> enumConst = default <EOL> return self . enumClass ( [ type [ <NUM_LIT:0> ] , type [ <NUM_LIT:1> ] , enumConst ] ) <EOL> return default <EOL> def getOperatorName ( self , methodName ) : <EOL> op = methodName [ <NUM_LIT:8> : ] <EOL> if op == '<STR_LIT:=>' : <EOL> methodName = None <EOL> else : <EOL> methodName = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:*>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:+>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:->' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:/>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } . get ( op , None ) <EOL> return methodName <EOL> def isSetMethod ( self ) : <EOL> if re . match ( '<STR_LIT>' , self . currentMethod ) : <EOL> return True <EOL> else : <EOL> return False <EOL> def isGetMethod ( self ) : <EOL> if re . match ( '<STR_LIT>' , self . currentMethod ) : <EOL> return True <EOL> else : <EOL> return False <EOL> def parseTypes ( self , proto ) : <EOL> defaults = { } <EOL> names = [ ] <EOL> types = { } <EOL> typeQualifiers = { } <EOL> tmpTypes = [ ] <EOL> for paramtype in proto . findAll ( '<STR_LIT>' , ** { '<STR_LIT:class>' : '<STR_LIT>' } ) : <EOL> buf = [ ] <EOL> [ buf . extend ( x . split ( ) ) for x in paramtype . findAll ( text = True ) ] <EOL> buf = [ x . strip ( ) . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) for x in buf if x . strip ( ) ] <EOL> i = <NUM_LIT:0> <EOL> for i , each in enumerate ( buf ) : <EOL> if each not in [ '<STR_LIT:*>' , '<STR_LIT:&>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> argtype = buf . pop ( i ) <EOL> break <EOL> else : <EOL> argtype = '<STR_LIT:int>' <EOL> if '<STR_LIT>' in buf and argtype in ( '<STR_LIT>' , '<STR_LIT:int>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) : <EOL> argtype = '<STR_LIT:u>' + argtype <EOL> argtype = self . handleEnums ( argtype ) <EOL> tmpTypes . append ( ( argtype , buf ) ) <EOL> i = <NUM_LIT:0> <EOL> for paramname in proto . findAll ( '<STR_LIT>' , ** { '<STR_LIT:class>' : '<STR_LIT>' } ) : <EOL> buf = [ x . strip ( ) . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) for x in paramname . findAll ( text = True ) if x . strip ( ) not in [ '<STR_LIT>' , '<STR_LIT:U+002C>' ] ] <EOL> if not buf : continue <EOL> argname = buf [ <NUM_LIT:0> ] <EOL> data = buf [ <NUM_LIT:1> : ] <EOL> type , qualifiers = tmpTypes [ i ] <EOL> default = None <EOL> joined = '<STR_LIT>' . join ( data ) . strip ( ) <EOL> if joined : <EOL> joined = joined . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) <EOL> brackets , default = re . search ( '<STR_LIT>' , joined ) . groups ( ) <EOL> if brackets : <EOL> numbuf = re . split ( r'<STR_LIT>' , brackets ) <EOL> if len ( numbuf ) > <NUM_LIT:1> : <EOL> type = type + '<STR_LIT>' + numbuf [ <NUM_LIT:1> ] <EOL> else : <EOL> print "<STR_LIT>" , repr ( brackets ) , joined <EOL> if default is not None : <EOL> try : <EOL> default = { <EOL> '<STR_LIT:true>' : True , <EOL> '<STR_LIT:false>' : False , <EOL> '<STR_LIT>' : None <EOL> } [ default ] <EOL> except KeyError : <EOL> try : <EOL> if type in [ '<STR_LIT:int>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> default = int ( default ) <EOL> elif type in [ '<STR_LIT:float>' , '<STR_LIT>' ] : <EOL> if '<STR_LIT:/>' in default : <EOL> default = eval ( default ) <EOL> elif default . endswith ( '<STR_LIT:F>' ) : <EOL> default = float ( default [ : - <NUM_LIT:1> ] ) <EOL> else : <EOL> default = float ( default ) <EOL> else : <EOL> default = self . handleEnumDefaults ( default , type ) <EOL> except ValueError : <EOL> default = self . handleEnumDefaults ( default , type ) <EOL> self . xprint ( '<STR_LIT>' , default ) <EOL> defaults [ argname ] = default <EOL> types [ argname ] = type <EOL> typeQualifiers [ argname ] = qualifiers <EOL> names . append ( argname ) <EOL> i += <NUM_LIT:1> <EOL> assert sorted ( names ) == sorted ( types . keys ( ) ) , '<STR_LIT>' % ( sorted ( names ) , sorted ( types . keys ( ) ) ) <EOL> return names , types , typeQualifiers , defaults <EOL> def parseEnums ( self , proto ) : <EOL> enumValues = { } <EOL> enumDocs = { } <EOL> for em in proto . findNextSiblings ( '<STR_LIT>' , limit = <NUM_LIT:1> ) [ <NUM_LIT:0> ] . findAll ( '<STR_LIT>' ) : <EOL> enumKey = str ( em . contents [ - <NUM_LIT:1> ] ) <EOL> try : <EOL> enumVal = getattr ( self . apiClass , enumKey ) <EOL> except : <EOL> _logger . warn ( "<STR_LIT>" % ( self . apiClassName , enumKey , self . currentMethod ) ) <EOL> enumVal = None <EOL> enumValues [ enumKey ] = enumVal <EOL> docItem = em . next . next . next . next . next <EOL> if isinstance ( docItem , NavigableString ) : <EOL> enumDocs [ enumKey ] = str ( docItem ) . strip ( ) <EOL> else : <EOL> enumDocs [ enumKey ] = str ( docItem . contents [ <NUM_LIT:0> ] ) . strip ( ) <EOL> apiEnum = util . Enum ( self . currentMethod , enumValues , multiKeys = True ) <EOL> apiToPymelNames = self . _apiEnumNamesToPymelEnumNames ( apiEnum ) <EOL> pymelEnum = self . _apiEnumToPymelEnum ( apiEnum , <EOL> apiToPymelNames = apiToPymelNames ) <EOL> for apiName , pymelName in apiToPymelNames . iteritems ( ) : <EOL> apiDoc = enumDocs . get ( apiName ) <EOL> if apiDoc is not None : <EOL> enumDocs [ pymelName ] = apiDoc <EOL> enumInfo = { '<STR_LIT>' : apiEnum , <EOL> '<STR_LIT>' : enumDocs , <EOL> } <EOL> return enumInfo , pymelEnum <EOL> def isObsolete ( self , proto ) : <EOL> addendum = proto . findNextSiblings ( '<STR_LIT>' , limit = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> if addendum . findAll ( text = lambda x : x in self . OBSOLETE_MSG ) : <EOL> self . xprint ( "<STR_LIT>" ) <EOL> self . currentMethod = None <EOL> return True <EOL> return False <EOL> def parseMethodArgs ( self , proto , returnType , names , types , typeQualifiers ) : <EOL> directions = { } <EOL> docs = { } <EOL> deprecated = False <EOL> returnDoc = '<STR_LIT>' <EOL> addendum = proto . findNextSiblings ( '<STR_LIT>' , limit = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> if addendum . findAll ( text = lambda x : x in self . DEPRECATED_MSG ) : <EOL> self . xprint ( "<STR_LIT>" ) <EOL> deprecated = True <EOL> methodDoc = '<STR_LIT:U+0020>' . join ( addendum . p . findAll ( text = True ) ) . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) <EOL> tmpDirs = [ ] <EOL> tmpNames = [ ] <EOL> tmpDocs = [ ] <EOL> if self . version and int ( self . version . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] ) < <NUM_LIT> : <EOL> extraInfos = addendum . findAll ( '<STR_LIT>' ) <EOL> else : <EOL> extraInfos = addendum . findAll ( lambda tag : tag . name == '<STR_LIT>' and ( '<STR_LIT:class>' , '<STR_LIT>' ) not in tag . attrs and ( '<STR_LIT:class>' , '<STR_LIT:user>' ) not in tag . attrs ) <EOL> if extraInfos : <EOL> if self . version and int ( self . version . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] ) < <NUM_LIT> : <EOL> extraInfo = extraInfos [ <NUM_LIT:0> ] <EOL> tmpDirs += extraInfo . findAll ( text = lambda text : text in [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> for tr in extraInfo . findAll ( '<STR_LIT>' ) : <EOL> assert tr , "<STR_LIT>" <EOL> td = tr . findNext ( lambda tag : tag . name == '<STR_LIT>' and ( '<STR_LIT:class>' , '<STR_LIT>' ) in tag . attrs ) <EOL> assert td , "<STR_LIT>" <EOL> name = td . findAll ( text = True , limit = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> tmpNames . append ( name ) <EOL> tds = extraInfo . findAll ( lambda tag : tag . name == '<STR_LIT>' and not any ( [ item for item in tag . attrs if '<STR_LIT:class>' in item ] ) ) <EOL> for doc in [ td . findAll ( text = lambda text : text . strip ( ) , recursive = False ) for td in tds ] : <EOL> tmpDocs . append ( '<STR_LIT>' . join ( doc ) ) <EOL> if not tmpDocs : <EOL> tmpDocs = [ '<STR_LIT>' ] * len ( tmpDirs ) <EOL> else : <EOL> for extraInfo in extraInfos : <EOL> for tr in extraInfo . findAll ( '<STR_LIT>' ) : <EOL> assert tr , "<STR_LIT>" <EOL> tds = tr . findAll ( lambda tag : tag . name == '<STR_LIT>' ) <EOL> assert tds , "<STR_LIT>" <EOL> assert len ( tds ) == <NUM_LIT:3> , "<STR_LIT>" % len ( tds ) <EOL> tt = tds [ <NUM_LIT:0> ] . findNext ( lambda tag : tag . name == '<STR_LIT>' ) <EOL> dir = tt . findAll ( text = True , limit = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> tmpDirs . append ( dir . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) ) <EOL> name = tds [ <NUM_LIT:1> ] . findAll ( text = True , limit = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> tmpNames . append ( name . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) ) <EOL> doc = '<STR_LIT>' . join ( tds [ <NUM_LIT:2> ] . findAll ( text = True ) ) <EOL> tmpDocs . append ( doc . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) ) <EOL> assert len ( tmpDirs ) == len ( tmpNames ) == len ( tmpDocs ) , '<STR_LIT>' % ( tmpDirs , tmpNames , tmpDocs ) <EOL> assert sorted ( tmpNames ) == sorted ( typeQualifiers . keys ( ) ) , '<STR_LIT>' % ( sorted ( tmpNames ) , sorted ( typeQualifiers . keys ( ) ) ) <EOL> for name , dir , doc in zip ( tmpNames , tmpDirs , tmpDocs ) : <EOL> if dir == '<STR_LIT>' : <EOL> if re . search ( r'<STR_LIT>' , doc ) : <EOL> _logger . warn ( "<STR_LIT>" % ( <EOL> self . apiClassName , self . currentMethod , '<STR_LIT:U+002CU+0020>' . join ( names ) , name , doc ) ) <EOL> dir = '<STR_LIT>' <EOL> elif not re . match ( '<STR_LIT>' , self . currentMethod ) and '<STR_LIT:&>' in typeQualifiers [ name ] and types [ name ] in [ '<STR_LIT:int>' , '<STR_LIT>' , '<STR_LIT:float>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> _logger . warn ( "<STR_LIT>" % ( <EOL> self . apiClassName , self . currentMethod , '<STR_LIT:U+002CU+0020>' . join ( names ) , name , types [ name ] , doc ) ) <EOL> dir = '<STR_LIT>' <EOL> else : <EOL> dir = '<STR_LIT>' <EOL> elif dir == '<STR_LIT>' : <EOL> if types [ name ] == '<STR_LIT>' : <EOL> _logger . warn ( "<STR_LIT>" % ( <EOL> self . apiClassName , self . currentMethod , '<STR_LIT:U+002CU+0020>' . join ( names ) , name ) ) <EOL> dir = '<STR_LIT>' <EOL> else : <EOL> dir = '<STR_LIT>' <EOL> elif dir == '<STR_LIT>' : <EOL> dir = '<STR_LIT>' <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % dir ) <EOL> assert name in names <EOL> directions [ name ] = dir <EOL> docs [ name ] = doc . replace ( '<STR_LIT>' , '<STR_LIT:U+0020>' ) . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) <EOL> if returnType : <EOL> try : <EOL> returnDocBuf = addendum . findAll ( '<STR_LIT>' , limit = <NUM_LIT:1> , ** { '<STR_LIT:class>' : '<STR_LIT>' } ) [ <NUM_LIT:0> ] . findAll ( text = True ) <EOL> except IndexError : <EOL> pass <EOL> else : <EOL> if returnDocBuf : <EOL> returnDoc = '<STR_LIT>' . join ( returnDocBuf [ <NUM_LIT:1> : ] ) . replace ( '<STR_LIT>' , '<STR_LIT:U+0020>' ) . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) <EOL> self . xprint ( '<STR_LIT>' , repr ( returnDoc ) ) <EOL> return directions , docs , methodDoc , returnDoc , deprecated <EOL> def getMethodNameAndOutput ( self , proto ) : <EOL> memb = proto . findAll ( '<STR_LIT>' , ** { '<STR_LIT:class>' : '<STR_LIT>' } ) [ <NUM_LIT:0> ] <EOL> buf = [ x . strip ( ) . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) for x in memb . findAll ( text = True ) ] <EOL> if len ( buf ) == <NUM_LIT:1> : <EOL> buf = [ x for x in buf [ <NUM_LIT:0> ] . split ( ) if x not in [ '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> if len ( buf ) == <NUM_LIT:1> : <EOL> returnType = None <EOL> methodName = buf [ <NUM_LIT:0> ] <EOL> else : <EOL> returnType = '<STR_LIT>' . join ( buf [ : - <NUM_LIT:1> ] ) <EOL> methodName = buf [ - <NUM_LIT:1> ] <EOL> else : <EOL> returnType = buf [ <NUM_LIT:0> ] <EOL> methodName = buf [ <NUM_LIT:1> ] <EOL> buf = [ x for x in buf [ <NUM_LIT:0> ] . split ( ) if x not in [ '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> if len ( buf ) > <NUM_LIT:1> : <EOL> returnType += buf [ <NUM_LIT:0> ] <EOL> methodName = buf [ <NUM_LIT:1> ] <EOL> methodName = methodName . split ( '<STR_LIT>' ) [ - <NUM_LIT:1> ] <EOL> if methodName . startswith ( '<STR_LIT>' ) : <EOL> methodName = self . getOperatorName ( methodName ) <EOL> else : <EOL> if methodName . startswith ( '<STR_LIT>' ) or methodName == self . apiClassName : <EOL> methodName = None <EOL> if returnType in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> returnType = None <EOL> else : <EOL> returnType = self . handleEnums ( returnType ) <EOL> return methodName , returnType <EOL> def iterProto ( self , apiClassName ) : <EOL> self . apiClassName = apiClassName <EOL> self . apiClass = getattr ( self . apiModule , self . apiClassName ) <EOL> self . docfile = self . getClassPath ( ) <EOL> _logger . info ( "<STR_LIT>" , self . docfile ) <EOL> f = open ( self . docfile ) <EOL> soup = BeautifulSoup ( f . read ( ) , convertEntities = '<STR_LIT:html>' ) <EOL> f . close ( ) <EOL> for proto in soup . body . findAll ( '<STR_LIT>' , ** { '<STR_LIT:class>' : '<STR_LIT>' } ) : <EOL> yield proto <EOL> def getClassPath ( self ) : <EOL> filename = self . getClassFilename ( ) + '<STR_LIT>' <EOL> apiBase = os . path . join ( self . docloc , '<STR_LIT>' ) <EOL> path = os . path . join ( apiBase , filename ) <EOL> if not os . path . isfile ( path ) : <EOL> path = os . path . join ( apiBase , '<STR_LIT>' , filename ) <EOL> return path <EOL> def parse ( self , apiClassName ) : <EOL> self . enums = { } <EOL> self . pymelEnums = { } <EOL> self . methods = util . defaultdict ( list ) <EOL> self . currentMethod = None <EOL> self . badEnums = [ ] <EOL> for proto in self . iterProto ( apiClassName ) : <EOL> methodName , returnType = self . getMethodNameAndOutput ( proto ) <EOL> if methodName is None : continue <EOL> self . currentMethod = str ( methodName ) <EOL> if self . currentMethod == '<STR_LIT>' : <EOL> continue <EOL> if returnType == '<STR_LIT>' : <EOL> self . xprint ( "<STR_LIT>" , returnType ) <EOL> try : <EOL> enumData = self . parseEnums ( proto ) <EOL> self . enums [ self . currentMethod ] = enumData [ <NUM_LIT:0> ] <EOL> self . pymelEnums [ self . currentMethod ] = enumData [ <NUM_LIT:1> ] <EOL> except AttributeError , msg : <EOL> _logger . error ( "<STR_LIT>" , msg ) <EOL> import traceback <EOL> _logger . debug ( traceback . format_exc ( ) ) <EOL> else : <EOL> self . xprint ( "<STR_LIT>" , returnType ) <EOL> static = False <EOL> try : <EOL> res = proto . findAll ( '<STR_LIT:code>' ) <EOL> if res : <EOL> code = res [ - <NUM_LIT:1> ] . string <EOL> if code and code . strip ( ) == '<STR_LIT>' : <EOL> static = True <EOL> except IndexError : pass <EOL> if self . isObsolete ( proto ) : <EOL> continue <EOL> names , types , typeQualifiers , defaults = self . parseTypes ( proto ) <EOL> try : <EOL> directions , docs , methodDoc , returnDoc , deprecated = self . parseMethodArgs ( proto , returnType , names , types , typeQualifiers ) <EOL> except AssertionError , msg : <EOL> _logger . error ( self . formatMsg ( "<STR_LIT>" , str ( msg ) ) ) <EOL> continue <EOL> except AttributeError : <EOL> import traceback <EOL> _logger . error ( self . formatMsg ( traceback . format_exc ( ) ) ) <EOL> continue <EOL> argInfo = { } <EOL> argList = [ ] <EOL> inArgs = [ ] <EOL> outArgs = [ ] <EOL> for argname in names [ : ] : <EOL> type = types [ argname ] <EOL> if argname not in directions : <EOL> self . xprint ( "<STR_LIT>" ) <EOL> directions [ argname ] = '<STR_LIT>' <EOL> direction = directions [ argname ] <EOL> doc = docs . get ( argname , '<STR_LIT>' ) <EOL> if type == '<STR_LIT>' : <EOL> types . pop ( argname ) <EOL> defaults . pop ( argname , None ) <EOL> directions . pop ( argname , None ) <EOL> docs . pop ( argname , None ) <EOL> idx = names . index ( argname ) <EOL> names . pop ( idx ) <EOL> else : <EOL> if direction == '<STR_LIT>' : <EOL> inArgs . append ( argname ) <EOL> else : <EOL> outArgs . append ( argname ) <EOL> argInfo [ argname ] = { '<STR_LIT:type>' : type , '<STR_LIT>' : doc } <EOL> if self . isGetMethod ( ) and not returnType and not outArgs : <EOL> for argname in names : <EOL> if '<STR_LIT:&>' in typeQualifiers [ argname ] : <EOL> doc = docs . get ( argname , '<STR_LIT>' ) <EOL> directions [ argname ] = '<STR_LIT>' <EOL> idx = inArgs . index ( argname ) <EOL> inArgs . pop ( idx ) <EOL> outArgs . append ( argname ) <EOL> _logger . warn ( "<STR_LIT>" % ( <EOL> self . apiClassName , self . currentMethod , '<STR_LIT:U+002CU+0020>' . join ( names ) , argname , doc ) ) <EOL> for argname in names : <EOL> type = types [ argname ] <EOL> self . xprint ( "<STR_LIT>" , directions ) <EOL> direction = directions [ argname ] <EOL> data = ( argname , type , direction ) <EOL> self . xprint ( "<STR_LIT>" , data ) <EOL> argList . append ( data ) <EOL> methodInfo = { '<STR_LIT>' : argInfo , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : returnType , '<STR_LIT>' : returnDoc } , <EOL> '<STR_LIT:args>' : argList , <EOL> '<STR_LIT>' : returnType , <EOL> '<STR_LIT>' : inArgs , <EOL> '<STR_LIT>' : outArgs , <EOL> '<STR_LIT>' : methodDoc , <EOL> '<STR_LIT>' : defaults , <EOL> '<STR_LIT>' : types , <EOL> '<STR_LIT>' : static , <EOL> '<STR_LIT>' : typeQualifiers , <EOL> '<STR_LIT>' : deprecated } <EOL> self . methods [ self . currentMethod ] . append ( methodInfo ) <EOL> self . currentMethod = None <EOL> pymelNames , invertibles = self . getPymelMethodNames ( ) <EOL> return { '<STR_LIT>' : dict ( self . methods ) , <EOL> '<STR_LIT>' : self . enums , <EOL> '<STR_LIT>' : self . pymelEnums , <EOL> '<STR_LIT>' : pymelNames , <EOL> '<STR_LIT>' : invertibles <EOL> } </s>
