# Path: error.py
# def is_valid_HTTP_code(code):
# def get_HTTP_err(code):
#   def __init__(self,
#                msg,
#                http_code=400,
#                app_code=DEF_ME_CODE,
#                inner_exc=None,
#                **kwds):
#   def gen_msgs(self, **kwds):
#   def get_err_dict(self):
#   def __str__(self):
#   def __init__(self,
#                msg,
#                http_code=500,
#                app_code=ParameterizedError.DEF_ME_CODE,
#                inner_exc=None,
#                **kwds):
#   def __init__(self, msg=None, *args, **kwds):
# class ParameterizedError(Exception):
# class NetworkAddressError(ParameterizedError):
# class ContentLoadError(ParameterizedError):
# class TypeVerifyError(ParameterizedError):
# class EmailError(ParameterizedError):
# class SubscriptionError(ParameterizedError):
# class MSSError(ParameterizedError):
# class UserLookupError(ParameterizedError):
# class UserAuthError(ParameterizedError):
# class BlobError(ParameterizedError):
# class BLOBClientError(ParameterizedError):
# class RelevanceError(ParameterizedError):
# class TextSearchError(ParameterizedError):
# class AutocompleteError(ParameterizedError):
# class EmptyResult(ParameterizedError):
# class GraphConnectionError(ParameterizedError):
# class FormattingError(ParameterizedError):
# class SessionError(ParameterizedError):
# class ConfigError(ParameterizedError):
# class SanitizationError(ParameterizedError):
# class BlurbError(ParameterizedError):
# class DomainOperationError(ParameterizedError):
# class GenericRuntimeError(ParameterizedError):
# class OAuthDisabledError(ParameterizedError):
# class RecaptchaError(ParameterizedError):
# class ReadOnlyDatabaseError(ParameterizedError):
#   DEF_PFX = '/api/status/error'
#   DEF_ME_CODE = '/unknown/unknown'


import re
  import sys, os
import json
import scope
import lookup
import pprint
import cgi
  import cmdline
from pymql.log import LOG, log_util, pprintlog, dumplog
from pymql.error import EmptyResult
from qprim import QueryPrimitive
from utils import (element, elements, dict_recurse, valid_relname, follow_path,
                   is_direct_pointer, valid_precompiled_sort, ReadMode,
                   WriteMode, PrepareMode, CheckMode, QueryDict, QueryList,
                   ResultDict, Missing)
from error import MQLResultError, MQLInternalError, MQLInternalParseError, MQLAccessError, MQLGraphError
from env import Varenv
        write_primitive = query.link
      elif query.node is not Missing and query.node.state in ('create',
                                                              'remove'):
        # if we do not write the (non Missing) link, we never have to write the node
        write_primitive = query.node
      elif query.ordered is not Missing and query.ordered.state in ('create',
                                                                    'modify'):
        # we may need to write just the order information to the (existing) link
        write_primitive = query.ordered

      # did we find something to do?
      if write_primitive:
        writeq = write_primitive.generate_write_query()

        dumplog('WRITE_QUERY', writeq)

        try:
          gresult = self.gc.write_varenv(writeq, varenv)
          has_written = True
        except MQLGraphError, e:
          subclass = e.get_kwd('subclass')
          if subclass == 'EXISTS' and write_primitive.unique == 'key':
            # must have gotten here due to a race condition in creating a
            # key in a namespace -- but that's ok, so silently succeed
            write_primitive.change_state('written')
            continue
          elif subclass in ['EXISTS', 'OUTDATED']:
            # we hit a uniqueness failure! Ick
            if not has_written:
              # thankfully this is the first such error; the write can be safely abandoned

# Path: error.py
# def is_valid_HTTP_code(code):
# def get_HTTP_err(code):
#   def __init__(self,
#                msg,
#                http_code=400,
#                app_code=DEF_ME_CODE,
#                inner_exc=None,
#                **kwds):
#   def gen_msgs(self, **kwds):
#   def get_err_dict(self):
#   def __str__(self):
#   def __init__(self,
#                msg,
#                http_code=500,
#                app_code=ParameterizedError.DEF_ME_CODE,
#                inner_exc=None,
#                **kwds):
#   def __init__(self, msg=None, *args, **kwds):
# class ParameterizedError(Exception):
# class NetworkAddressError(ParameterizedError):
# class ContentLoadError(ParameterizedError):
# class TypeVerifyError(ParameterizedError):
# class EmailError(ParameterizedError):
# class SubscriptionError(ParameterizedError):
# class MSSError(ParameterizedError):
# class UserLookupError(ParameterizedError):
# class UserAuthError(ParameterizedError):
# class BlobError(ParameterizedError):
# class BLOBClientError(ParameterizedError):
# class RelevanceError(ParameterizedError):
# class TextSearchError(ParameterizedError):
# class AutocompleteError(ParameterizedError):
# class EmptyResult(ParameterizedError):
# class GraphConnectionError(ParameterizedError):
# class FormattingError(ParameterizedError):
# class SessionError(ParameterizedError):
# class ConfigError(ParameterizedError):
# class SanitizationError(ParameterizedError):
# class BlurbError(ParameterizedError):
# class DomainOperationError(ParameterizedError):
# class GenericRuntimeError(ParameterizedError):
# class OAuthDisabledError(ParameterizedError):
# class RecaptchaError(ParameterizedError):
# class ReadOnlyDatabaseError(ParameterizedError):
#   DEF_PFX = '/api/status/error'
#   DEF_ME_CODE = '/unknown/unknown'


# Path: mql/lojson.py
import re
  import sys, os
import json
import scope
import lookup
import pprint
import cgi
  import cmdline
from pymql.log import LOG, log_util, pprintlog, dumplog
from pymql.error import EmptyResult
from qprim import QueryPrimitive
from utils import (element, elements, dict_recurse, valid_relname, follow_path,
                   is_direct_pointer, valid_precompiled_sort, ReadMode,
                   WriteMode, PrepareMode, CheckMode, QueryDict, QueryList,
                   ResultDict, Missing)
from error import MQLResultError, MQLInternalError, MQLInternalParseError, MQLAccessError, MQLGraphError
from env import Varenv

        write_primitive = query.link
      elif query.node is not Missing and query.node.state in ('create',
                                                              'remove'):
        # if we do not write the (non Missing) link, we never have to write the node
        write_primitive = query.node
      elif query.ordered is not Missing and query.ordered.state in ('create',
                                                                    'modify'):
        # we may need to write just the order information to the (existing) link
        write_primitive = query.ordered

      # did we find something to do?
      if write_primitive:
        writeq = write_primitive.generate_write_query()

        dumplog('WRITE_QUERY', writeq)

        try:
          gresult = self.gc.write_varenv(writeq, varenv)
          has_written = True
        except MQLGraphError, e:
          subclass = e.get_kwd('subclass')
          if subclass == 'EXISTS' and write_primitive.unique == 'key':
            # must have gotten here due to a race condition in creating a
            # key in a namespace -- but that's ok, so silently succeed
            write_primitive.change_state('written')
            continue
          elif subclass in ['EXISTS', 'OUTDATED']:
            # we hit a uniqueness failure! Ick
            if not has_written:
              # thankfully this is the first such error; the write can be safely abandoned

              raise MQLResultError(