seawolf2357 commited on
Commit
cfe72d3
·
verified ·
1 Parent(s): a65138c

Add unokit

Browse files
unokit/setup.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import os.path
3
+ cwd = os.getcwd()
4
+ os.chdir(os.path.dirname(__file__))
5
+ try:
6
+ from setuptools import setup, find_packages
7
+ setup(name='unokit',
8
+ packages=find_packages())
9
+ finally:
10
+ os.chdir(cwd)
unokit/unokit/__init__.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pyhwp : hwp file format parser in python
4
+ # Copyright (C) 2010,2011,2012 https://github.com/mete0r
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ import unohelper
20
+
21
+
22
+ class Base(unohelper.Base):
23
+
24
+ def __init__(self, context):
25
+ self.context = context
26
+
27
+
28
+ def component_context(f):
29
+ import unokit.contexts
30
+ def wrapper(self, *args, **kwargs):
31
+ unokit.contexts.push(self.context)
32
+ try:
33
+ return f(self, *args, **kwargs)
34
+ finally:
35
+ unokit.contexts.pop()
36
+ return wrapper
unokit/unokit/adapters.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pyhwp : hwp file format parser in python
4
+ # Copyright (C) 2010,2011,2012 https://github.com/mete0r
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ import uno
20
+ import unohelper
21
+ from com.sun.star.io import XInputStream, XSeekable, XOutputStream
22
+
23
+
24
+ class InputStreamFromFileLike(unohelper.Base, XInputStream, XSeekable):
25
+ ''' Implementation of XInputStream, XSeekable based on a file-like object
26
+
27
+ Implements com.sun.star.io.XInputStream and com.sun.star.io.XSeekable
28
+
29
+ :param f: a file-like object
30
+ '''
31
+ def __init__(self, f, dontclose=False):
32
+ self.f = f
33
+ self.dontclose = dontclose
34
+
35
+ def readBytes(self, aData, nBytesToRead):
36
+ data = self.f.read(nBytesToRead)
37
+ return len(data), uno.ByteSequence(data)
38
+
39
+ readSomeBytes = readBytes
40
+
41
+ def skipBytes(self, nBytesToSkip):
42
+ self.f.read(nBytesToSkip)
43
+
44
+ def available(self):
45
+ return 0
46
+
47
+ def closeInput(self):
48
+ if not self.dontclose:
49
+ self.f.close()
50
+
51
+ def seek(self, location):
52
+ self.f.seek(location)
53
+
54
+ def getPosition(self):
55
+ pos = self.f.tell()
56
+ return pos
57
+
58
+ def getLength(self):
59
+ pos = self.f.tell()
60
+ try:
61
+ self.f.seek(0, 2)
62
+ length = self.f.tell()
63
+ return length
64
+ finally:
65
+ self.f.seek(pos)
66
+
67
+
68
+ class OutputStreamToFileLike(unohelper.Base, XOutputStream):
69
+ ''' Implementation of XOutputStream based on a file-like object.
70
+
71
+ Implements com.sun.star.io.XOutputStream.
72
+
73
+ :param f: a file-like object
74
+ '''
75
+ def __init__(self, f, dontclose=False):
76
+ self.f = f
77
+ self.dontclose = dontclose
78
+
79
+ def writeBytes(self, bytesequence):
80
+ self.f.write(bytesequence.value)
81
+
82
+ def flush(self):
83
+ self.f.flush()
84
+
85
+ def closeOutput(self):
86
+ if not self.dontclose:
87
+ self.f.close()
88
+
89
+
90
+ class FileFromStream(object):
91
+ ''' A file-like object based on XInputStream/XOuputStream/XSeekable
92
+
93
+ :param stream: a stream object which implements
94
+ com.sun.star.io.XInputStream, com.sun.star.io.XOutputStream or
95
+ com.sun.star.io.XSeekable
96
+ '''
97
+ def __init__(self, stream):
98
+ self.stream = stream
99
+
100
+ if hasattr(stream, 'readBytes'):
101
+ def read(size=None):
102
+ if size is None:
103
+ data = ''
104
+ while True:
105
+ bytes = uno.ByteSequence('')
106
+ n_read, bytes = stream.readBytes(bytes, 4096)
107
+ if n_read == 0:
108
+ return data
109
+ data += bytes.value
110
+ bytes = uno.ByteSequence('')
111
+ n_read, bytes = stream.readBytes(bytes, size)
112
+ return bytes.value
113
+ self.read = read
114
+
115
+ if hasattr(stream, 'seek'):
116
+ self.tell = stream.getPosition
117
+
118
+ def seek(offset, whence=0):
119
+ if whence == 0:
120
+ pass
121
+ elif whence == 1:
122
+ offset += stream.getPosition()
123
+ elif whence == 2:
124
+ offset += stream.getLength()
125
+ stream.seek(offset)
126
+ self.seek = seek
127
+
128
+ if hasattr(stream, 'writeBytes'):
129
+ def write(s):
130
+ stream.writeBytes(uno.ByteSequence(s))
131
+ self.write = write
132
+
133
+ def flush():
134
+ stream.flush()
135
+ self.flush = flush
136
+
137
+ def close(self):
138
+ if hasattr(self.stream, 'closeInput'):
139
+ self.stream.closeInput()
140
+ elif hasattr(self.stream, 'closeOutput'):
141
+ self.stream.closeOutput()
unokit/unokit/configuration.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pyhwp : hwp file format parser in python
4
+ # Copyright (C) 2010,2011,2012 https://github.com/mete0r
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ def open_config(nodepath):
21
+ from unokit.services import css
22
+ from unokit.util import dict_to_propseq
23
+ provider = css.configuration.ConfigurationProvider()
24
+ param = dict_to_propseq(dict(nodepath=nodepath))
25
+ configaccess = 'com.sun.star.configuration.ConfigurationAccess'
26
+ return provider.createInstanceWithArguments(configaccess, param)
27
+
28
+
29
+ def get_soffice_product_info():
30
+ config = open_config('/org.openoffice.Setup')
31
+
32
+ # see schema in libreoffice/officecfg/registry/schema/org/office/Setup.xcs
33
+
34
+ version = tuple(int(x) for x in config.Product.ooSetupVersionAboutBox.split('.'))
35
+ if hasattr(config.Product, 'ooSetupVersionAboutBoxSuffix'):
36
+ # seems for libreoffice >= 3.5 only
37
+ version += (config.Product.ooSetupVersionAboutBoxSuffix,)
38
+ return dict(vendor=config.Product.ooVendor,
39
+ name=config.Product.ooName,
40
+ version=version,
41
+ locale=config.L10N.ooLocale)
unokit/unokit/contexts.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pyhwp : hwp file format parser in python
4
+ # Copyright (C) 2010,2011,2012 https://github.com/mete0r
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ import uno
20
+ import threading
21
+
22
+
23
+ tls = threading.local()
24
+ localcontext = uno.getComponentContext()
25
+
26
+
27
+ def get_stack():
28
+ try:
29
+ return tls.context_stack
30
+ except AttributeError:
31
+ tls.context_stack = []
32
+ return tls.context_stack
33
+
34
+
35
+ def push(context):
36
+ return get_stack().append(context)
37
+
38
+
39
+ def pop():
40
+ return get_stack().pop()
41
+
42
+
43
+ def get_current():
44
+ stack = get_stack()
45
+ if len(stack) == 0:
46
+ return localcontext
47
+ return stack[-1]
unokit/unokit/services.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pyhwp : hwp file format parser in python
4
+ # Copyright (C) 2010,2011,2012 https://github.com/mete0r
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ def create_service(name, *args):
21
+ import unokit.contexts
22
+ context = unokit.contexts.get_current()
23
+ sm = context.ServiceManager
24
+ if len(args) > 0:
25
+ return sm.createInstanceWithArgumentsAndContext(name, args, context)
26
+ else:
27
+ return sm.createInstanceWithContext(name, context)
28
+
29
+
30
+ class NamespaceNode(object):
31
+ def __init__(self, dotted_name):
32
+ self.dotted_name = dotted_name
33
+
34
+ def __getattr__(self, name):
35
+ return NamespaceNode(self.dotted_name + '.' + name)
36
+
37
+ def __call__(self, *args):
38
+ return create_service(self.dotted_name, *args)
39
+
40
+ def __iter__(self):
41
+ import unokit.contexts
42
+ context = unokit.contexts.get_current()
43
+ sm = context.ServiceManager
44
+ prefix = self.dotted_name + '.'
45
+ for name in sm.AvailableServiceNames:
46
+ if name.startswith(prefix):
47
+ basename = name[len(prefix):]
48
+ if basename.find('.') == -1:
49
+ yield basename
50
+
51
+
52
+ css = NamespaceNode('com.sun.star')
unokit/unokit/singletons.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pyhwp : hwp file format parser in python
4
+ # Copyright (C) 2010,2011,2012 https://github.com/mete0r
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ def get_singleton(name):
21
+ import unokit.contexts
22
+ context = unokit.contexts.get_current()
23
+ return context.getValueByName('/singletons/'+name)
24
+
25
+
26
+ def iter_singleton_names():
27
+ import unokit.contexts
28
+ context = unokit.contexts.get_current()
29
+ names = (name[len('/singletons/'):]
30
+ for name in context.ElementNames
31
+ if (name.startswith('/singletons/')
32
+ and not name.endswith('/service')))
33
+ return names
34
+
35
+
36
+ class NamespaceNode(object):
37
+ def __init__(self, dotted_name):
38
+ self.dotted_name = dotted_name
39
+
40
+ def __getattr__(self, name):
41
+ import unokit.contexts
42
+ context = unokit.contexts.get_current()
43
+ dotted_name = self.dotted_name + '.' + name
44
+ full_name = '/singletons/' + dotted_name
45
+ if full_name in context.ElementNames:
46
+ return context.getValueByName(full_name)
47
+ return NamespaceNode(self.dotted_name + '.' + name)
48
+
49
+ def __iter__(self):
50
+ prefix = self.dotted_name + '.'
51
+ for name in iter_singleton_names():
52
+ if name.startswith(prefix):
53
+ basename = name[len(prefix):]
54
+ if basename.find('.') == -1:
55
+ yield basename
56
+
57
+
58
+ css = NamespaceNode('com.sun.star')
unokit/unokit/tests/__init__.py ADDED
File without changes
unokit/unokit/tests/test_configuration.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pyhwp : hwp file format parser in python
4
+ # Copyright (C) 2010,2011,2012 https://github.com/mete0r
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ from unittest import TestCase
20
+
21
+
22
+ class TestBase(TestCase):
23
+ pass
24
+
25
+
26
+ class GetSofficeProductInfoTest(TestBase):
27
+ def test_basic(self):
28
+ from unokit.configuration import get_soffice_product_info
29
+ info = get_soffice_product_info()
30
+ self.assertTrue('name' in info)
31
+ self.assertTrue('vendor' in info)
32
+ self.assertTrue('version' in info)
33
+ self.assertTrue('locale' in info)
unokit/unokit/tests/test_singletons.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pyhwp : hwp file format parser in python
4
+ # Copyright (C) 2010,2011,2012 https://github.com/mete0r
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ from unittest import TestCase
20
+
21
+
22
+ class TestBase(TestCase):
23
+ pass
24
+
25
+
26
+ class TestSingletons(TestBase):
27
+ def test_extman(self):
28
+ from unokit.singletons import css
29
+ extman = css.deployment.ExtensionManager
30
+ self.assertTrue(extman is not None)
31
+
32
+ def test_pkginfo_prov(self):
33
+ from unokit.singletons import css
34
+ pkginfo_prov = css.deployment.PackageInformationProvider
35
+ self.assertTrue(pkginfo_prov is not None)
36
+
37
+ for ext_id, ext_ver in pkginfo_prov.ExtensionList:
38
+ ext_loc = pkginfo_prov.getPackageLocation(ext_id)
39
+ print ext_id, ext_ver, ext_loc
40
+ self.assertTrue(ext_loc != '')
unokit/unokit/tests/test_ucb.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pyhwp : hwp file format parser in python
4
+ # Copyright (C) 2010,2011,2012 https://github.com/mete0r
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ from unittest import TestCase
20
+
21
+
22
+ class TestBase(TestCase):
23
+ pass
24
+
25
+
26
+ class OpenURLTest(TestBase):
27
+ def test_basic(self):
28
+ #import os.path
29
+ #from uno import systemPathToFileUrl
30
+ from unokit.ucb import open_url
31
+
32
+ #path = os.path.abspath('fixtures/sample-5017.hwp')
33
+ #url = systemPathToFileUrl(path)
34
+ inputstream = open_url('http://google.com')
35
+ inputstream.closeInput()
unokit/unokit/ucb.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pyhwp : hwp file format parser in python
4
+ # Copyright (C) 2010,2011,2012 https://github.com/mete0r
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+
21
+ def open_url(url):
22
+ ''' open InputStream from a URL.
23
+
24
+ :param url: a URL to open an InputStream.
25
+ :returns: an instance of InputStream
26
+ '''
27
+
28
+ # see http://wiki.openoffice.org/wiki/Documentation/DevGuide/UCB/Using_the_UCB_API
29
+
30
+ from unokit.services import css
31
+ ucb = css.ucb.UniversalContentBroker('Local', 'Office')
32
+ content_id = ucb.createContentIdentifier(url)
33
+ content = ucb.queryContent(content_id)
34
+
35
+ import unohelper
36
+ from com.sun.star.io import XActiveDataSink
37
+ class DataSink(unohelper.Base, XActiveDataSink):
38
+ def setInputStream(self, stream):
39
+ self.stream = stream
40
+ def getInputStream(self):
41
+ return self.stream
42
+ datasink = DataSink()
43
+
44
+ from com.sun.star.ucb import Command, OpenCommandArgument2
45
+ openargs = OpenCommandArgument2()
46
+ openargs.Mode = 2 # OpenMode.DOCUMENT
47
+ openargs.Priority = 32768
48
+ openargs.Sink = datasink
49
+
50
+ command = Command()
51
+ command.Name = 'open'
52
+ command.Handle = -1
53
+ command.Argument = openargs
54
+
55
+ content.execute(command, 0, None)
56
+ return datasink.stream
unokit/unokit/util.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # pyhwp : hwp file format parser in python
4
+ # Copyright (C) 2010,2011,2012 https://github.com/mete0r
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ import uno
20
+
21
+
22
+ def unofy_value(value):
23
+ if isinstance(value, dict):
24
+ value = dict_to_propseq(value)
25
+ elif isinstance(value, list):
26
+ value = tuple(value)
27
+ return value
28
+
29
+
30
+ def xenumeration_list(xenum):
31
+ return list(iterate(xenum))
32
+
33
+
34
+ def dict_to_propseq(d):
35
+ from com.sun.star.beans import PropertyValue
36
+ DIRECT_VALUE = uno.Enum('com.sun.star.beans.PropertyState', 'DIRECT_VALUE')
37
+ return tuple(PropertyValue(k, 0, unofy_value(d[k]), DIRECT_VALUE)
38
+ for k in d)
39
+
40
+
41
+ def propseq_to_dict(propvalues):
42
+ return dict((p.Name, p.Value) for p in propvalues)
43
+
44
+
45
+ def enumerate(xenumaccess):
46
+ ''' Enumerate an instance of com.sun.star.container.XEnumerationAccess '''
47
+ if hasattr(xenumaccess, 'createEnumeration'):
48
+ xenum = xenumaccess.createEnumeration()
49
+ return iterate(xenum)
50
+ else:
51
+ return iter([])
52
+
53
+
54
+ def iterate(xenum):
55
+ ''' Iterate an instance of com.sun.star.container.XEnumeration '''
56
+ if hasattr(xenum, 'hasMoreElements'):
57
+ while xenum.hasMoreElements():
58
+ yield xenum.nextElement()
59
+
60
+
61
+ def dump(obj):
62
+ from binascii import b2a_hex
63
+ if hasattr(obj, 'ImplementationId'):
64
+ print 'Implementation Id:', b2a_hex(obj.ImplementationId.value)
65
+ print
66
+
67
+ if hasattr(obj, 'ImplementationName'):
68
+ print 'Implementation Name:', obj.ImplementationName
69
+ print
70
+
71
+ if hasattr(obj, 'SupportedServiceNames'):
72
+ print 'Supported Services:'
73
+ for x in obj.SupportedServiceNames:
74
+ print '', x
75
+ print
76
+
77
+ if hasattr(obj, 'Types'):
78
+ print 'Types:'
79
+ for x in obj.Types:
80
+ print '', x.typeClass.value, x.typeName
81
+ print
82
+
83
+
84
+ def dumpdir(obj):
85
+ print 'dir:'
86
+ for e in sorted(dir(obj)):
87
+ print '', e
88
+ print