#NEWLINE# def identity_key( * args , **kwargs ) : #NEWLINE# #INDENT# 'Generate "identity key" tuples, as are used as keys in the\n    :attr:`.Session.identity_map` dictionary.\n\n    This function has several call styles:\n\n    * ``identity_key(class, ident)``\n\n      This form receives a mapped class and a primary key scalar or\n      tuple as an argument.\n\n      E.g.::\n\n        >>> identity_key(MyClass, (1, 2))\n        (<class \'__main__.MyClass\'>, (1, 2))\n\n      :param class: mapped class (must be a positional argument)\n      :param ident: primary key, may be a scalar or tuple argument.\n\n\n    * ``identity_key(instance=instance)``\n\n      This form will produce the identity key for a given instance.  The\n      instance need not be persistent, only that its primary key attributes\n      are populated (else the key will contain ``None`` for those missing\n      values).\n\n      E.g.::\n\n        >>> instance = MyClass(1, 2)\n        >>> identity_key(instance=instance)\n        (<class \'__main__.MyClass\'>, (1, 2))\n\n      In this form, the given instance is ultimately run though\n      :meth:`.Mapper.identity_key_from_instance`, which will have the\n      effect of performing a database check for the corresponding row\n      if the object is expired.\n\n      :param instance: object instance (must be given as a keyword arg)\n\n    * ``identity_key(class, row=row)``\n\n      This form is similar to the class/tuple form, except is passed a\n      database result row as a :class:`.RowProxy` object.\n\n      E.g.::\n\n        >>> row = engine.execute("select * from table where a=1 and b=2").first()\n        >>> identity_key(MyClass, row=row)\n        (<class \'__main__.MyClass\'>, (1, 2))\n\n      :param class: mapped class (must be a positional argument)\n      :param row: :class:`.RowProxy` row returned by a :class:`.ResultProxy`\n       (must be given as a keyword arg)\n\n    ' #NEWLINE# if args : #NEWLINE# #INDENT# if ( len ( args ) == 1 ) : #NEWLINE# #INDENT# class_ = args [ 0 ] #NEWLINE# try : #NEWLINE# #INDENT# row = kwargs . pop ( 'row' ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# ident = kwargs . pop ( 'ident' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( args ) == 2 ) : #NEWLINE# #INDENT# ( class_ , ident ) = args #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( args ) == 3 ) : #NEWLINE# #INDENT# ( class_ , ident ) = args #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise sa_exc . ArgumentError ( ( 'expected up to three positional arguments, got %s' % len ( args ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if kwargs : #NEWLINE# #INDENT# raise sa_exc . ArgumentError ( ( 'unknown keyword arguments: %s' % ', ' . join ( ident ) ) ) #NEWLINE# #UNINDENT# mapper = class_mapper ( class_ ) #NEWLINE# if ( 'ident' in locals ( ) ) : #NEWLINE# #INDENT# return mapper . identity_key_from_primary_key ( util . to_list ( ident ) ) #NEWLINE# #UNINDENT# return mapper . identity_key_from_row ( row ) #NEWLINE# #UNINDENT# instance = kwargs . pop ( 'instance' ) #NEWLINE# if kwargs : #NEWLINE# #INDENT# raise sa_exc . ArgumentError ( ( 'unknown keyword arguments: %s' % ', ' . join ( kwargs . keys ) ) ) #NEWLINE# #UNINDENT# mapper = object_mapper ( instance ) #NEWLINE# return mapper . identity_key_from_instance ( instance )