@utils.positional(<NUM_LIT:1>)<EOL>def _ConstructReference(cls, pairs=None, flat=None,<EOL>reference=None, serialized=None, urlsafe=None,<EOL>app=None, namespace=None, parent=None):
if cls is not Key:<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>' % cls)<EOL><DEDENT>if (bool(pairs) + bool(flat) + bool(reference) + bool(serialized) +<EOL>bool(urlsafe)) != <NUM_LIT:1>:<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if flat or pairs:<EOL><INDENT>if flat:<EOL><INDENT>if len(flat) % <NUM_LIT:2>:<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>pairs = [(flat[i], flat[i + <NUM_LIT:1>]) for i in range(<NUM_LIT:0>, len(flat), <NUM_LIT:2>)]<EOL><DEDENT>elif parent is not None:<EOL><INDENT>pairs = list(pairs)<EOL><DEDENT>if not pairs:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if parent is not None:<EOL><INDENT>if not isinstance(parent, Key):<EOL><INDENT>raise datastore_errors.BadValueError(<EOL>'<STR_LIT>' % parent)<EOL><DEDENT>pairs[:<NUM_LIT:0>] = parent.pairs()<EOL>if app:<EOL><INDENT>if app != parent.app():<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(app, parent.app()))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>app = parent.app()<EOL><DEDENT>if namespace is not None:<EOL><INDENT>if namespace != parent.namespace():<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(namespace, parent.namespace()))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>namespace = parent.namespace()<EOL><DEDENT><DEDENT>reference = _ReferenceFromPairs(pairs, app=app, namespace=namespace)<EOL><DEDENT>else:<EOL><INDENT>if parent is not None:<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if urlsafe:<EOL><INDENT>serialized = _DecodeUrlSafe(urlsafe)<EOL><DEDENT>if serialized:<EOL><INDENT>reference = _ReferenceFromSerialized(serialized)<EOL><DEDENT>if not reference.path().element_size():<EOL><INDENT>raise RuntimeError('<STR_LIT>'<EOL>% (urlsafe, serialized, str(reference)))<EOL><DEDENT>if not serialized:<EOL><INDENT>reference = _ReferenceFromReference(reference)<EOL><DEDENT>if app is not None:<EOL><INDENT>ref_app = reference.app()<EOL>if app != ref_app:<EOL><INDENT>raise RuntimeError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(ref_app, app))<EOL><DEDENT><DEDENT>if namespace is not None:<EOL><INDENT>ref_namespace = reference.name_space()<EOL>if namespace != ref_namespace:<EOL><INDENT>raise RuntimeError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(ref_namespace, namespace))<EOL><DEDENT><DEDENT><DEDENT>return reference<EOL>
Construct a Reference; the signature is the same as for Key.