]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.2/Demo/classes/Range.py
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Demo / classes / Range.py
diff --git a/AppPkg/Applications/Python/Python-2.7.2/Demo/classes/Range.py b/AppPkg/Applications/Python/Python-2.7.2/Demo/classes/Range.py
deleted file mode 100644 (file)
index b0ce5cb..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-"""Example of a generator: re-implement the built-in range function\r
-without actually constructing the list of values.\r
-\r
-OldStyleRange is coded in the way required to work in a 'for' loop before\r
-iterators were introduced into the language; using __getitem__ and __len__ .\r
-\r
-"""\r
-def handleargs(arglist):\r
-    """Take list of arguments and extract/create proper start, stop, and step\r
-    values and return in a tuple"""\r
-    try:\r
-        if len(arglist) == 1:\r
-            return 0, int(arglist[0]), 1\r
-        elif len(arglist) == 2:\r
-            return int(arglist[0]), int(arglist[1]), 1\r
-        elif len(arglist) == 3:\r
-            if arglist[2] == 0:\r
-                raise ValueError("step argument must not be zero")\r
-            return tuple(int(x) for x in arglist)\r
-        else:\r
-            raise TypeError("range() accepts 1-3 arguments, given", len(arglist))\r
-    except TypeError:\r
-        raise TypeError("range() arguments must be numbers or strings "\r
-        "representing numbers")\r
-\r
-def genrange(*a):\r
-    """Function to implement 'range' as a generator"""\r
-    start, stop, step = handleargs(a)\r
-    value = start\r
-    while value < stop:\r
-        yield value\r
-        value += step\r
-\r
-class oldrange:\r
-    """Class implementing a range object.\r
-    To the user the instances feel like immutable sequences\r
-    (and you can't concatenate or slice them)\r
-\r
-    Done using the old way (pre-iterators; __len__ and __getitem__) to have an\r
-    object be used by a 'for' loop.\r
-\r
-    """\r
-\r
-    def __init__(self, *a):\r
-        """ Initialize start, stop, and step values along with calculating the\r
-        nubmer of values (what __len__ will return) in the range"""\r
-        self.start, self.stop, self.step = handleargs(a)\r
-        self.len = max(0, (self.stop - self.start) // self.step)\r
-\r
-    def __repr__(self):\r
-        """implement repr(x) which is also used by print"""\r
-        return 'range(%r, %r, %r)' % (self.start, self.stop, self.step)\r
-\r
-    def __len__(self):\r
-        """implement len(x)"""\r
-        return self.len\r
-\r
-    def __getitem__(self, i):\r
-        """implement x[i]"""\r
-        if 0 <= i <= self.len:\r
-            return self.start + self.step * i\r
-        else:\r
-            raise IndexError, 'range[i] index out of range'\r
-\r
-\r
-def test():\r
-    import time, __builtin__\r
-    #Just a quick sanity check\r
-    correct_result = __builtin__.range(5, 100, 3)\r
-    oldrange_result = list(oldrange(5, 100, 3))\r
-    genrange_result = list(genrange(5, 100, 3))\r
-    if genrange_result != correct_result or oldrange_result != correct_result:\r
-        raise Exception("error in implementation:\ncorrect   = %s"\r
-                         "\nold-style = %s\ngenerator = %s" %\r
-                         (correct_result, oldrange_result, genrange_result))\r
-    print "Timings for range(1000):"\r
-    t1 = time.time()\r
-    for i in oldrange(1000):\r
-        pass\r
-    t2 = time.time()\r
-    for i in genrange(1000):\r
-        pass\r
-    t3 = time.time()\r
-    for i in __builtin__.range(1000):\r
-        pass\r
-    t4 = time.time()\r
-    print t2-t1, 'sec (old-style class)'\r
-    print t3-t2, 'sec (generator)'\r
-    print t4-t3, 'sec (built-in)'\r
-\r
-\r
-if __name__ == '__main__':\r
-    test()\r