Commits

Martin Geisler  committed 180d48d

Move code to appendix

  • Participants
  • Parent commits 5741396

Comments (0)

Files changed (1)

File python-hg-talk.tex

 \end{frame}
 
 
-\begin{frame}[fragile]{Demand-Loading Python Modules}
-  Rewiring the \code{import} statement is quite easy!
-
-\begin{lstlisting}[language=Python]
-import __builtin__
-_origimport = __import__ # save for later
-
-class _demandmod(object):
-    """module demand-loader and proxy"""
-    # ... one slide away
-
-# modules that require immediate ImportErrors
-ignore = ['_hashlib', '_xmlplus', 'fcntl', ...]
-
-def _demandimport(name, globals, locals, fromlist):
-    """import name and return _demandmod proxy"""
-    # ... two slides away
-
-def enable():
-    __builtin__.__import__ = _demandimport
-\end{lstlisting}
-\end{frame}
-
-\begin{frame}[fragile]{Proxy Modules}
-\begin{lstlisting}[language=Python]
-class _demandmod(object):
-    def __init__(self, n, g, l):
-        object.__setattr__(self, "_data", (n, g, l))
-        object.__setattr__(self, "_module", None)
-
-    def _loadmodule(self):
-        if not self._module:
-            mod = _origimport(*self._data)
-            object.__setattr__(self, "_module", mod)
-        return self._module
-
-    def __getattribute__(self, attr):
-        if attr in ('_data', '_loadmodule', '_module'):
-            return object.__getattribute__(self, attr)
-        return getattr(self._loadmodule(), attr)
-
-    def __setattr__(self, attr, val):
-        setattr(self._loadmodule(), attr, val)
-\end{lstlisting}
-\end{frame}
-
-\begin{frame}[fragile]{New Import Function}
-\begin{lstlisting}[language=Python]
-def _demandimport(name, globals, locals, fromlist):
-    if name in ignore or fromlist == ('*',):
-        # ignored module or "from a import *"
-        return _origimport(name, globals, locals, fromlist)
-    elif not fromlist:
-        # "import a" or "import a as b"
-        return _demandmod(name, globals, locals)
-    else:
-        # "from a import b, c"
-        mod = _origimport(name, globals, locals)
-        for x in fromlist:
-            # set requested submodules for demand load
-            if not hasattr(mod, x):
-                submod = _demandmod(x, mod.__dict__, locals)
-                setattr(mod, x, submod)
-        return mod
-\end{lstlisting}
-\end{frame}
-
 \section{Traditional Techniques}
 
 \begin{frame}{Optimizing Code}
   \end{itemize}
 \end{frame}
 
+\appendix
+\newcounter{finalframe}
+\setcounter{finalframe}{\value{framenumber}}
 
+
+\begin{frame}[fragile]{Demand-Loading Python Modules}
+  Rewiring the \code{import} statement is quite easy!
+
+\begin{lstlisting}[language=Python]
+import __builtin__
+_origimport = __import__ # save for later
+
+class _demandmod(object):
+    """module demand-loader and proxy"""
+    # ... one slide away
+
+# modules that require immediate ImportErrors
+ignore = ['_hashlib', '_xmlplus', 'fcntl', ...]
+
+def _demandimport(name, globals, locals, fromlist):
+    """import name and return _demandmod proxy"""
+    # ... two slides away
+
+def enable():
+    __builtin__.__import__ = _demandimport
+\end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]{Proxy Modules}
+\begin{lstlisting}[language=Python]
+class _demandmod(object):
+    def __init__(self, n, g, l):
+        object.__setattr__(self, "_data", (n, g, l))
+        object.__setattr__(self, "_module", None)
+
+    def _loadmodule(self):
+        if not self._module:
+            mod = _origimport(*self._data)
+            object.__setattr__(self, "_module", mod)
+        return self._module
+
+    def __getattribute__(self, attr):
+        if attr in ('_data', '_loadmodule', '_module'):
+            return object.__getattribute__(self, attr)
+        return getattr(self._loadmodule(), attr)
+
+    def __setattr__(self, attr, val):
+        setattr(self._loadmodule(), attr, val)
+\end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]{New Import Function}
+\begin{lstlisting}[language=Python]
+def _demandimport(name, globals, locals, fromlist):
+    if name in ignore or fromlist == ('*',):
+        # ignored module or "from a import *"
+        return _origimport(name, globals, locals, fromlist)
+    elif not fromlist:
+        # "import a" or "import a as b"
+        return _demandmod(name, globals, locals)
+    else:
+        # "from a import b, c"
+        mod = _origimport(name, globals, locals)
+        for x in fromlist:
+            # set requested submodules for demand load
+            if not hasattr(mod, x):
+                submod = _demandmod(x, mod.__dict__, locals)
+                setattr(mod, x, submod)
+        return mod
+\end{lstlisting}
+\end{frame}
+
+\setcounter{framenumber}{\value{finalframe}}
 \end{document}