<commit_before>#!/usr/bin/python2.5
#
# Copyright 2008 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Functions for composing Model entity key names.
"""

__authors__ = [
  '"<NAME>" <<EMAIL>>',
  '"<NAME>" <<EMAIL>>',
  ]


from soc.logic import path_link_name


class Error(Exception):
  """Base class for all exceptions raised by this module."""
  pass


def nameDocument(partial_path, link_id=None):
  """Returns a Document key name constructed from a path and link ID.
    
  Args:
    partial_path: the first portion of the path to the Document that uniquely
      identifies it
    link_id: optional link ID to append to path (when omitted,
      partial_path is actually the entire path, with the link_id already
      appended)

  Raises:
    Error if partial_path and link_id produce a "False" path (None,
    empty string, etc.)
  """
  path = [partial_path]
  
  if link_id:
    path.append(link_id)

  path = path_link_name.combinePath(path)

  if not path:
    raise Error('"path" must be non-False: "%s"' % path)

  return 'Document:%s' % path


def nameSiteSettings(partial_path, link_id):
  """Returns a SiteSettings key name constructed from a supplied path.
  
  Raises:
    Error if path is "False" (None, empty string, etc.)
  """

  if not partial_path:
    raise Error('"partial_path" must be non-False: "%s"' % partial_path)

  if not link_id:
    raise Error('"link_id" must be non-False: "%s"' % link_id)

  return 'SiteSettings:%s:%s' % (partial_path, link_id)


def nameHomeSettings(partial_path, link_id):
  """Returns a HomeSettings key name constructed from a supplied path.

  Raises:
    Error if path is "False" (None, empty string, etc.)
  """

  if not partial_path:
    raise Error('"partial_path" must be non-False: "%s"' % partial_path)

  if not link_id:
    raise Error('"link_id" must be non-False: "%s"' % link_id)

  return 'HomeSettings:%s:%s' % (partial_path, link_id)


def nameUser(email):
  """Returns a User key name constructed from a supplied email address.
  
  Raises:<commit_msg>OK, this one file was missing from r1061 for some reason.<commit_after>#!/usr/bin/python2.5
#
# Copyright 2008 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Functions for composing Model entity key names.
"""

__authors__ = [
  '"<NAME>" <<EMAIL>>',
  '"<NAME>" <<EMAIL>>',
  ]


from soc.logic import path_link_name


class Error(Exception):
  """Base class for all exceptions raised by this module."""
  pass


def nameDocument(scope_path, link_id=None):
  """Returns a Document key name constructed from a path and link ID.
    
  Args:
    scope_path: the first portion of the path to the Document that uniquely
      identifies it
    link_id: optional link ID to append to path (when omitted,
      scope_path is actually the entire path, with the link_id already
      appended)

  Raises:
    Error if scope_path and link_id produce a "False" path (None,
    empty string, etc.)
  """
  path = [scope_path]
  
  if link_id:
    path.append(link_id)

  path = path_link_name.combinePath(path)

  if not path:
    raise Error('"path" must be non-False: "%s"' % path)

  return 'Document:%s' % path


def nameSiteSettings(scope_path, link_id):
  """Returns a SiteSettings key name constructed from a supplied path.
  
  Raises:
    Error if path is "False" (None, empty string, etc.)
  """

  if not scope_path:
    raise Error('"scope_path" must be non-False: "%s"' % scope_path)

  if not link_id:
    raise Error('"link_id" must be non-False: "%s"' % link_id)

  return 'SiteSettings:%s:%s' % (scope_path, link_id)


def nameHomeSettings(scope_path, link_id):
  """Returns a HomeSettings key name constructed from a supplied path.

  Raises:
    Error if path is "False" (None, empty string, etc.)
  """

  if not scope_path:
    raise Error('"scope_path" must be non-False: "%s"' % scope_path)

  if not link_id:
    raise Error('"link_id" must be non-False: "%s"' % link_id)

  return 'HomeSettings:%s:%s' % (scope_path, link_id)


def nameUser(email):
  """Returns a User key name constructed from a supplied email address.
  
  Raises:
{'fraction_non_alphanumeric': 0.1037846273897776, 'fraction_numerical': 0.0046820132657042525, 'mean_word_length': 3.7648698884758365, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1275805', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1545, 'n_words': 619}