"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py" (11 Apr 2017, 1247 Bytes) of package /windows/misc/atom-windows.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 for x in (type(None), int, long, float,
   32           bool, str, unicode, type):
   33   d[x] = _deepcopy_atomic
   34 
   35 def _deepcopy_list(x):
   36   return [deepcopy(a) for a in x]
   37 d[list] = _deepcopy_list
   38 
   39 def _deepcopy_dict(x):
   40   y = {}
   41   for key, value in x.iteritems():
   42     y[deepcopy(key)] = deepcopy(value)
   43   return y
   44 d[dict] = _deepcopy_dict
   45 
   46 del d