开发者

Is there a unicodedata module for IronPython?

I'm trying to get the generic sample code for the selenium2 Sauce OnDemand service working with IronPython, for some test work I'm doing, and I've run into a problem I can't quite figure out.

First, Here's the environment:

Windows 7 Home Premium, 64bit.

IronPython 2.7.0.40 on .Net 4.0.30319.225

My path:

>>> sys.path
['.', 'C:\\users\\me\\scripts\\python', 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\Extensions\\Microsoft\\IronStudio\\0.4\\Lib', 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\Extensions\\Microsoft\\IronStudio\\0.4\\DLLs', 'C:\\opt\\win\\ipy\\Lib', 'C:\\opt\\win\\ipy\\DLLs', 'C:\\opt\\win\\ipy']  

I'm aware that IronPython has issues using compressed eggs, so I've extracted the following libraries into the \Lib directory on the sys.path:

selenium (2.0b4dev)

rdflib (3.1.0)

Now, the sample code from Sauce Labs:

import unittest
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

class Selenium2OnSauce(unittest.TestCase):

    def setUp(self):
        desired_capabilities = dict(platform="WINDOWS",
                                    browserName="firefox",
                                    version="3.6", 
                                    name="Hello, Selenium 2!")
        self.driver = webdriver.Remote(
            desired_capabilities=desired_capabilities,
            command_executor="http://me:my-site-access-key@ondemand.saucelabs.com:80/wd/hub")

    def test_sauce(self):
        self.driver.get('http://example.saucelabs.com')
        assert "Sauce Labs" in self.driver.title

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()

Here's the error I'm getting:

开发者_StackOverflow社区Traceback (most recent call last):
File "selenium2_test.py", line 3, in <module>
File "c:\opt\win\ipy\Lib\selenium\webdriver\__init__.py", line 18, in <module>
File "c:\opt\win\ipy\Lib\selenium\webdriver\firefox\webdriver.py", line 24, in <module>
File "c:\opt\win\ipy\Lib\selenium\webdriver\firefox\firefox_profile.py", line 23, in <module>
File "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\IronStudio\0.4\Lib\rdflib\__init__.py", line 65, in <module>
File "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\IronStudio\0.4\Lib\rdflib\namespace.py", line 282, in <module>
ImportError: No module named unicodedata

I've tried searching for packages with unicodedata in them (such as FePY), but none of them seem to work. I've tried copying the .pyd from my Python27 installation, but that didn't work either.

Is this something that's not yet available in IronPython 2.7? Alternatively, is there a library or namespace I can reference to accomplish the same task?

If not, I guess I'll have to go without selenium2 until the Iron guys get a unicodedata for IP27. :(

Thanks,

Greg.


Alas, the unicodedata module is currently not included in IronPython. But fear not! For the upcoming 2.7.1 release will have it, and all of your troubles shall be no more.

Sorry about that. As for when 2.7.1 will be released, I'm thinking early June. You can check https://github.com/IronLanguages/main/commit/5395af28b5794b0acf982ab87d17466925ab819f for the patch, but it's fairly large and fiddly because of the included Unicode database.


See @Micheal Greene's comments on the original question. Here is the module with the edits as directed:

# Copyright (c) 2006 by Seo Sanghyeon
# 2006-07-13 sanxiyn Created
# 2006-07-19 sanxiyn Added unidata_version, normalize
# Modified 2011 - Greg Gauthier - To provide needed functionality for rdflib
#                                 and other utilities, in IronPython 2.7.0

unidata_version = '3.2.0'

# --------------------------------------------------------------------
# Normalization

from System import String
from System.Text import NormalizationForm

def normalize(form, string):
    return String.Normalize(string, _form_mapping[form])

_form_mapping = {
    'NFC': NormalizationForm.FormC,
    'NFKC': NormalizationForm.FormKC,
    'NFD': NormalizationForm.FormD,
    'NFKD': NormalizationForm.FormKD,
}

# --------------------------------------------------------------------
# Character properties

from System.Globalization import CharUnicodeInfo

def _handle_default(function):
    def wrapper(unichr, default=None):
        result = function(unichr)
        if result != -1:
            return result
        if default is None:
            raise ValueError()
        return default
    return wrapper

decimal = _handle_default(CharUnicodeInfo.GetDecimalDigitValue)
digit = _handle_default(CharUnicodeInfo.GetDigitValue)
numeric = _handle_default(CharUnicodeInfo.GetNumericValue)

def category(unichr):
    uc = CharUnicodeInfo.GetUnicodeCategory(unichr)
    return _category_mapping[int(uc)]

_category_mapping = {
    0: 'Lu',
    1: 'Ll',
    2: 'Lt',
    3: 'Lm',
    4: 'Lo',
    5: 'Mn',
    6: 'Mc',
    7: 'Me',
    8: 'Nd',
    9: 'Nl',
    10: 'No',
    11: 'Zs',
    12: 'Zl',
    13: 'Zp',
    14: 'Cc',
    15: 'Cf',
    16: 'Cs',
    17: 'Co',
    18: 'Pc',
    19: 'Pd',
    20: 'Ps',
    21: 'Pe',
    22: 'Pi',
    23: 'Pf',
    24: 'Po',
    25: 'Sm',
    26: 'Sc',
    27: 'Sk',
    28: 'So',
    29: 'Cn',
}

# added for rdflib/ironpython
def decomposition(unichr): 
    return String.Normalize(unichr.ToString(), NormalizationForm.FormD)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜