cti.session
index
/home/miyabe/workspaces/copper_drivers/cti.python/src/code/cti/session.py

$Id: session.py 935 2013-05-31 06:46:26Z miyabe $

 
Modules
       
os
select
sys
tempfile

 
Classes
       
builtins.Exception(builtins.BaseException)
IllegalStateError
builtins.object
MainOut
Resource
ResourceOut
Session

 
class IllegalStateError(builtins.Exception)
    IllegalStateError(message)
 
関数の呼び出し順が不適切な場合に発生する例外です。
 
 
Method resolution order:
IllegalStateError
builtins.Exception
builtins.BaseException
builtins.object

Methods defined here:
__init__(self, message)
Initialize self.  See help(type(self)) for accurate signature.
__str__(self)
Return str(self).

Data descriptors defined here:
__weakref__
list of weak references to the object

Static methods inherited from builtins.Exception:
__new__(*args, **kwargs) class method of builtins.Exception
Create and return a new object.  See help(type) for accurate signature.

Methods inherited from builtins.BaseException:
__delattr__(self, name, /)
Implement delattr(self, name).
__getattribute__(self, name, /)
Return getattr(self, name).
__reduce__(...)
Helper for pickle.
__repr__(self, /)
Return repr(self).
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
__setstate__(...)
add_note(...)
Exception.add_note(note) --
add a note to the exception
with_traceback(...)
Exception.with_traceback(tb) --
set self.__traceback__ to tb and return self.

Data descriptors inherited from builtins.BaseException:
__cause__
exception cause
__context__
exception context
__dict__
__suppress_context__
__traceback__
args

 
class MainOut(builtins.object)
    MainOut(io, session)
 

 
  Methods defined here:
__enter__(self)
__exit__(self, exc_type, exc_value, traceback)
__init__(self, io, session)
Initialize self.  See help(type(self)) for accurate signature.
close(self)
write(self, s)

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class Resource(builtins.object)
    Resource(io, uri)
 

 
  Methods defined here:
__init__(self, io, uri)
Initialize self.  See help(type(self)) for accurate signature.
finish(self)
found(self, opts={})
サーバーから要求されたリソースが見つかった場合の処理をします。
 
opts: リソースオプション(ハッシュ型で、'mime_type', 'encoding', 'length'というキーでデータ型、文字コード、長さを設定することができます。)
 
戻り値: 出力先ストリームが返されます。
 
例:
Session#resolver を参照してください。
missing(self)

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class ResourceOut(builtins.object)
    ResourceOut(io)
 

 
  Methods defined here:
__enter__(self)
__exit__(self, exc_type, exc_value, traceback)
__init__(self, io)
Initialize self.  See help(type(self)) for accurate signature.
close(self)
write(self, s)

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class Session(builtins.object)
    Session(io, options={})
 

 
  Methods defined here:
__enter__(self)
__exit__(self, exc_type, exc_value, traceback)
__init__(self, io, options={})
セッションのコンストラクタです。
セッションの作成は通常DriverManager.phpのcti_get_sessionで行うため、
ユーザーがコンストラクタを直接呼び出す必要はありません。
 
io: ソケット
options: 接続オプション
abort(self, mode)
変換処理の中断を要求します。
 
mode: 中断モード 0=生成済みのデータを出力して中断, 1=即時中断
build_next(self)
close(self)
セッションを閉じます。
get_server_info(self, uri)
サーバー情報を返します。
詳細は{オンラインのドキュメント}[http://sourceforge.jp/projects/copper/wiki/CTIP2.0%E3%81%AE%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E6%83%85%E5%A0%B1]をご覧下さい
 
uri: サーバー情報のURI
 
返り値: サーバー情報のデータ文字列(XML)
join(self)
結果を結合します。
 
先にSession#set_continuous を呼び出しておく必要があります。
property(self, name, value)
プロパティを設定します。
 
セッションを作成した直後に呼び出してください。
利用可能なプロパティの一覧は{資料集}[http://dl.cssj.jp/docs/copper/3.0/html/5100_io-properties.html]を参照してください
 
name: 名前
value: 値
reset(self)
全ての状態をリセットします。
resource(self, uri, opts={})
リソース送信処理を行います。
Session#transcode および Session#transcode_server の前に呼び出してください。
 
uri: 仮想URI
opts: リソースオプション(ハッシュ型で、'mime_type', 'encoding', 'length'というキーでデータ型、文字コード、長さを設定することができます。)
 
戻り値: リソースの出力先ストリームが返されます。
 
例:
    out = session.resource('test.css', {'mime_type': 'test/css'})
    try:
        file = open('data/test.css')
        try:
            out.write(file.read())
        finally:
            file.close()
    finally:
        out.close()
set_continuous(self, continuous)
複数の結果を結合するモードを切り替えます。
モードが有効な場合、 Session#join の呼び出しで複数の結果を結合して返します。
 
Session#transcode およびSession#transcode_server の前に呼び出してください。
 
continuous: 有効にするにはtrue
set_message_func(self, message_func)
エラーメッセージ受信のためのコールバック関数を設定します。
 
Session#transcode および Session#transcode_server の前に呼び出してください。
コールバック関数の引数は、エラーコード(int)、メッセージ(str)、付属データ(配列)です。
 
message_func: 関数
 
例:
    def message_func(code, message, args):
        print("{:X} {}".format(code, message))
    session.set_message_func(message_func)
set_output_as_directory(self, dir, prefix='', suffix='')
変換結果の出力先ディレクトリ名を指定します。
 
Session#set_results の簡易版です。
こちらは、複数の結果をファイルとして出力するディレクトリ名を直接設定することができます。
ファイル名は prefix ページ番号 suffix をつなげたものです。
 
dir: 出力先ディレクトリ名
prefix: 出力するファイルの名前の前に付ける文字列
suffix: 出力するファイルの名前の後に付ける文字列
set_output_as_file(self, file)
変換結果の出力先ファイル名を指定します。
 
Session#set_results の簡易版です。
こちらは、1つだけ結果を出力するファイル名を直接設定することができます。
 
file: 出力先ファイル名
set_output_as_stream(self, out)
変換結果の出力先リソースを指定します。
 
Session#set_results の簡易版です。
こちらは、1つだけの結果出力先を直接設定することができます。
 
out: 出力先 IO オブジェクト
set_progress_func(self, progress_func)
進行状況受信のためのコールバック関数を設定します。
 
Session#transcode および Session#transcode_server の前に呼び出してください。
コールバック関数の引数は、全体のバイト数(int)、読み込み済みバイト数(int)です。
 
progress_func: 関数
 
例:
    def progress_func(length, read):
        print("{} {}".format(length, read))
    session.set_progress_func(progress_func)
set_resolver_func(self, resolver_func)
リソース解決のためのコールバック関数を設定します。
 
Session#transcode および Session#transcode_server の前に呼び出してください。
コールバック関数の引数は、URI(str)、リソース出力クラス( Resource )です。
 
resolver_func: 関数
 
URIに対応するリソースが見つかった場合、 Resource#found メソッドを呼び出してください。
foundの呼び出しがない場合、リソースは見つからなかったものと扱われます。
 
例:
    def resolver(uri, r):
        if os.path.exists(uri):
            out = r.found()
            try:
                file = open(uri)
                try:
                    out.write(file.read())
                finally:
                    file.close()
            finally:
                out.close()
    session.set_resolver_func(resolver)
set_results(self, results)
変換結果の出力先を指定します。
 
Session#transcode および Session#transcode_server の前に呼び出してください。
この関数を呼び出さないデフォルトの状態では、出力先は標準出力( sys.__stdout__ )になります。
 
また、デフォルトの状態では、自動的にContent-Type, Content-Lengthヘッダが送出されます。
 
results: 出力先のResults オブジェクト
transcode(self, uri='.', opts={})
変換対象の文書リソースを送信し、変換処理を行います。
 
uri: 仮想URI
opts: リソースオプション(ハッシュ型で、'mime_type', 'encoding', 'length'というキーでデータ型、文字コード、長さを設定することができます。)
 
戻り値: リソースの出力先ストリームが返されます。
 
例:
    out = session.transcode('.', {'mime_type': 'text/html'})
    try:
        file = open('data/test.html')
        try:
            out.write(file.read())
        finally:
            file.close()
    finally:
        out.close()
transcode_server(self, uri)
サーバー側リソースを変換します。
 
uri: URI

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
Functions
       
calcsize(format, /)
Return size in bytes of the struct described by the format string.
iter_unpack(format, buffer, /)
Return an iterator yielding tuples unpacked from the given bytes.
 
The bytes are unpacked according to the format string, like
a repeated invocation of unpack_from().
 
Requires that the bytes length be a multiple of the format struct size.
pack(...)
pack(format, v1, v2, ...) -> bytes
 
Return a bytes object containing the values v1, v2, ... packed according
to the format string.  See help(struct) for more on format strings.
pack_into(...)
pack_into(format, buffer, offset, v1, v2, ...)
 
Pack the values v1, v2, ... according to the format string and write
the packed bytes into the writable buffer buf starting at offset.  Note
that the offset is a required argument.  See help(struct) for more
on format strings.
unpack(format, buffer, /)
Return a tuple containing values unpacked according to the format string.
 
The buffer's size in bytes must be calcsize(format).
 
See help(struct) for more on format strings.
unpack_from(format, /, buffer, offset=0)
Return a tuple containing values unpacked according to the format string.
 
The buffer's size, minus offset, must be at least calcsize(format).
 
See help(struct) for more on format strings.

 
Data
        CTI_BUFFER_SIZE = 1024
FRG_MEM_SIZE = 256
ON_MEMORY = 1048576
REQ_ABORT = 50
REQ_CLIENT_RESOURCE = 4
REQ_CLOSE = 66
REQ_CONTINUOUS = 5
REQ_DATA = 17
REQ_EOF = 49
REQ_JOIN = 51
REQ_MISSING_RESOURCE = 34
REQ_PROPERTY = 1
REQ_RESET = 65
REQ_SERVER_INFO = 81
REQ_SERVER_MAIN = 3
REQ_START_MAIN = 2
REQ_START_RESOURCE = 33
RES_ABORT = 50
RES_ADD_BLOCK = 18
RES_BLOCK_DATA = 17
RES_CLOSE_BLOCK = 24
RES_DATA = 23
RES_EOF = 49
RES_INSERT_BLOCK = 19
RES_MAIN_LENGTH = 21
RES_MAIN_READ = 22
RES_MESSAGE = 20
RES_NEXT = 51
RES_RESOURCE_REQUEST = 33
RES_START_DATA = 1
SEGMENT_SIZE = 8192