#NEWLINE# def register( self , resource , canonical = True ) : #NEWLINE# #INDENT# '\n        Registers an instance of a ``Resource`` subclass with the API.\n\n        Optionally accept a ``canonical`` argument, which indicates that the\n        resource being registered is the canonical variant. Defaults to\n        ``True``.\n        ' #NEWLINE# resource_name = getattr ( resource . _meta , 'resource_name' , None ) #NEWLINE# if ( resource_name is None ) : #NEWLINE# #INDENT# raise ImproperlyConfigured ( ( "Resource %r must define a 'resource_name'." % resource ) ) #NEWLINE# #UNINDENT# self . _registry [ resource_name ] = resource #NEWLINE# if ( canonical is True ) : #NEWLINE# #INDENT# if ( resource_name in self . _canonicals ) : #NEWLINE# #INDENT# warnings . warn ( ( "A new resource '%r' is replacing the existing canonical URL for '%s'." % ( resource , resource_name ) ) , Warning , stacklevel = 2 ) #NEWLINE# #UNINDENT# self . _canonicals [ resource_name ] = resource #NEWLINE# resource . _meta . api_name = self . api_name #NEWLINE# resource . __class__ . Meta . api_name = self . api_name