On Dienstag, 24. November 2009, Seth Hill wrote:
> Hello,
>> I filed a bug report with the django folks too (
> http://code.djangoproject.com/ticket/12256). We determined that the issue
> isn't specific to django's use of metaclasses, but is in fact an issue with
> some older versions of python. This class:
>> class Foo(object):
> def __init__(self, x):
> self.x = x
> def __unicode__(self):
> print self.x
>> Generates the same TypeError when you call unicode(type(Foo())). My python
> is 2.5.1. I wasn't able to duplicate the issue on my Mac under python
> 2.6.2. I haven't been able to find a bug about this in the python bug list
> though.
Over here it is working fine under openSUSE 11.2 with Python 2.6.2.
Unfortunately I don't have a Python 2.5.x installation any more.
>> On Mon, Nov 23, 2009 at 9:16 AM, detlev <detlev at die-offenbachs.de> wrote:
> > Hello again,
> >
> > On Sonntag, 22. November 2009, Seth Hill wrote:
> > > On Nov 22, 2009, at 3:33 AM, detlev wrote:
> > > > On Samstag, 21. November 2009, Seth Hill wrote:
> > > >> I'm working with a django 1.1 project, trying to get debugging
> > > >> going. I'm working with a form in a view function. I set a
> > > >> breakpoint in the view function, and get a TypeError in
> > > >> DebugClientBase.py:1608. It looks like the debugger is going through
> > > >> the locals and calling unicode() on all of them. Some of the locals
> > > >> in this case don't support the unicode method. When the debugger
> > > >> calls the unicode() method, it triggers an exception inside the
> > > >> running wsgi server. I get an error message on the web page, and the
> > > >> debug session stops working.
> > > >>
> > > >> My code looks like:
> > > >>
> > > >> forms.py:
> > > >> class NewCustomerForm(forms.Form):
> > > >> name = forms.CharField()
> > > >> # etc
> > > >>
> > > >> views.py:
> > > >> def create_customer(request):
> > > >> if request.method == "POST": # breakpoint here
> > > >> form = NewCustomerForm(request.POST)
> > > >> if form.is_valid(): # exception occurs when stepping
> > > >> to here
> > > >>
> > > >>
> > > >> The line in DebugClientBase.py looks like:
> > > >> valtypestr = unicode(type(value))[1:-1]
> > > >
> > > > I don't understand, why type(value) does not support the unicode()
> > > > method.
> > >
> > > Now that you mention it, I don't either. I've been digging a little
> > > deeper, and it seems that this is django's problem:
> > >
> > > A django.forms.forms.Form class defines __metaclass__ =
> > > DeclarativeFieldsMetaclass (see source code http://
> > > code.djangoproject.com/browser/django/trunk/django/forms/forms.py:
> > > 336). I'm not entirely sure what it does, but I gather that it
> > > converts the class attributes into fields which can be accessed by a
> > > class instance.
> > >
> > > Anyway, the metaclass seems to be promoting the __unicode__ function
> > >
> > > of Form to type(Form):
> > > >>> f = Form()
> > > >>> type(f)
> > >
> > > <class 'django.forms.forms.Form'>
> >
> > That seems to be a Django bug because the net result is, that you cannot
> > convert the result of type(f) to a unicode string.
> >
> > > >>> unicode(type(f))
> > >
> > > Traceback (most recent call last):
> > > File "<console>", line 1, in <module>
> > > TypeError: unbound method __unicode__() must be called with Form
> > > instance as first argument (got nothing instead)
> > >
> > > >>> type(Form)
> > >
> > > <class 'django.forms.forms.DeclarativeFieldsMetaclass'>
> > >
> > > >>> import inspect
> > > >>> inspect.getsource(type(f).__unicode__)
> > >
> > > ' def __unicode__(self):\n return self.as_table()\n'
> >
> > Can you please check, what ist returned by
> > "inspect.getsource(type(f).__repr__)"?
> >
> >>> inspect.getsource(type(f).__repr__)
>> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "C:\Software\Python25\lib\inspect.py", line 629, in getsource
> lines, lnum = getsourcelines(object)
> File "C:\Software\Python25\lib\inspect.py", line 618, in getsourcelines
> lines, lnum = findsource(object)
> File "C:\Software\Python25\lib\inspect.py", line 461, in findsource
> file = getsourcefile(object) or getfile(object)
> File "C:\Software\Python25\lib\inspect.py", line 383, in getsourcefile
> filename = getfile(object)
> File "C:\Software\Python25\lib\inspect.py", line 363, in getfile
> raise TypeError('arg is not a module, class, method, '
> TypeError: arg is not a module, class, method, function, traceback, frame,
> or code object
>> I assume this means that __repr__ hasn't been defined (not in source code
> anyway).
>> However, this also doesn't work even if I do define __repr__:
> >>> class Foo(Form):
>> ... def __repr__(self):
> ... return 'called repr'
> ...
>> >>> inspect.getsource(Foo().__repr___)
>> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "C:\Software\Python25\lib\inspect.py", line 629, in getsource
> lines, lnum = getsourcelines(object)
> File "C:\Software\Python25\lib\inspect.py", line 618, in getsourcelines
> lines, lnum = findsource(object)
> File "C:\Software\Python25\lib\inspect.py", line 468, in findsource
> raise IOError('could not get source code')
> IOError: could not get source code
>> >>> repr(Foo())
>> 'called repr'
>> But that might be because I'm doing it on the console.
>> > What is needed by the eric4 debugger backend is a method to return the
> > type of
> > a variable as a string.
>> This is kinda wacky, but might work:
>> t = type(value)
> if not t is type:
> t = type(t)
> valtypestr = unicode(t)[1:-1]
>> If f = Foo(), and Foo defines a metaclass, then type(f) isn't <type
> 'type'>. However, type(type(f)) should be.
>> > > Anyway, the effect is still that if you are running the debugger and
> > > have a Form instance as a local variable, it will blow up. I would be
> > > willing to be that debugging a Model instance would have a similar
> > > effect (since it also uses a metaclass).
> > >
> > > Maybe, instead of below a workaround should be:
> > >
> > > if type(value) is type:
> > > valtypestr = unicode(type(value))[1:-1]
> > > else:
> > > valtypestr = repr(type(value))[1:-1]
> > >
> > > However, even when doing that I suppose some metaclass could screw up
> > > __repr__ just like django's DeclarativeFieldsMetaclass did with
> > > __unicode__. (?)
> > >
> > > >> I've "fixed" the error by wrapping the line in a try:
> > > >>
> > > >> try:
> > > >> valtypestr = unicode(type(value))[1:-1]
> > > >> except TypeError:
> > > >> valtypestr = repr(type(value))[1:-1]
> >
> > Regards
> > Detlev
> > --
> > Detlev Offenbach
> > detlev at die-offenbachs.de
>
--
Detlev Offenbach
detlev at die-offenbachs.de
More information about the Eric
mailing list
‘She has never mentioned her father to me. Was he—well, the sort of man whom the County Club would not have blackballed?’ "We walked by the side of our teams or behind the wagons, we slept on the ground at night, we did our own cooking, we washed our knives by sticking them into the ground rapidly a few times, and we washed our plates with sand and wisps of grass. When we stopped, we arranged our wagons in a circle, and thus formed a 'corral,' or yard, where we drove our oxen to yoke them up. And the corral was often very useful as a fort, or camp, for defending ourselves against the Indians. Do you see that little hollow down there?" he asked, pointing to a depression in the ground a short distance to the right of the train. "Well, in that hollow our wagon-train was kept three days and nights by the Indians. Three days and nights they stayed around, and made several attacks. Two of our men were killed and three were wounded by their arrows, and others had narrow escapes. One arrow hit me on the throat, but I was saved by the knot of my neckerchief, and the point only tore the skin a little. Since that time I have always had a fondness for large neckties. I don't know how many of the Indians we killed, as they carried off their dead and wounded, to save them from being scalped. Next to getting the scalps of their enemies, the most important thing with the Indians is to save their own. We had several fights during our journey, but that one was the worst. Once a little party of us were surrounded in a small 'wallow,' and had a tough time to defend ourselves successfully. Luckily for us, the Indians had no fire-arms then, and their bows and arrows were no match for our rifles. Nowadays they are well armed, but there are[Pg 41] not so many of them, and they are not inclined to trouble the railway trains. They used to do a great deal of mischief in the old times, and many a poor fellow has been killed by them." As dusk came on nearly the whole population of Maastricht, with all their temporary guests, formed an endless procession and went to invoke God's mercy by the Virgin Mary's intercession. They went to Our Lady's Church, in which stands the miraculous statue of Sancta Maria Stella Maris. The procession filled all the principal streets and squares of the town. I took my stand at the corner of the Vrijthof, where all marched past me, men, women, and children, all praying aloud, with loud voices beseeching: "Our Lady, Star of the Sea, pray for us ... pray for us ... pray for us ...!" It had not occurred to her for some hours after Mrs. Campbell had told her of Landor's death that she was free now to give herself to Cairness. She had gasped, indeed, when she did remember it, and had put the thought away, angrily and self-reproachfully. But it returned now, and she felt that she might cling to it. She had been grateful, and she had been faithful, too.[Pg 286] She remembered only that Landor had been kind to her, and forgot that for the last two years she had borne with much harsh coldness, and with a sort of contempt which she felt in her unanalyzing mind to have been entirely unmerited. Gradually she raised herself until she sat quite erect by the side of the mound, the old exultation of her half-wild girlhood shining in her face as she planned the future, which only a few minutes before had seemed so hopeless. After he had gloated over Sergeant Ramsey, Shorty got his men into the road ready to start. Si placed himself in front of the squad and deliberately loaded his musket in their sight. Shorty took his place in the rear, and gave out: The groups about each gun thinned out, as the shrieking fragments of shell mowed down man after man, but the rapidity of the fire did not slacken in the least. One of the Lieutenants turned and motioned with his saber to the riders seated on their horses in the line of limbers under the cover of the slope. One rider sprang from each team and ran up to take the place of men who had fallen. "As long as there's men and women in the world, the men 'ull be top and the women bottom." Then, in the house, the little girls were useful. Mrs. Backfield was not so energetic as she used to be. She had never been a robust woman, and though her husband's care had kept her well and strong, her frame was not equal to Reuben's demands; after fourteen years' hard labour, she suffered from rheumatism, which though seldom acute, was inclined to make her stiff and slow. It was here that Caro and Tilly came in, and Reuben began to appreciate his girls. After all, girls were needed in a house—and as for young men and marriage, their father could easily see that such follies did not spoil their usefulness or take them from him. Caro and Tilly helped their grandmother in all sorts of ways—they dusted, they watched pots, they shelled peas and peeled potatoes, they darned house-linen, they could even make a bed between them. HoME一级毛片视频免费公开
ENTER NUMBET 0018www.jjj-jjj.com.cn c0c0.com.cn runyahn.com.cn southokay.com.cn xuelutong.com.cn yj33.com.cn www.lilaile.com.cn www.tdeey.com.cn www.msssxz.com.cn www.tianfuk.com.cn