Note that there are some explanatory texts on larger screens.

plurals
  1. PORuntimeError: maximum recursion depth exceeded : why?
    primarykey
    data
    text
    <p>I created a subclass of the Django File object to take care of remote file. I also wanted to make a lazy version by creating a RemoteFileLazy subclassing the Lazyobject class but it does not work as I expected. I get an error.</p> <pre><code>import urllib2 from django.core.files.base import File from django.utils.functional import LazyObject class RemoteFile(File): def __init__(self, url): super(RemoteFile, self).__init__(urllib2.urlopen(urllib2.Request(url))) def __str__(self): return 'Remote content' def __nonzero__(self): return True def open(self, mode=None): self.seek(0) def close(self): pass def chunks(self, chunk_size=None): # CHUNKS taking care of no known size! if not chunk_size: chunk_size = self.DEFAULT_CHUNK_SIZE if hasattr(self, 'seek'): self.seek(0) # Assume the pointer is at zero... counter = self.size while True: data = self.read(chunk_size) if not data: break yield data class RemoteFileLazy(LazyObject): def __init__(self, url): # # as said in the django code: For some reason, we have to inline LazyObject.__init__ here to avoid # recursion self._wrapped = None self.url = url def _setup(self): self._wrapped = RemoteFile(self.url) </code></pre> <p>When I run this code:</p> <pre><code>rfl = filehelper.RemoteFileLazy(url="http://www.google.fr") </code></pre> <p>I got this error:</p> <pre><code>RuntimeError: maximum recursion depth exceeded </code></pre> <p>Any idea ? I did not call LazyObject.<strong>init</strong> as it was mentioned in the django code though... I think the "self.url = url" in the <strong>init</strong> method triggers this error right ? So I cannot use a lazy object with attributes ?</p> <p>Thanks.</p> <p>Traceback:</p> <pre><code>c:\Users\Michael\Dropbox\development\tools\Portable Python 2.7.2.1-django1.3.1\App\lib\site-packages\django\utils\functional.pyc in __getattr__(self, name) 274 def __getattr__(self, name): 275 if self._wrapped is None: --&gt; 276 self._setup() 277 return getattr(self._wrapped, name) 278 C:\Users\Michael\Dropbox\development\projects\django-socialdealing\socialdealing\apps\etl\utils\filehelper.py in _setup(self) 58 59 def _setup(self): ---&gt; 60 self._wrapped = RemoteFile(self.url) 61 62 c:\Users\Michael\Dropbox\development\tools\Portable Python 2.7.2.1-django1.3.1\App\lib\site-packages\django\utils\functional.pyc in __getattr__(self, name) 274 def __getattr__(self, name): 275 if self._wrapped is None: --&gt; 276 self._setup() 277 return getattr(self._wrapped, name) 278 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload