type 모듈¶
- class mozrepl.type.Object(repl, uuid)¶
Bases: object
javascript object에 대한 인터페이스를 제공합니다.
- 사전 형식으로 속성에 접근할 수 있습니다(__getitem__, __setitem__, __delitem__).
- 속성 형식으로 속성에 접근 할 수 있습니다(__getattr__, __setattr__, __delattr__).
- __eq__, __contains__ 메소드가 구현되어 있습니다.
만약, 이 객체에 존재하는 속성의 이름과 같은 자바스크립트 오브젝트의 속성에 접근하려면, 사전 형식으로 원소에 접근하십시오.
사용 예는 다음과 같습니다.
>>> import mozrepl >>> repl = mozrepl.Mozrepl() >>> a = repl.execute('repl') >>> b = repl.execute('repl') >>> a == b # __eq__ True >>> '_name' in a # __contains__ True >>> a._name # __getattr__ u'repl' >>> a['_name'] # __getitem__ u'repl' >>> a['_name'] = 'pymozrepl' # __setitem__ >>> a['_name'] u'pymozrepl' >>> del a._name # __delattr__ >>> a._name None >>> for key, value in a: # __iter__ ...
- __iter__()¶
javascript Object에 iterator하게 접근합니다.
Yield: value; 오브젝트에 ‘__iterator__’ 속성이 존재한다면, Iterator를 사용하여 작업을 수행합니다. Yield: 별도의 이터레이터가 정의되어 있지 않다면, (key, value) 쌍을 전달합니다.
- __unicode__()¶
자바스크립트에서 이 오브젝트에 대한 참조값.
만약, 자바스크립트에서 직접 이 오브젝트에 대해 접근하기를 원한다면, 이 속성을 통해 변수 이름을 얻을 수 있습니다. 예컨데, 다음과 같이 사용 할 수 있습니다.
>>> import mozrepl >>> repl = mozrepl.Mozrepl() >>> obj = repl.execute('window') >>> unicode(obj) u'__pymozrepl_c8d7323280c54d09809e2dd7d34d1c70.ref["1e1c7ae3-c1fc-4664-b57f-1281bdc1c996"]' >>> repl.execute('var value = {reference}'.format(reference=obj))
- class mozrepl.type.Array(repl, uuid)¶
Bases: mozrepl.type.object.Object
javascript array에 대한 인터페이스를 제공합니다.
__len__, __iter__ 메소드가 구현되어 있습니다.
사용 예는 다음과 같습니다.
>>> import mozrepl >>> repl = mozrepl.Mozrepl() >>> array = repl.execute('[1,2,3,4,5,10]') >>> len(array) # __len__ 6 >>> list(array) # __iter__ [1, 2, 3, 4, 5, 10]
- __iter__()¶
javascript Object에 iterator하게 접근합니다.
Yield: value; 0 ~ 마지막 값까지 yield합니다.
- class mozrepl.type.Function(repl, uuid)¶
Bases: mozrepl.type.object.Object
javascript function에 대한 인터페이스를 제공합니다.
사용 예는 다음과 같습니다.
>>> import mozrepl >>> repl = mozrepl.Mozrepl() >>> func = repl.execute('(function(){ return "mozrepl"; })') #__call__ >>> func() u'mozrepl' >>> repl.execute('window').toString() #__call__ u'[object ChromeWindow]'
- __call__(*args)¶
javascript Function object를 실행합니다.
입력하는 각 인자는 convertToJs() 함수에서 허용하는 형식을 준수해야 합니다.
- class mozrepl.type.Raw(code)¶
자바스크립트 코드를 담는 클래스.
이 클래스로 생성된 코드는 convertToJs() 함수에 의해 변환되지 않고, 입력된 그대로 전달되게 됩니다.
Parameters: code (unicode) – 자바스크립트 코드.