"Fossies" - the Fresh Open Source Software Archive

Member "node-v12.18.4-win-x86/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py" (14 Feb 2020, 1383 Bytes) of package /windows/www/node-v12.18.4-win-x86.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # Copyright 2014 Google Inc. All rights reserved.
    2 # Use of this source code is governed by a BSD-style license that can be
    3 # found in the LICENSE file.
    4 
    5 """A clone of the default copy.deepcopy that doesn't handle cyclic
    6 structures or complex types except for dicts and lists. This is
    7 because gyp copies so large structure that small copy overhead ends up
    8 taking seconds in a project the size of Chromium."""
    9 
   10 class Error(Exception):
   11   pass
   12 
   13 __all__ = ["Error", "deepcopy"]
   14 
   15 def deepcopy(x):
   16   """Deep copy operation on gyp objects such as strings, ints, dicts
   17   and lists. More than twice as fast as copy.deepcopy but much less
   18   generic."""
   19 
   20   try:
   21     return _deepcopy_dispatch[type(x)](x)
   22   except KeyError:
   23     raise Error('Unsupported type %s for deepcopy. Use copy.deepcopy ' +
   24                 'or expand simple_copy support.' % type(x))
   25 
   26 _deepcopy_dispatch = d = {}
   27 
   28 def _deepcopy_atomic(x):
   29   return x
   30 
   31 try:
   32   types = bool, float, int, str, type, type(None), long, unicode
   33 except NameError:  # Python 3
   34   types = bool, float, int, str, type, type(None)
   35 
   36 for x in types:
   37   d[x] = _deepcopy_atomic
   38 
   39 def _deepcopy_list(x):
   40   return [deepcopy(a) for a in x]
   41 d[list] = _deepcopy_list
   42 
   43 def _deepcopy_dict(x):
   44   y = {}
   45   for key, value in x.items():
   46     y[deepcopy(key)] = deepcopy(value)
   47   return y
   48 d[dict] = _deepcopy_dict
   49 
   50 del d