ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yus...@apache.org
Subject [39/51] [partial] AMBARI-7621. Import initial contribution for Ambari support on Windows to branch-windows-dev. (Jayush Luniya and Florian Barca via yusaku)
Date Tue, 07 Oct 2014 22:53:07 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_commons/os_windows.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/os_windows.py b/ambari-common/src/main/python/ambari_commons/os_windows.py
new file mode 100644
index 0000000..8c59063
--- /dev/null
+++ b/ambari-common/src/main/python/ambari_commons/os_windows.py
@@ -0,0 +1,563 @@
+# !/usr/bin/env python
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+'''
+import os
+import getpass
+import shlex
+import subprocess
+import sys
+import time
+import win32api
+import win32event
+import win32service
+import win32con
+import win32serviceutil
+import wmi
+import random
+import string
+
+import ctypes
+
+from win32security import *
+from win32api import *
+from winerror import ERROR_INVALID_HANDLE
+from win32process import GetExitCodeProcess, STARTF_USESTDHANDLES, STARTUPINFO, CreateProcessAsUser
+from win32event import WaitForSingleObject, INFINITE
+import msvcrt
+import tempfile
+import logging
+from win32event import *
+from win32api import CloseHandle
+
+from ambari_commons.exceptions import *
+
+from win32security import LsaOpenPolicy, POLICY_CREATE_ACCOUNT, POLICY_LOOKUP_NAMES, LookupAccountName, \
+  LsaAddAccountRights, LsaRemoveAccountRights, SE_SERVICE_LOGON_NAME
+from win32net import NetUserAdd
+from win32netcon import USER_PRIV_USER, UF_NORMAL_ACCOUNT, UF_SCRIPT
+import pywintypes
+
+SERVICE_STATUS_UNKNOWN = "unknown"
+SERVICE_STATUS_STARTING = "starting"
+SERVICE_STATUS_RUNNING = "running"
+SERVICE_STATUS_STOPPING = "stopping"
+SERVICE_STATUS_STOPPED = "stopped"
+SERVICE_STATUS_NOT_INSTALLED = "not installed"
+
+WHOAMI_GROUPS = "whoami /groups"
+ADMIN_ACCOUNT = "BUILTIN\\Administrators"
+
+class OSVERSIONINFOEXW(ctypes.Structure):
+    _fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
+                ('dwMajorVersion', ctypes.c_ulong),
+                ('dwMinorVersion', ctypes.c_ulong),
+                ('dwBuildNumber', ctypes.c_ulong),
+                ('dwPlatformId', ctypes.c_ulong),
+                ('szCSDVersion', ctypes.c_wchar*128),
+                ('wServicePackMajor', ctypes.c_ushort),
+                ('wServicePackMinor', ctypes.c_ushort),
+                ('wSuiteMask', ctypes.c_ushort),
+                ('wProductType', ctypes.c_byte),
+                ('wReserved', ctypes.c_byte)]
+
+def get_windows_version():
+    """
+    Get's the OS major and minor versions.  Returns a tuple of
+    (OS_MAJOR, OS_MINOR).
+    """
+    os_version = OSVERSIONINFOEXW()
+    os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
+    retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
+    if retcode != 0:
+        raise Exception("Failed to get OS version")
+
+    return os_version.dwMajorVersion, os_version.dwMinorVersion, os_version.dwBuildNumber
+
+CHECK_FIREWALL_SCRIPT = """[string]$CName = $env:computername
+$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$computer)
+$domain = $reg.OpenSubKey("System\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile").GetValue("EnableFirewall")
+$standart = $reg.OpenSubKey("System\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile").GetValue("EnableFirewall")
+$public = $reg.OpenSubKey("System\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\PublicProfile").GetValue("EnableFirewall")
+Write-Host $domain
+Write-Host $standart
+Write-Host $public
+"""
+
+def _create_tmp_files():
+  out_file = tempfile.TemporaryFile(mode="r+b")
+  err_file = tempfile.TemporaryFile(mode="r+b")
+  return (msvcrt.get_osfhandle(out_file.fileno()),
+          msvcrt.get_osfhandle(err_file.fileno()),
+          out_file,
+          err_file)
+
+
+def _get_files_output(out, err):
+  out.seek(0)
+  err.seek(0)
+  return out.read().strip(), err.read().strip()
+
+
+def _safe_duplicate_handle(h):
+  try:
+    h = DuplicateHandle(GetCurrentProcess(),
+                        h,
+                        GetCurrentProcess(),
+                        0,
+                        True,
+                        win32con.DUPLICATE_SAME_ACCESS)
+    return True, h
+  except Exception as exc:
+    if exc.winerror == ERROR_INVALID_HANDLE:
+      return True, None
+  return False, None
+
+
+def run_os_command_impersonated(cmd, user, password, domain='.'):
+  si = STARTUPINFO()
+
+  out_handle, err_handle, out_file, err_file = _create_tmp_files()
+
+  ok, si.hStdInput = _safe_duplicate_handle(GetStdHandle(STD_INPUT_HANDLE))
+
+  if not ok:
+    raise Exception("Unable to create StdInput for child process")
+  ok, si.hStdOutput = _safe_duplicate_handle(out_handle)
+  if not ok:
+    raise Exception("Unable to create StdOut for child process")
+  ok, si.hStdError = _safe_duplicate_handle(err_handle)
+  if not ok:
+    raise Exception("Unable to create StdErr for child process")
+
+  si.dwFlags = STARTF_USESTDHANDLES
+  si.lpDesktop = ""
+
+  user_token = LogonUser(user, domain, password, win32con.LOGON32_LOGON_SERVICE, win32con.LOGON32_PROVIDER_DEFAULT)
+  primary_token = DuplicateTokenEx(user_token, SecurityImpersonation, 0, TokenPrimary)
+  info = CreateProcessAsUser(primary_token, None, cmd, None, None, 1, 0, None, None, si)
+
+  hProcess, hThread, dwProcessId, dwThreadId = info
+  hThread.Close()
+
+  try:
+    WaitForSingleObject(hProcess, INFINITE)
+  except KeyboardInterrupt:
+    pass
+
+  out, err = _get_files_output(out_file, err_file)
+  exitcode = GetExitCodeProcess(hProcess)
+
+  return exitcode, out, err
+
+def run_os_command(cmd, env=None):
+  if isinstance(cmd,basestring):
+    cmd = cmd.replace("\\", "\\\\")
+    cmd = shlex.split(cmd)
+  process = subprocess.Popen(cmd,
+                             stdout=subprocess.PIPE,
+                             stdin=subprocess.PIPE,
+                             stderr=subprocess.PIPE,
+                             env=env
+  )
+  (stdoutdata, stderrdata) = process.communicate()
+  return process.returncode, stdoutdata, stderrdata
+
+# execute powershell script passed in script_content. Script will be in temporary file to avoid different escape
+# and formatting problems.
+def run_powershell_script(script_content):
+  tmp_dir = tempfile.gettempdir()
+  random_filename = ''.join(random.choice(string.lowercase) for i in range(10))
+  script_file = open(os.path.join(tmp_dir,random_filename+".ps1"),"w")
+  script_file.write(script_content)
+  script_file.close()
+  result = run_os_command("powershell  -ExecutionPolicy unrestricted -File {0}".format(script_file.name))
+  os.remove(script_file.name)
+  return result
+
+def os_change_owner(filePath, user):
+  cmd = ['icacls', filePath, '/setowner', user]
+  retcode, outdata, errdata = run_os_command(cmd)
+  return retcode
+
+def os_is_root():
+  '''
+  Checks whether the current user is a member of the Administrators group
+  Returns True if yes, otherwise False
+  '''
+  retcode, out, err = run_os_command(WHOAMI_GROUPS)
+  if retcode != 0:
+    err_msg = "Unable to check the current user's group memberships. Command {0} returned exit code {1} with message: {2}".format(WHOAMI_GROUPS, retcode, err)
+    logging.print_warning_msg(err_msg)
+    raise FatalException(retcode, err_msg)
+
+  #Check for Administrators group membership
+  if -1 != out.find('\n' + ADMIN_ACCOUNT):
+    return True
+
+  return False
+
+def os_set_file_permissions(file, mod, recursive, user):
+  retcode = 0
+
+  #WARN_MSG = "Command {0} returned exit code {1} with message: {2}"
+  #if recursive:
+  #  params = " -R "
+  #else:
+  #  params = ""
+  #command = NR_CHMOD_CMD.format(params, mod, file)
+  #retcode, out, err = run_os_command(command)
+  #if retcode != 0:
+  #  print_warning_msg(WARN_MSG.format(command, file, err))
+  #command = NR_CHOWN_CMD.format(params, user, file)
+  #retcode, out, err = run_os_command(command)
+  #if retcode != 0:
+  #  print_warning_msg(WARN_MSG.format(command, file, err))
+
+  # rights = mod
+  # acls_remove_cmd = "icacls {0} /remove {1}".format(file, user)
+  # retcode, out, err = run_os_command(acls_remove_cmd)
+  # if retcode == 0:
+  #   acls_modify_cmd = "icacls {0} /grant {1}:{2}".format(file, user, rights)
+  #   retcode, out, err = run_os_command(acls_modify_cmd)
+  return retcode
+
+
+def os_set_open_files_limit(maxOpenFiles):
+  # No open files limit in Windows. Not messing around with the System Resource Manager, at least for now.
+  pass
+
+
+def os_getpass(prompt, stream=None):
+  """Prompt for password with echo off, using Windows getch()."""
+  if sys.stdin is not sys.__stdin__:
+    return getpass.fallback_getpass(prompt, stream)
+
+  import msvcrt
+
+  for c in prompt:
+    msvcrt.putch(c)
+
+  pw = ""
+  while True:
+    c = msvcrt.getch()
+    if c == '\r' or c == '\n':
+      break
+    if c == '\003':
+      raise KeyboardInterrupt
+    if c == '\b':
+      if pw == '':
+        pass
+      else:
+        pw = pw[:-1]
+        msvcrt.putch('\b')
+        msvcrt.putch(" ")
+        msvcrt.putch('\b')
+    else:
+      pw = pw + c
+      msvcrt.putch("*")
+
+  msvcrt.putch('\r')
+  msvcrt.putch('\n')
+  return pw
+
+#[fbarca] Not used for now, keep it around just in case
+def wait_for_pid_wmi(processName, parentPid, pattern, timeout):
+  """
+    Check pid for existence during timeout
+  """
+  tstart = time.time()
+  pid_live = 0
+
+  c = wmi.WMI(find_classes=False)
+  qry = "select * from Win32_Process where Name=\"%s\" and ParentProcessId=%d" % (processName, parentPid)
+
+  while int(time.time() - tstart) <= timeout:
+    for proc in c.query(qry):
+      cmdLine = proc.CommandLine
+      if cmdLine is not None and pattern in cmdLine:
+        return pid_live
+    time.sleep(1)
+  return 0
+
+
+#need this for redirecting output form python process to file
+class SyncStreamWriter(object):
+  def __init__(self, stream, hMutexWrite):
+    self.stream = stream
+    self.hMutexWrite = hMutexWrite
+
+  def write(self, data):
+    #Ensure that the output is thread-safe when writing from 2 separate streams into the same file
+    #  (typical when redirecting both stdout and stderr to the same file).
+    win32event.WaitForSingleObject(self.hMutexWrite, win32event.INFINITE)
+    try:
+      self.stream.write(data)
+      self.stream.flush()
+    finally:
+      win32event.ReleaseMutex(self.hMutexWrite)
+
+  def __getattr__(self, attr):
+    return getattr(self.stream, attr)
+
+
+class SvcStatusCallback(object):
+  def __init__(self, svc):
+    self.svc = svc
+
+  def reportStartPending(self):
+    self.svc.ReportServiceStatus(win32service.SERVICE_START_PENDING)
+
+  def reportStarted(self):
+    self.svc.ReportServiceStatus(win32service.SERVICE_RUNNING)
+
+  def reportStopPending(self):
+    self.svc.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
+
+  def reportStopped(self):
+    self.svc.ReportServiceStatus(win32service.SERVICE_STOPPED)
+
+
+class WinServiceController:
+  @staticmethod
+  def Start(serviceName, waitSecs=30):
+    err = 0
+    try:
+      win32serviceutil.StartService(serviceName)
+      if waitSecs:
+        win32serviceutil.WaitForServiceStatus(serviceName, win32service.SERVICE_RUNNING, waitSecs)
+    except win32service.error, exc:
+      print "Error starting service: %s" % exc.strerror
+      err = exc.winerror
+    return err
+
+  @staticmethod
+  def Stop(serviceName, waitSecs=30):
+    err = 0
+    try:
+      if waitSecs:
+        win32serviceutil.StopServiceWithDeps(serviceName, waitSecs=waitSecs)
+      else:
+        win32serviceutil.StopService(serviceName)
+        if waitSecs:
+          win32serviceutil.WaitForServiceStatus(serviceName, win32service.SERVICE_STOPPED, waitSecs)
+    except win32service.error, exc:
+      print "Error stopping service: %s (%d)" % (exc.strerror, exc.winerror)
+      err = exc.winerror
+    return err
+
+  @staticmethod
+  def QueryStatus(serviceName):
+    statusString = SERVICE_STATUS_UNKNOWN
+
+    try:
+      status = win32serviceutil.QueryServiceStatus(serviceName)[1]
+
+      if status == win32service.SERVICE_STOPPED:
+        statusString = SERVICE_STATUS_STOPPED
+      elif status == win32service.SERVICE_START_PENDING:
+        statusString = SERVICE_STATUS_STARTING
+      elif status == win32service.SERVICE_RUNNING:
+        statusString = SERVICE_STATUS_RUNNING
+      elif status == win32service.SERVICE_STOP_PENDING:
+        statusString = SERVICE_STATUS_STOPPING
+    except win32api.error:
+      statusString = SERVICE_STATUS_NOT_INSTALLED
+      pass
+
+    return statusString
+
+  @staticmethod
+  def EnsureServiceIsStarted(serviceName, waitSecs=30):
+    err = 0
+    try:
+      status = win32serviceutil.QueryServiceStatus(serviceName)[1]
+      if win32service.SERVICE_RUNNING != status:
+        if win32service.SERVICE_START_PENDING != status:
+          win32serviceutil.StartService(serviceName)
+        if waitSecs:
+          win32serviceutil.WaitForServiceStatus(serviceName, win32service.SERVICE_RUNNING, waitSecs)
+    except win32service.error, exc:
+      err = exc.winerror
+    return err
+
+
+class WinService(win32serviceutil.ServiceFramework):
+  # _svc_name_ = The service name
+  # _svc_display_name_ = The service display name
+  # _svc_description_ = The service description
+
+  _heventSvcStop = win32event.CreateEvent(None, 0, 0, None)
+  _hmtxOut = win32event.CreateMutex(None, False, None)  #[fbarca] Python doesn't support critical sections
+
+  def __init__(self, *args):
+    win32serviceutil.ServiceFramework.__init__(self, *args)
+
+  def SvcDoRun(self):
+    try:
+      self.ReportServiceStatus(win32service.SERVICE_RUNNING)
+      self.ServiceMain()
+    except Exception, x:
+      #TODO: Log exception
+      self.SvcStop()
+
+  def SvcStop(self):
+    self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
+    win32event.SetEvent(self._heventSvcStop)
+
+  # Service code entry point. Override it to implement the intended functionality.
+  def ServiceMain(self):
+    #Default implementation, does nothing.
+    win32event.WaitForSingleObject(self._heventSvcStop, win32event.INFINITE)
+    pass
+
+  def DefCtrlCHandler(self):
+    logging.print_info_msg("Ctrl+C handler invoked. Stopping.")
+    win32event.SetEvent(self._heventSvcStop)
+    pass
+
+  #username domain\\username : The Username the service is to run under
+  #password password : The password for the username
+  #startup [manual|auto|disabled|delayed] : How the service starts, default = auto
+  #interactive : Allow the service to interact with the desktop.
+  #perfmonini file: .ini file to use for registering performance monitor data
+  #perfmondll file: .dll file to use when querying the service for performance data, default = perfmondata.dll
+  @classmethod
+  def Install(cls, startupMode = "auto", username = None, password = None, interactive = False,
+              perfMonIni = None, perfMonDll = None):
+    installArgs = [sys.argv[0], "--startup=" + startupMode]
+    if username is not None and username:
+      installArgs.append("--username=" + username)
+      if password is not None and password:
+        installArgs.append("--password=" + password)
+    if interactive:
+      installArgs.append("--interactive")
+    if perfMonIni is not None and perfMonIni:
+      installArgs.append("--perfmonini=" + perfMonIni)
+    if perfMonDll is not None and perfMonDll:
+      installArgs.append("--perfmondll=" + perfMonDll)
+    installArgs.append("install")
+    win32serviceutil.HandleCommandLine(cls, None, installArgs)
+
+  @classmethod
+  def Start(cls, waitSecs = 30):
+    return WinServiceController.Start(cls._svc_name_, waitSecs)
+
+  @classmethod
+  def Stop(cls, waitSecs = 30):
+    return WinServiceController.Stop(cls._svc_name_, waitSecs)
+
+  @classmethod
+  def QueryStatus(cls):
+    return WinServiceController.QueryStatus(cls._svc_name_)
+
+  @classmethod
+  def set_ctrl_c_handler(cls, ctrlHandler):
+    win32api.SetConsoleCtrlHandler(ctrlHandler, True)
+    pass
+
+  def _RedirectOutputStreamsToFile(self, outFilePath):
+    outFileDir = os.path.dirname(outFilePath)
+    if not os.path.exists(outFileDir):
+      os.makedirs(outFileDir)
+
+    out_writer = SyncStreamWriter(file(outFilePath, "w"), self._hmtxOut)
+    sys.stderr = out_writer
+    sys.stdout = out_writer
+    pass
+
+  def CheckForStop(self):
+    #Check for stop event to be signaled
+    return win32event.WAIT_OBJECT_0 == win32event.WaitForSingleObject(self._heventSvcStop, 1)
+
+  def _StopOrWaitForChildProcessToFinish(self, childProcess):
+    #Wait for the child process to finish or for the stop event to be signaled
+    if(win32event.WAIT_OBJECT_0 == win32event.WaitForMultipleObjects([self._heventSvcStop, childProcess._handle], False, win32event.INFINITE)):
+      # The OS only detaches the child process when the master process exits.
+      # We must kill it manually.
+      try:
+        #Sending signal.CTRL_BREAK_EVENT doesn't work. It only detaches the child process from the master.
+        #  Must brutally terminate the child process. Sorry Java.
+        childProcess.terminate()
+      except OSError, e:
+        logging.print_info_msg("Unable to stop Ambari Server - " + str(e))
+        return False
+
+    return True
+
+class SystemWideLock(object):
+
+  def __init__(self, name):
+    self._mutex = CreateMutex(None, 0, name)
+
+  def lock(self, timeout=0):
+    result = WaitForSingleObject(self._mutex, timeout)
+    if result in [WAIT_TIMEOUT, WAIT_ABANDONED, WAIT_FAILED]:
+      return False
+    elif result == WAIT_OBJECT_0:
+      return True
+
+  def unlock(self):
+    try:
+      ReleaseMutex(self._mutex)
+      return True
+    except:
+      return False
+
+  def __del__(self):
+    CloseHandle(self._mutex)
+
+class UserHelper(object):
+  ACTION_OK = 0
+  USER_EXISTS = 1
+  ACTION_FAILED = -1
+
+  def __init__(self):
+    self._policy = LsaOpenPolicy(None, POLICY_CREATE_ACCOUNT | POLICY_LOOKUP_NAMES)
+
+  def create_user(self, name, password, comment="Ambari user"):
+    user_info = {}
+    user_info['name'] = name
+    user_info['password'] = password
+    user_info['priv'] = USER_PRIV_USER
+    user_info['comment'] = comment
+    user_info['flags'] = UF_NORMAL_ACCOUNT | UF_SCRIPT
+    try:
+      NetUserAdd(None, 1, user_info)
+    except pywintypes.error as e:
+      if e.winerror == 2224:
+        return UserHelper.USER_EXISTS, e.strerror
+      else:
+        return UserHelper.ACTION_FAILED, e.strerror
+    return UserHelper.ACTION_OK, "User created."
+
+  def add_user_privilege(self, name, privilege):
+    try:
+      acc_sid = LookupAccountName(None, name)[0]
+      LsaAddAccountRights(self._policy, acc_sid, (privilege,))
+    except pywintypes.error as e:
+      return UserHelper.ACTION_FAILED, e.strerror
+    return UserHelper.ACTION_OK, "Privilege added."
+
+  def remove_user_privilege(self, name, privilege):
+    try:
+      acc_sid = LookupAccountName(None, name)[0]
+      LsaRemoveAccountRights(self._policy, acc_sid, 0, (privilege,))
+    except pywintypes.error as e:
+      return UserHelper.ACTION_FAILED, e.strerror
+    return UserHelper.ACTION_OK, "Privilege removed."

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_commons/str_utils.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/str_utils.py b/ambari-common/src/main/python/ambari_commons/str_utils.py
new file mode 100644
index 0000000..9a9e954
--- /dev/null
+++ b/ambari-common/src/main/python/ambari_commons/str_utils.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+'''
+
+def compress_backslashes(s):
+  s1 = s
+  while (-1 != s1.find('\\\\')):
+    s1 = s1.replace('\\\\', '\\')
+  return s1
+
+def ensure_double_backslashes(s):
+  s1 = compress_backslashes(s)
+  s2 = s1.replace('\\', '\\\\')
+  return s2

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/AUTHORS
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/AUTHORS b/ambari-common/src/main/python/ambari_jinja2/AUTHORS
deleted file mode 100644
index c6cd9ba..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/AUTHORS
+++ /dev/null
@@ -1,31 +0,0 @@
-Jinja is written and maintained by the Jinja Team and various
-contributors:
-
-Lead Developer:
-
-- Armin Ronacher <armin.ronacher@active-4.com>
-
-Developers:
-
-- Christoph Hack
-- Georg Brandl
-
-Contributors:
-
-- Bryan McLemore
-- Mickaël Guérin <kael@crocobox.org>
-- Cameron Knight
-- Lawrence Journal-World.
-- David Cramer
-
-Patches and suggestions:
-
-- Ronny Pfannschmidt
-- Axel Böhm
-- Alexey Melchakov
-- Bryan McLemore
-- Clovis Fabricio (nosklo)
-- Cameron Knight
-- Peter van Dijk (Habbie)
-- Stefan Ebner
-- Rene Leonhardt

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/CHANGES
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/CHANGES b/ambari-common/src/main/python/ambari_jinja2/CHANGES
deleted file mode 100644
index 25b8aa4..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/CHANGES
+++ /dev/null
@@ -1,235 +0,0 @@
-Jinja2 Changelog
-================
-
-Version 2.5.5
--------------
-(re-release of 2.5.4 with built documentation removed for filesize.
- Released on October 18th 2010)
-
-- built documentation is no longer part of release.
-
-Version 2.5.4
--------------
-(bugfix release, released on October 17th 2010)
-
-- Fixed extensions not loading properly with overlays.
-- Work around a bug in cpython for the debugger that causes segfaults
-  on 64bit big-endian architectures.
-
-Version 2.5.3
--------------
-(bugfix release, released on October 17th 2010)
-
-- fixed an operator precedence error introduced in 2.5.2.  Statements
-  like "-foo.bar" had their implicit parentheses applied around the
-  first part of the expression ("(-foo).bar") instead of the more
-  correct "-(foo.bar)".
-
-Version 2.5.2
--------------
-(bugfix release, released on August 18th 2010)
-
-- improved setup.py script to better work with assumptions people
-  might still have from it (``--with-speedups``).
-- fixed a packaging error that excluded the new debug support.
-
-Version 2.5.1
--------------
-(bugfix release, released on August 17th 2010)
-
-- StopIteration exceptions raised by functions called from templates
-  are now intercepted and converted to undefineds.  This solves a
-  lot of debugging grief.  (StopIteration is used internally to
-  abort template execution)
-- improved performance of macro calls slightly.
-- babel extraction can now properly extract newstyle gettext calls.
-- using the variable `num` in newstyle gettext for something else
-  than the pluralize count will no longer raise a :exc:`KeyError`.
-- removed builtin markup class and switched to markupsafe.  For backwards
-  compatibility the pure Python implementation still exists but is
-  pulled from markupsafe by the Jinja2 developers.  The debug support
-  went into a separate feature called "debugsupport" and is disabled
-  by default because it is only relevant for Python 2.4
-- fixed an issue with unary operators having the wrong precendence.
-
-Version 2.5
------------
-(codename Incoherence, relased on May 29th 2010)
-
-- improved the sort filter (should have worked like this for a
-  long time) by adding support for case insensitive searches.
-- fixed a bug for getattribute constant folding.
-- support for newstyle gettext translations which result in a
-  nicer in-template user interface and more consistent
-  catalogs. (:ref:`newstyle-gettext`)
-- it's now possible to register extensions after an environment
-  was created.
-
-Version 2.4.1
--------------
-(bugfix release, released on April 20th 2010)
-
-- fixed an error reporting bug for undefineds.
-
-Version 2.4
------------
-(codename Correlation, released on April 13th 2010)
-
-- the environment template loading functions now transparently
-  pass through a template object if it was passed to it.  This
-  makes it possible to import or extend from a template object
-  that was passed to the template.
-- added a :class:`ModuleLoader` that can load templates from
-  precompiled sources.  The environment now features a method
-  to compile the templates from a configured loader into a zip
-  file or folder.
-- the _speedups C extension now supports Python 3.
-- added support for autoescaping toggling sections and support
-  for evaluation contexts (:ref:`eval-context`).
-- extensions have a priority now.
-
-Version 2.3.1
--------------
-(bugfix release, released on February 19th 2010)
-
-- fixed an error reporting bug on all python versions
-- fixed an error reporting bug on Python 2.4
-
-Version 2.3
------------
-(3000 Pythons, released on February 10th 2010)
-
-- fixes issue with code generator that causes unbound variables
-  to be generated if set was used in if-blocks and other small
-  identifier problems.
-- include tags are now able to select between multiple templates
-  and take the first that exists, if a list of templates is
-  given.
-- fixed a problem with having call blocks in outer scopes that
-  have an argument that is also used as local variable in an
-  inner frame (#360).
-- greatly improved error message reporting (#339)
-- implicit tuple expressions can no longer be totally empty.
-  This change makes ``{% if %}...{% endif %}`` a syntax error
-  now. (#364)
-- added support for translator comments if extracted via babel.
-- added with-statement extension.
-- experimental Python 3 support.
-
-Version 2.2.1
--------------
-(bugfix release, released on September 14th 2009)
-
-- fixes some smaller problems for Jinja2 on Jython.
-
-Version 2.2
------------
-(codename Kong, released on September 13th 2009)
-
-- Include statements can now be marked with ``ignore missing`` to skip
-  non existing templates.
-- Priority of `not` raised.  It's now possible to write `not foo in bar`
-  as an alias to `foo not in bar` like in python.  Previously the grammar
-  required parentheses (`not (foo in bar)`) which was odd.
-- Fixed a bug that caused syntax errors when defining macros or using the
-  `{% call %}` tag inside loops.
-- Fixed a bug in the parser that made ``{{ foo[1, 2] }}`` impossible.
-- Made it possible to refer to names from outer scopes in included templates
-  that were unused in the callers frame (#327)
-- Fixed a bug that caused internal errors if names where used as iteration
-  variable and regular variable *after* the loop if that variable was unused
-  *before* the loop.  (#331)
-- Added support for optional `scoped` modifier to blocks.
-- Added support for line-comments.
-- Added the `meta` module.
-- Renamed (undocumented) attribute "overlay" to "overlayed" on the
-  environment because it was clashing with a method of the same name.
-- speedup extension is now disabled by default.
-
-Version 2.1.1
--------------
-(Bugfix release)
-
-- Fixed a translation error caused by looping over empty recursive loops.
-
-Version 2.1
------------
-(codename Yasuzō, released on November 23rd 2008)
-
-- fixed a bug with nested loops and the special loop variable.  Before the
-  change an inner loop overwrote the loop variable from the outer one after
-  iteration.
-
-- fixed a bug with the i18n extension that caused the explicit pluralization
-  block to look up the wrong variable.
-
-- fixed a limitation in the lexer that made ``{{ foo.0.0 }}`` impossible.
-
-- index based subscribing of variables with a constant value returns an
-  undefined object now instead of raising an index error.  This was a bug
-  caused by eager optimizing.
-
-- the i18n extension looks up `foo.ugettext` now followed by `foo.gettext`
-  if an translations object is installed.  This makes dealing with custom
-  translations classes easier.
-
-- fixed a confusing behavior with conditional extending.  loops were partially
-  executed under some conditions even though they were not part of a visible
-  area.
-
-- added `sort` filter that works like `dictsort` but for arbitrary sequences.
-
-- fixed a bug with empty statements in macros.
-
-- implemented a bytecode cache system.  (:ref:`bytecode-cache`)
-
-- the template context is now weakref-able
-
-- inclusions and imports "with context" forward all variables now, not only
-  the initial context.
-
-- added a cycle helper called `cycler`.
-
-- added a joining helper called `joiner`.
-
-- added a `compile_expression` method to the environment that allows compiling
-  of Jinja expressions into callable Python objects.
-
-- fixed an escaping bug in urlize
-
-Version 2.0
------------
-(codename jinjavitus, released on July 17th 2008)
-
-- the subscribing of objects (looking up attributes and items) changed from
-  slightly.  It's now possible to give attributes or items a higher priority
-  by either using dot-notation lookup or the bracket syntax.  This also
-  changed the AST slightly.  `Subscript` is gone and was replaced with
-  :class:`~ambari_jinja2.nodes.Getitem` and :class:`~ambari_jinja2.nodes.Getattr`.
-
-  For more information see :ref:`the implementation details <notes-on-subscriptions>`.
-
-- added support for preprocessing and token stream filtering for extensions.
-  This would allow extensions to allow simplified gettext calls in template
-  data and something similar.
-
-- added :meth:`ambari_jinja2.environment.TemplateStream.dump`.
-
-- added missing support for implicit string literal concatenation.
-  ``{{ "foo" "bar" }}`` is equivalent to ``{{ "foobar" }}``
-
-- `else` is optional for conditional expressions.  If not given it evaluates
-  to `false`.
-
-- improved error reporting for undefined values by providing a position.
-
-- `filesizeformat` filter uses decimal prefixes now per default and can be
-  set to binary mode with the second parameter.
-
-- fixed bug in finalizer
-
-Version 2.0rc1
---------------
-(no codename, released on June 9th 2008)
-
-- first release of Jinja2

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/LICENSE
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/LICENSE b/ambari-common/src/main/python/ambari_jinja2/LICENSE
deleted file mode 100644
index 31bf900..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/LICENSE
+++ /dev/null
@@ -1,31 +0,0 @@
-Copyright (c) 2009 by the Jinja Team, see AUTHORS for more details.
-
-Some rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
-    * Redistributions of source code must retain the above copyright
-      notice, this list of conditions and the following disclaimer.
-
-    * Redistributions in binary form must reproduce the above
-      copyright notice, this list of conditions and the following
-      disclaimer in the documentation and/or other materials provided
-      with the distribution.
-
-    * The names of the contributors may not be used to endorse or
-      promote products derived from this software without specific
-      prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/MANIFEST.in
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/MANIFEST.in b/ambari-common/src/main/python/ambari_jinja2/MANIFEST.in
deleted file mode 100644
index 17ef0bd..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/MANIFEST.in
+++ /dev/null
@@ -1,12 +0,0 @@
-include MANIFEST.in Makefile CHANGES LICENSE AUTHORS ambari_jinja2/_debugsupport.c
-recursive-include docs *
-recursive-include custom_fixers *
-recursive-include ext *
-recursive-include artwork *
-recursive-include examples *
-recursive-include ambari_jinja2/testsuite/res *
-recursive-exclude docs/_build *
-recursive-exclude ambari_jinja2 *.pyc
-recursive-exclude docs *.pyc
-recursive-exclude ambari_jinja2 *.pyo
-recursive-exclude docs *.pyo

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/Makefile
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/Makefile b/ambari-common/src/main/python/ambari_jinja2/Makefile
deleted file mode 100644
index 60ca1d7..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-test:
-	python setup.py test
-
-.PHONY: test

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/__init__.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/__init__.py
deleted file mode 100644
index d02aab2..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/__init__.py
+++ /dev/null
@@ -1,73 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-    ambari_jinja2
-    ~~~~~~
-
-    Jinja2 is a template engine written in pure Python.  It provides a
-    Django inspired non-XML syntax but supports inline expressions and
-    an optional sandboxed environment.
-
-    Nutshell
-    --------
-
-    Here a small example of a Jinja2 template::
-
-        {% extends 'base.html' %}
-        {% block title %}Memberlist{% endblock %}
-        {% block content %}
-          <ul>
-          {% for user in users %}
-            <li><a href="{{ user.url }}">{{ user.username }}</a></li>
-          {% endfor %}
-          </ul>
-        {% endblock %}
-
-
-    :copyright: (c) 2010 by the Jinja Team.
-    :license: BSD, see LICENSE for more details.
-"""
-__docformat__ = 'restructuredtext en'
-try:
-    __version__ = __import__('pkg_resources') \
-        .get_distribution('Jinja2').version
-except:
-    __version__ = 'unknown'
-
-# high level interface
-from ambari_jinja2.environment import Environment, Template
-
-# loaders
-from ambari_jinja2.loaders import BaseLoader, FileSystemLoader, PackageLoader, \
-     DictLoader, FunctionLoader, PrefixLoader, ChoiceLoader, \
-     ModuleLoader
-
-# bytecode caches
-from ambari_jinja2.bccache import BytecodeCache, FileSystemBytecodeCache, \
-     MemcachedBytecodeCache
-
-# undefined types
-from ambari_jinja2.runtime import Undefined, DebugUndefined, StrictUndefined
-
-# exceptions
-from ambari_jinja2.exceptions import TemplateError, UndefinedError, \
-     TemplateNotFound, TemplatesNotFound, TemplateSyntaxError, \
-     TemplateAssertionError
-
-# decorators and public utilities
-from ambari_jinja2.filters import environmentfilter, contextfilter, \
-     evalcontextfilter
-from ambari_jinja2.utils import Markup, escape, clear_caches, \
-     environmentfunction, evalcontextfunction, contextfunction, \
-     is_undefined
-
-__all__ = [
-    'Environment', 'Template', 'BaseLoader', 'FileSystemLoader',
-    'PackageLoader', 'DictLoader', 'FunctionLoader', 'PrefixLoader',
-    'ChoiceLoader', 'BytecodeCache', 'FileSystemBytecodeCache',
-    'MemcachedBytecodeCache', 'Undefined', 'DebugUndefined',
-    'StrictUndefined', 'TemplateError', 'UndefinedError', 'TemplateNotFound',
-    'TemplatesNotFound', 'TemplateSyntaxError', 'TemplateAssertionError',
-    'ModuleLoader', 'environmentfilter', 'contextfilter', 'Markup', 'escape',
-    'environmentfunction', 'contextfunction', 'clear_caches', 'is_undefined',
-    'evalcontextfilter', 'evalcontextfunction'
-]

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_debugsupport.c
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_debugsupport.c b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_debugsupport.c
deleted file mode 100644
index 041c94f..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_debugsupport.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * ambari_jinja2._debugsupport
- * ~~~~~~~~~~~~~~~~~~~~
- *
- * C implementation of `tb_set_next`.
- *
- * :copyright: (c) 2010 by the Jinja Team.
- * :license: BSD.
- */
-
-#include <Python.h>
-
-
-static PyObject*
-tb_set_next(PyObject *self, PyObject *args)
-{
-	PyTracebackObject *tb, *old;
-	PyObject *next;
-
-	if (!PyArg_ParseTuple(args, "O!O:tb_set_next", &PyTraceBack_Type, &tb, &next))
-		return NULL;
-	if (next == Py_None)
-		next = NULL;
-	else if (!PyTraceBack_Check(next)) {
-		PyErr_SetString(PyExc_TypeError,
-				"tb_set_next arg 2 must be traceback or None");
-		return NULL;
-	}
-	else
-		Py_INCREF(next);
-
-	old = tb->tb_next;
-	tb->tb_next = (PyTracebackObject*)next;
-	Py_XDECREF(old);
-
-	Py_INCREF(Py_None);
-	return Py_None;
-}
-
-static PyMethodDef module_methods[] = {
-	{"tb_set_next", (PyCFunction)tb_set_next, METH_VARARGS,
-	 "Set the tb_next member of a traceback object."},
-	{NULL, NULL, 0, NULL}		/* Sentinel */
-};
-
-
-#if PY_MAJOR_VERSION < 3
-
-#ifndef PyMODINIT_FUNC	/* declarations for DLL import/export */
-#define PyMODINIT_FUNC void
-#endif
-PyMODINIT_FUNC
-init_debugsupport(void)
-{
-	Py_InitModule3("ambari_jinja2._debugsupport", module_methods, "");
-}
-
-#else /* Python 3.x module initialization */
-
-static struct PyModuleDef module_definition = {
-        PyModuleDef_HEAD_INIT,
-	"ambari_jinja2._debugsupport",
-	NULL,
-	-1,
-	module_methods,
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-PyMODINIT_FUNC
-PyInit__debugsupport(void)
-{
-	return PyModule_Create(&module_definition);
-}
-
-#endif

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/__init__.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/__init__.py
deleted file mode 100644
index 74d0fe3..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/__init__.py
+++ /dev/null
@@ -1,225 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-    markupsafe
-    ~~~~~~~~~~
-
-    Implements a Markup string.
-
-    :copyright: (c) 2010 by Armin Ronacher.
-    :license: BSD, see LICENSE for more details.
-"""
-import re
-from itertools import imap
-
-
-__all__ = ['Markup', 'soft_unicode', 'escape', 'escape_silent']
-
-
-_striptags_re = re.compile(r'(<!--.*?-->|<[^>]*>)')
-_entity_re = re.compile(r'&([^;]+);')
-
-
-class Markup(unicode):
-    r"""Marks a string as being safe for inclusion in HTML/XML output without
-    needing to be escaped.  This implements the `__html__` interface a couple
-    of frameworks and web applications use.  :class:`Markup` is a direct
-    subclass of `unicode` and provides all the methods of `unicode` just that
-    it escapes arguments passed and always returns `Markup`.
-
-    The `escape` function returns markup objects so that double escaping can't
-    happen.
-
-    The constructor of the :class:`Markup` class can be used for three
-    different things:  When passed an unicode object it's assumed to be safe,
-    when passed an object with an HTML representation (has an `__html__`
-    method) that representation is used, otherwise the object passed is
-    converted into a unicode string and then assumed to be safe:
-
-    >>> Markup("Hello <em>World</em>!")
-    Markup(u'Hello <em>World</em>!')
-    >>> class Foo(object):
-    ...  def __html__(self):
-    ...   return '<a href="#">foo</a>'
-    ... 
-    >>> Markup(Foo())
-    Markup(u'<a href="#">foo</a>')
-
-    If you want object passed being always treated as unsafe you can use the
-    :meth:`escape` classmethod to create a :class:`Markup` object:
-
-    >>> Markup.escape("Hello <em>World</em>!")
-    Markup(u'Hello &lt;em&gt;World&lt;/em&gt;!')
-
-    Operations on a markup string are markup aware which means that all
-    arguments are passed through the :func:`escape` function:
-
-    >>> em = Markup("<em>%s</em>")
-    >>> em % "foo & bar"
-    Markup(u'<em>foo &amp; bar</em>')
-    >>> strong = Markup("<strong>%(text)s</strong>")
-    >>> strong % {'text': '<blink>hacker here</blink>'}
-    Markup(u'<strong>&lt;blink&gt;hacker here&lt;/blink&gt;</strong>')
-    >>> Markup("<em>Hello</em> ") + "<foo>"
-    Markup(u'<em>Hello</em> &lt;foo&gt;')
-    """
-    __slots__ = ()
-
-    def __new__(cls, base=u'', encoding=None, errors='strict'):
-        if hasattr(base, '__html__'):
-            base = base.__html__()
-        if encoding is None:
-            return unicode.__new__(cls, base)
-        return unicode.__new__(cls, base, encoding, errors)
-
-    def __html__(self):
-        return self
-
-    def __add__(self, other):
-        if hasattr(other, '__html__') or isinstance(other, basestring):
-            return self.__class__(unicode(self) + unicode(escape(other)))
-        return NotImplemented
-
-    def __radd__(self, other):
-        if hasattr(other, '__html__') or isinstance(other, basestring):
-            return self.__class__(unicode(escape(other)) + unicode(self))
-        return NotImplemented
-
-    def __mul__(self, num):
-        if isinstance(num, (int, long)):
-            return self.__class__(unicode.__mul__(self, num))
-        return NotImplemented
-    __rmul__ = __mul__
-
-    def __mod__(self, arg):
-        if isinstance(arg, tuple):
-            arg = tuple(imap(_MarkupEscapeHelper, arg))
-        else:
-            arg = _MarkupEscapeHelper(arg)
-        return self.__class__(unicode.__mod__(self, arg))
-
-    def __repr__(self):
-        return '%s(%s)' % (
-            self.__class__.__name__,
-            unicode.__repr__(self)
-        )
-
-    def join(self, seq):
-        return self.__class__(unicode.join(self, imap(escape, seq)))
-    join.__doc__ = unicode.join.__doc__
-
-    def split(self, *args, **kwargs):
-        return map(self.__class__, unicode.split(self, *args, **kwargs))
-    split.__doc__ = unicode.split.__doc__
-
-    def rsplit(self, *args, **kwargs):
-        return map(self.__class__, unicode.rsplit(self, *args, **kwargs))
-    rsplit.__doc__ = unicode.rsplit.__doc__
-
-    def splitlines(self, *args, **kwargs):
-        return map(self.__class__, unicode.splitlines(self, *args, **kwargs))
-    splitlines.__doc__ = unicode.splitlines.__doc__
-
-    def unescape(self):
-        r"""Unescape markup again into an unicode string.  This also resolves
-        known HTML4 and XHTML entities:
-
-        >>> Markup("Main &raquo; <em>About</em>").unescape()
-        u'Main \xbb <em>About</em>'
-        """
-        from ambari_jinja2._markupsafe._constants import HTML_ENTITIES
-        def handle_match(m):
-            name = m.group(1)
-            if name in HTML_ENTITIES:
-                return unichr(HTML_ENTITIES[name])
-            try:
-                if name[:2] in ('#x', '#X'):
-                    return unichr(int(name[2:], 16))
-                elif name.startswith('#'):
-                    return unichr(int(name[1:]))
-            except ValueError:
-                pass
-            return u''
-        return _entity_re.sub(handle_match, unicode(self))
-
-    def striptags(self):
-        r"""Unescape markup into an unicode string and strip all tags.  This
-        also resolves known HTML4 and XHTML entities.  Whitespace is
-        normalized to one:
-
-        >>> Markup("Main &raquo;  <em>About</em>").striptags()
-        u'Main \xbb About'
-        """
-        stripped = u' '.join(_striptags_re.sub('', self).split())
-        return Markup(stripped).unescape()
-
-    @classmethod
-    def escape(cls, s):
-        """Escape the string.  Works like :func:`escape` with the difference
-        that for subclasses of :class:`Markup` this function would return the
-        correct subclass.
-        """
-        rv = escape(s)
-        if rv.__class__ is not cls:
-            return cls(rv)
-        return rv
-
-    def make_wrapper(name):
-        orig = getattr(unicode, name)
-        def func(self, *args, **kwargs):
-            args = _escape_argspec(list(args), enumerate(args))
-            _escape_argspec(kwargs, kwargs.iteritems())
-            return self.__class__(orig(self, *args, **kwargs))
-        func.__name__ = orig.__name__
-        func.__doc__ = orig.__doc__
-        return func
-
-    for method in '__getitem__', 'capitalize', \
-                  'title', 'lower', 'upper', 'replace', 'ljust', \
-                  'rjust', 'lstrip', 'rstrip', 'center', 'strip', \
-                  'translate', 'expandtabs', 'swapcase', 'zfill':
-        locals()[method] = make_wrapper(method)
-
-    # new in python 2.5
-    if hasattr(unicode, 'partition'):
-        partition = make_wrapper('partition'),
-        rpartition = make_wrapper('rpartition')
-
-    # new in python 2.6
-    if hasattr(unicode, 'format'):
-        format = make_wrapper('format')
-
-    # not in python 3
-    if hasattr(unicode, '__getslice__'):
-        __getslice__ = make_wrapper('__getslice__')
-
-    del method, make_wrapper
-
-
-def _escape_argspec(obj, iterable):
-    """Helper for various string-wrapped functions."""
-    for key, value in iterable:
-        if hasattr(value, '__html__') or isinstance(value, basestring):
-            obj[key] = escape(value)
-    return obj
-
-
-class _MarkupEscapeHelper(object):
-    """Helper for Markup.__mod__"""
-
-    def __init__(self, obj):
-        self.obj = obj
-
-    __getitem__ = lambda s, x: _MarkupEscapeHelper(s.obj[x])
-    __str__ = lambda s: str(escape(s.obj))
-    __unicode__ = lambda s: unicode(escape(s.obj))
-    __repr__ = lambda s: str(escape(repr(s.obj)))
-    __int__ = lambda s: int(s.obj)
-    __float__ = lambda s: float(s.obj)
-
-
-# we have to import it down here as the speedups and native
-# modules imports the markup type which is define above.
-try:
-    from ambari_jinja2._markupsafe._speedups import escape, escape_silent, soft_unicode
-except ImportError:
-    from ambari_jinja2._markupsafe._native import escape, escape_silent, soft_unicode

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_bundle.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_bundle.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_bundle.py
deleted file mode 100644
index de5d15e..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_bundle.py
+++ /dev/null
@@ -1,49 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-    ambari_jinja2._markupsafe._bundle
-    ~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-    This script pulls in markupsafe from a source folder and
-    bundles it with Jinja2.  It does not pull in the speedups
-    module though.
-
-    :copyright: Copyright 2010 by the Jinja team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-import sys
-import os
-import re
-
-
-def rewrite_imports(lines):
-    for idx, line in enumerate(lines):
-        new_line = re.sub(r'(import|from)\s+markupsafe\b',
-                          r'\1 ambari_jinja2._markupsafe', line)
-        if new_line != line:
-            lines[idx] = new_line
-
-
-def main():
-    if len(sys.argv) != 2:
-        print 'error: only argument is path to markupsafe'
-        sys.exit(1)
-    basedir = os.path.dirname(__file__)
-    markupdir = sys.argv[1]
-    for filename in os.listdir(markupdir):
-        if filename.endswith('.py'):
-            f = open(os.path.join(markupdir, filename))
-            try:
-                lines = list(f)
-            finally:
-                f.close()
-            rewrite_imports(lines)
-            f = open(os.path.join(basedir, filename), 'w')
-            try:
-                for line in lines:
-                    f.write(line)
-            finally:
-                f.close()
-
-
-if __name__ == '__main__':
-    main()

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_constants.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_constants.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_constants.py
deleted file mode 100644
index 919bf03..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_constants.py
+++ /dev/null
@@ -1,267 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-    markupsafe._constants
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Highlevel implementation of the Markup string.
-
-    :copyright: (c) 2010 by Armin Ronacher.
-    :license: BSD, see LICENSE for more details.
-"""
-
-
-HTML_ENTITIES = {
-    'AElig': 198,
-    'Aacute': 193,
-    'Acirc': 194,
-    'Agrave': 192,
-    'Alpha': 913,
-    'Aring': 197,
-    'Atilde': 195,
-    'Auml': 196,
-    'Beta': 914,
-    'Ccedil': 199,
-    'Chi': 935,
-    'Dagger': 8225,
-    'Delta': 916,
-    'ETH': 208,
-    'Eacute': 201,
-    'Ecirc': 202,
-    'Egrave': 200,
-    'Epsilon': 917,
-    'Eta': 919,
-    'Euml': 203,
-    'Gamma': 915,
-    'Iacute': 205,
-    'Icirc': 206,
-    'Igrave': 204,
-    'Iota': 921,
-    'Iuml': 207,
-    'Kappa': 922,
-    'Lambda': 923,
-    'Mu': 924,
-    'Ntilde': 209,
-    'Nu': 925,
-    'OElig': 338,
-    'Oacute': 211,
-    'Ocirc': 212,
-    'Ograve': 210,
-    'Omega': 937,
-    'Omicron': 927,
-    'Oslash': 216,
-    'Otilde': 213,
-    'Ouml': 214,
-    'Phi': 934,
-    'Pi': 928,
-    'Prime': 8243,
-    'Psi': 936,
-    'Rho': 929,
-    'Scaron': 352,
-    'Sigma': 931,
-    'THORN': 222,
-    'Tau': 932,
-    'Theta': 920,
-    'Uacute': 218,
-    'Ucirc': 219,
-    'Ugrave': 217,
-    'Upsilon': 933,
-    'Uuml': 220,
-    'Xi': 926,
-    'Yacute': 221,
-    'Yuml': 376,
-    'Zeta': 918,
-    'aacute': 225,
-    'acirc': 226,
-    'acute': 180,
-    'aelig': 230,
-    'agrave': 224,
-    'alefsym': 8501,
-    'alpha': 945,
-    'amp': 38,
-    'and': 8743,
-    'ang': 8736,
-    'apos': 39,
-    'aring': 229,
-    'asymp': 8776,
-    'atilde': 227,
-    'auml': 228,
-    'bdquo': 8222,
-    'beta': 946,
-    'brvbar': 166,
-    'bull': 8226,
-    'cap': 8745,
-    'ccedil': 231,
-    'cedil': 184,
-    'cent': 162,
-    'chi': 967,
-    'circ': 710,
-    'clubs': 9827,
-    'cong': 8773,
-    'copy': 169,
-    'crarr': 8629,
-    'cup': 8746,
-    'curren': 164,
-    'dArr': 8659,
-    'dagger': 8224,
-    'darr': 8595,
-    'deg': 176,
-    'delta': 948,
-    'diams': 9830,
-    'divide': 247,
-    'eacute': 233,
-    'ecirc': 234,
-    'egrave': 232,
-    'empty': 8709,
-    'emsp': 8195,
-    'ensp': 8194,
-    'epsilon': 949,
-    'equiv': 8801,
-    'eta': 951,
-    'eth': 240,
-    'euml': 235,
-    'euro': 8364,
-    'exist': 8707,
-    'fnof': 402,
-    'forall': 8704,
-    'frac12': 189,
-    'frac14': 188,
-    'frac34': 190,
-    'frasl': 8260,
-    'gamma': 947,
-    'ge': 8805,
-    'gt': 62,
-    'hArr': 8660,
-    'harr': 8596,
-    'hearts': 9829,
-    'hellip': 8230,
-    'iacute': 237,
-    'icirc': 238,
-    'iexcl': 161,
-    'igrave': 236,
-    'image': 8465,
-    'infin': 8734,
-    'int': 8747,
-    'iota': 953,
-    'iquest': 191,
-    'isin': 8712,
-    'iuml': 239,
-    'kappa': 954,
-    'lArr': 8656,
-    'lambda': 955,
-    'lang': 9001,
-    'laquo': 171,
-    'larr': 8592,
-    'lceil': 8968,
-    'ldquo': 8220,
-    'le': 8804,
-    'lfloor': 8970,
-    'lowast': 8727,
-    'loz': 9674,
-    'lrm': 8206,
-    'lsaquo': 8249,
-    'lsquo': 8216,
-    'lt': 60,
-    'macr': 175,
-    'mdash': 8212,
-    'micro': 181,
-    'middot': 183,
-    'minus': 8722,
-    'mu': 956,
-    'nabla': 8711,
-    'nbsp': 160,
-    'ndash': 8211,
-    'ne': 8800,
-    'ni': 8715,
-    'not': 172,
-    'notin': 8713,
-    'nsub': 8836,
-    'ntilde': 241,
-    'nu': 957,
-    'oacute': 243,
-    'ocirc': 244,
-    'oelig': 339,
-    'ograve': 242,
-    'oline': 8254,
-    'omega': 969,
-    'omicron': 959,
-    'oplus': 8853,
-    'or': 8744,
-    'ordf': 170,
-    'ordm': 186,
-    'oslash': 248,
-    'otilde': 245,
-    'otimes': 8855,
-    'ouml': 246,
-    'para': 182,
-    'part': 8706,
-    'permil': 8240,
-    'perp': 8869,
-    'phi': 966,
-    'pi': 960,
-    'piv': 982,
-    'plusmn': 177,
-    'pound': 163,
-    'prime': 8242,
-    'prod': 8719,
-    'prop': 8733,
-    'psi': 968,
-    'quot': 34,
-    'rArr': 8658,
-    'radic': 8730,
-    'rang': 9002,
-    'raquo': 187,
-    'rarr': 8594,
-    'rceil': 8969,
-    'rdquo': 8221,
-    'real': 8476,
-    'reg': 174,
-    'rfloor': 8971,
-    'rho': 961,
-    'rlm': 8207,
-    'rsaquo': 8250,
-    'rsquo': 8217,
-    'sbquo': 8218,
-    'scaron': 353,
-    'sdot': 8901,
-    'sect': 167,
-    'shy': 173,
-    'sigma': 963,
-    'sigmaf': 962,
-    'sim': 8764,
-    'spades': 9824,
-    'sub': 8834,
-    'sube': 8838,
-    'sum': 8721,
-    'sup': 8835,
-    'sup1': 185,
-    'sup2': 178,
-    'sup3': 179,
-    'supe': 8839,
-    'szlig': 223,
-    'tau': 964,
-    'there4': 8756,
-    'theta': 952,
-    'thetasym': 977,
-    'thinsp': 8201,
-    'thorn': 254,
-    'tilde': 732,
-    'times': 215,
-    'trade': 8482,
-    'uArr': 8657,
-    'uacute': 250,
-    'uarr': 8593,
-    'ucirc': 251,
-    'ugrave': 249,
-    'uml': 168,
-    'upsih': 978,
-    'upsilon': 965,
-    'uuml': 252,
-    'weierp': 8472,
-    'xi': 958,
-    'yacute': 253,
-    'yen': 165,
-    'yuml': 255,
-    'zeta': 950,
-    'zwj': 8205,
-    'zwnj': 8204
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_native.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_native.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_native.py
deleted file mode 100644
index 97c8d35..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_native.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-    markupsafe._native
-    ~~~~~~~~~~~~~~~~~~
-
-    Native Python implementation the C module is not compiled.
-
-    :copyright: (c) 2010 by Armin Ronacher.
-    :license: BSD, see LICENSE for more details.
-"""
-from ambari_jinja2._markupsafe import Markup
-
-
-def escape(s):
-    """Convert the characters &, <, >, ' and " in string s to HTML-safe
-    sequences.  Use this if you need to display text that might contain
-    such characters in HTML.  Marks return value as markup string.
-    """
-    if hasattr(s, '__html__'):
-        return s.__html__()
-    return Markup(unicode(s)
-        .replace('&', '&amp;')
-        .replace('>', '&gt;')
-        .replace('<', '&lt;')
-        .replace("'", '&#39;')
-        .replace('"', '&#34;')
-    )
-
-
-def escape_silent(s):
-    """Like :func:`escape` but converts `None` into an empty
-    markup string.
-    """
-    if s is None:
-        return Markup()
-    return escape(s)
-
-
-def soft_unicode(s):
-    """Make a string unicode if it isn't already.  That way a markup
-    string is not converted back to unicode.
-    """
-    if not isinstance(s, unicode):
-        s = unicode(s)
-    return s

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/tests.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/tests.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/tests.py
deleted file mode 100644
index 8e88bfe..0000000
--- a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/tests.py
+++ /dev/null
@@ -1,80 +0,0 @@
-import gc
-import unittest
-from ambari_jinja2._markupsafe import Markup, escape, escape_silent
-
-
-class MarkupTestCase(unittest.TestCase):
-
-    def test_markup_operations(self):
-        # adding two strings should escape the unsafe one
-        unsafe = '<script type="application/x-some-script">alert("foo");</script>'
-        safe = Markup('<em>username</em>')
-        assert unsafe + safe == unicode(escape(unsafe)) + unicode(safe)
-
-        # string interpolations are safe to use too
-        assert Markup('<em>%s</em>') % '<bad user>' == \
-               '<em>&lt;bad user&gt;</em>'
-        assert Markup('<em>%(username)s</em>') % {
-            'username': '<bad user>'
-        } == '<em>&lt;bad user&gt;</em>'
-
-        # an escaped object is markup too
-        assert type(Markup('foo') + 'bar') is Markup
-
-        # and it implements __html__ by returning itself
-        x = Markup("foo")
-        assert x.__html__() is x
-
-        # it also knows how to treat __html__ objects
-        class Foo(object):
-            def __html__(self):
-                return '<em>awesome</em>'
-            def __unicode__(self):
-                return 'awesome'
-        assert Markup(Foo()) == '<em>awesome</em>'
-        assert Markup('<strong>%s</strong>') % Foo() == \
-               '<strong><em>awesome</em></strong>'
-
-        # escaping and unescaping
-        assert escape('"<>&\'') == '&#34;&lt;&gt;&amp;&#39;'
-        assert Markup("<em>Foo &amp; Bar</em>").striptags() == "Foo & Bar"
-        assert Markup("&lt;test&gt;").unescape() == "<test>"
-
-    def test_all_set(self):
-        import ambari_jinja2._markupsafe as markup
-        for item in markup.__all__:
-            getattr(markup, item)
-
-    def test_escape_silent(self):
-        assert escape_silent(None) == Markup()
-        assert escape(None) == Markup(None)
-        assert escape_silent('<foo>') == Markup(u'&lt;foo&gt;')
-
-
-class MarkupLeakTestCase(unittest.TestCase):
-
-    def test_markup_leaks(self):
-        counts = set()
-        for count in xrange(20):
-            for item in xrange(1000):
-                escape("foo")
-                escape("<foo>")
-                escape(u"foo")
-                escape(u"<foo>")
-            counts.add(len(gc.get_objects()))
-        assert len(counts) == 1, 'ouch, c extension seems to leak objects'
-
-
-def suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(MarkupTestCase))
-
-    # this test only tests the c extension
-    if not hasattr(escape, 'func_code'):
-        suite.addTest(unittest.makeSuite(MarkupLeakTestCase))
-
-    return suite
-
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='suite')


Mime
View raw message