コード例 #1
0
ファイル: schema.py プロジェクト: hforge/itools

stl_uri = 'http://www.hforge.org/xml-namespaces/stl'

stl_attributes = {
    'repeat': String,
    'if': String,
    'omit-tag': String}


class STLElement(ElementSchema):

    attributes = stl_attributes


stl_elements = [
    STLElement(name='block', is_inline=False),
    STLElement(name='inline', is_inline=True)]


stl_namespace = XMLNamespace(
    uri=stl_uri,
    prefix='stl',
    elements=stl_elements,
    attributes=stl_attributes)


# Register
register_namespace(stl_namespace)

コード例 #2
0
ファイル: schema.py プロジェクト: mmather02/itools
    ElementSchema('group'),
    ElementSchema('trans-unit'),
    ElementSchema('source'),
    ElementSchema('target'),
    ElementSchema('bin-unit'),
    ElementSchema('bin-source'),
    ElementSchema('bin-target'),
    ElementSchema('alt-trans'),
    # Inline
    ElementSchema('g'),
    ElementSchema('x'),
    ElementSchema('bx'),
    ElementSchema('ex'),
    ElementSchema('bpt'),
    ElementSchema('ept'),
    ElementSchema('sub'),
    ElementSchema('it'),
    ElementSchema('ph'),
    # Delimiter
    ElementSchema('mrk'),
]

#'urn:oasis:names:tc:xliff:document:1.1'
xliff_namespace = XMLNamespace('urn:oasis:names:tc:xliff:document:1.2', None,
                               xliff_elements)

###########################################################################
# Register
###########################################################################
register_namespace(xliff_namespace)
コード例 #3
0
    def get_element_schema(self, name):
        element = self.elements_kw.get(name)
        if element is not None:
            context = element.context or name
            return element(strict=self.strict, context=context)
        # Obsolete elements
        obsolete_element = self.obsolete_elements_kw.get(name)
        if obsolete_element is not None:
            if self.strict:
                message = 'unexpected element "{}"'
                raise XMLError(message.format(name))
            msg = 'WARNING HTML5: {} is an obsolete element'
            print(msg.format(name))
            context = obsolete_element.context or name
            return obsolete_element(strict=self.strict, context=context)
        # Custom elements are authorized if contains "-"
        # https://www.w3.org/TR/html5/infrastructure.html#extensibility-0
        # <itools-users></itools-users>
        if '-' in name:
            return WebComponentElement(name=name,
                                       strict=self.strict,
                                       context=name)
        raise XMLError('unexpected element "%s"' % name)


html_namespace = HTML5Namespace(strict=False)
###########################################################################
# Register
###########################################################################
register_namespace(html_namespace)
コード例 #4
0
ファイル: schema.py プロジェクト: kennym/itools
rng_file = ro_database.get_handler(rng_file, RelaxNGFile)
namespaces = rng_file.get_namespaces()

# Apply the metadata
for uri, element_name in inline_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.is_inline = True
for uri, element_name in skip_content_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.skip_content = True
for uri, element_name in unknown_elements:
    elements = namespaces[uri].elements
    if element_name in elements:
        raise ValueError, 'element "%s" is defined twice' % element_name
    elements[element_name] = ElementSchema(element_name,
                                           default_datatype=String)
for uri, element_name, context in contexts:
    element = namespaces[uri].get_element_schema(element_name)
    element.context = context

# The namespaces fo and svg have two names
fo_uri_2 = 'http://www.w3.org/1999/XSL/Format'
duplicate_ns(namespaces, fo_uri, fo_uri_2)
svg_uri_2 = 'http://www.w3.org/2000/svg'
duplicate_ns(namespaces, svg_uri, svg_uri_2)

# Register the namespaces
for uri, namespace in namespaces.iteritems():
    if not has_namespace(uri):
        register_namespace(namespace)
コード例 #5
0
ファイル: schema.py プロジェクト: pombredanne/itools
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from itools
from itools.datatypes import String
from itools.xml import register_namespace, ElementSchema, XMLNamespace

stl_uri = 'http://www.hforge.org/xml-namespaces/stl'

stl_attributes = {'repeat': String, 'if': String, 'omit-tag': String}


class STLElement(ElementSchema):

    attributes = stl_attributes


stl_elements = [
    STLElement('block', is_inline=False),
    STLElement('inline', is_inline=True)
]

stl_namespace = XMLNamespace(stl_uri, 'stl', stl_elements, stl_attributes)

# Register
register_namespace(stl_namespace)
コード例 #6
0
ファイル: schema.py プロジェクト: Ramel/itools
        (text_uri, 'p', 'paragraph'),
    ]


###########################################################################
# Make the namespaces
###########################################################################
# Read the Relax NG schema
rng_file = get_abspath('OpenDocument-v1.2-cd05-schema.rng')
rng_file = ODFRelaxNGFile(rng_file)
rng_file.auto_register()

# The namespaces fo and svg have two names
fo_uri_2 = 'http://www.w3.org/1999/XSL/Format'
namespace_fo = get_namespace(fo_uri)
register_namespace(namespace_fo(uri=fo_uri_2))

svg_uri_2 = 'http://www.w3.org/2000/svg'
namespace_svg = get_namespace(svg_uri)
register_namespace(namespace_svg(uri=svg_uri_2))

# Specific to OpenOffice
officeooo = XMLNamespace(uri='http://openoffice.org/2009/office',
                         prefix='officeooo',
                         elements=[],
                         free_atributes={
                             'rsid': String,
                             'paragraph-rsid': String
                         })
register_namespace(officeooo)
コード例 #7
0
            'property': 'og:site_name',
            'content': self.get_property('website_title')
        }, {
            'property': 'fb:admins',
            'content': self.get_property('fb_admins')
        }]


register_resource_class(ShopModule_Opengraph)

##############################
# Register opengraph schema
##############################

og_attributes = {'property': String, 'content': Unicode}


class OGElement(ElementSchema):

    attributes = og_attributes


og_elements = [
    OGElement('meta', skip_content=True),
]

og_namespace = XMLNamespace('http://opengraphprotocol.org/schema/', 'og',
                            og_elements, og_attributes)

register_namespace(og_namespace)
コード例 #8
0
ファイル: schema.py プロジェクト: Nabellaleen/itools
namespaces = rng_file.get_namespaces()

# Apply the metadata
for uri, element_name in inline_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.is_inline = True
for uri, element_name in skip_content_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.skip_content = True
for uri, element_name, context in contexts:
    element = namespaces[uri].get_element_schema(element_name)
    element.context = context

# The namespaces fo and svg have two names
fo_uri_2 = "http://www.w3.org/1999/XSL/Format"
duplicate_ns(namespaces, fo_uri, fo_uri_2)
svg_uri_2 = "http://www.w3.org/2000/svg"
duplicate_ns(namespaces, svg_uri, svg_uri_2)

# Register the namespaces
for uri, namespace in namespaces.iteritems():
    if not has_namespace(uri):
        register_namespace(namespace)

# Specific to OpenOffice
officeooo = XMLNamespace(
    "http://openoffice.org/2009/office", "officeooo", [], {"rsid": String, "paragraph-rsid": String}
)

register_namespace(officeooo)
コード例 #9
0
ファイル: opengraph.py プロジェクト: nicolasderam/shop
            {"property": "og:description", "content": resource.get_property("description")},
            {"property": "og:image", "content": thumb},
            {"property": "og:type", "content": "product"},
            {"property": "og:url", "content": url},
            {"property": "og:site_name", "content": self.get_property("website_title")},
            {"property": "fb:admins", "content": self.get_property("fb_admins")},
        ]


register_resource_class(ShopModule_Opengraph)

##############################
# Register opengraph schema
##############################

og_attributes = {"property": String, "content": Unicode}


class OGElement(ElementSchema):

    attributes = og_attributes


og_elements = [OGElement("meta", skip_content=True)]


og_namespace = XMLNamespace("http://opengraphprotocol.org/schema/", "og", og_elements, og_attributes)


register_namespace(og_namespace)
コード例 #10
0
ファイル: schema.py プロジェクト: hforge/itools
    ElementSchema(name='alt-trans'),
    # Inline
    ElementSchema(name='g'),
    ElementSchema(name='x'),
    ElementSchema(name='bx'),
    ElementSchema(name='ex'),
    ElementSchema(name='bpt'),
    ElementSchema(name='ept'),
    ElementSchema(name='sub'),
    ElementSchema(name='it'),
    ElementSchema(name='ph'),
    # Delimiter
    ElementSchema(name='mrk'),
]





#'urn:oasis:names:tc:xliff:document:1.1'
xliff_namespace = XMLNamespace(
    uri='urn:oasis:names:tc:xliff:document:1.2',
    prefix=None,
    elements=xliff_elements)


###########################################################################
# Register
###########################################################################
register_namespace(xliff_namespace)
コード例 #11
0
ファイル: schema.py プロジェクト: hforge/itools
        (text_uri, 'h', 'heading'),
        (text_uri, 'p', 'paragraph'),
        ]


###########################################################################
# Make the namespaces
###########################################################################
# Read the Relax NG schema
rng_file = get_abspath('OpenDocument-v1.2-cd05-schema.rng')
rng_file = ODFRelaxNGFile(rng_file)
rng_file.auto_register()

# The namespaces fo and svg have two names
fo_uri_2 = 'http://www.w3.org/1999/XSL/Format'
namespace_fo = get_namespace(fo_uri)
register_namespace(namespace_fo(uri=fo_uri_2))

svg_uri_2 = 'http://www.w3.org/2000/svg'
namespace_svg = get_namespace(svg_uri)
register_namespace(namespace_svg(uri=svg_uri_2))


# Specific to OpenOffice
officeooo = XMLNamespace(
    uri='http://openoffice.org/2009/office',
    prefix='officeooo',
    elements=[],
    free_atributes={'rsid': String, 'paragraph-rsid': String})
register_namespace(officeooo)
コード例 #12
0
ファイル: schema.py プロジェクト: kennym/itools
    Element('strike', common_attrs),
    Element('u', common_attrs),
    # XHTML 1.0 frameset
    EmptyBlockElement('frame', core_attrs + ['longdesc', 'name', 'src',
        'frameborder', 'marginwidth', 'marginheight', 'noresize',
        'scrolling']),
    BlockElement('frameset', core_attrs + ['rows', 'cols', 'onload',
        'onunload']),
    BlockElement('iframe', core_attrs + ['longdesc', 'name', 'src',
        'frameborder', 'marginwidth', 'marginheight', 'scrolling', 'align',
        'height', 'width']),
    BlockElement('noframes', common_attrs),
    # Vendor specific, not approved by W3C
    # for a talk about <embed> see:
    #   http://alistapart.com/articles/byebyeembed
    # FIXME Check the attribute list for <embed>
    EmptyBlockElement('embed', ['quality', 'pluginspage', 'src', 'type',
        'width', 'height']),
    ]



html_namespace = XMLNamespace(html_uri, None, html_elements)


###########################################################################
# Register
###########################################################################
register_namespace(html_namespace)

コード例 #13
0
ファイル: __init__.py プロジェクト: hforge/itws
from itools.core import get_abspath
from itools.datatypes import String
from itools.handlers import ro_database
from itools.relaxng import RelaxNGFile
from itools.xml import XMLNamespace, register_namespace

# Import from itws
from sitemap import SiteMap


#############################################################################
# SITEMAP
#############################################################################
# Required by the SiteMap
xsins_uri = 'http://www.w3.org/2001/XMLSchema-instance'
xsi_namespace = XMLNamespace(
    xsins_uri, 'xsi',
    free_attributes={'schemaLocation': String})
register_namespace(xsi_namespace)

# Read the Relax NG schema of SiteMap and register its namespace
rng_file = ro_database.get_handler(get_abspath('SiteMap-schema.rng'),
                                   RelaxNGFile)
for namespace in rng_file.namespaces.itervalues():
    # Remove sitemap prefix
    namespace.prefix = None
rng_file.auto_register()

# Silent pyflakes
SiteMap
コード例 #14
0
ファイル: relaxng.py プロジェクト: mmather02/itools
 def auto_register(self):
     for uri, namespace in self.namespaces.iteritems():
         if not has_namespace(uri):
             register_namespace(namespace)
コード例 #15
0
ファイル: relaxng.py プロジェクト: kennym/itools
 def auto_register(self):
     for uri, namespace in self.namespaces.iteritems():
         if not has_namespace(uri):
             register_namespace(namespace)
コード例 #16
0
ファイル: schema.py プロジェクト: pombredanne/itools
rng_file = ro_database.get_handler(rng_file, RelaxNGFile)
namespaces = rng_file.get_namespaces()

# Apply the metadata
for uri, element_name in inline_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.is_inline = True
for uri, element_name in skip_content_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.skip_content = True
for uri, element_name in unknown_elements:
    elements = namespaces[uri].elements
    if element_name in elements:
        raise ValueError, 'element "%s" is defined twice' % element_name
    elements[element_name] = ElementSchema(element_name,
                                           default_datatype=String)
for uri, element_name, context in contexts:
    element = namespaces[uri].get_element_schema(element_name)
    element.context = context

# The namespaces fo and svg have two names
fo_uri_2 = 'http://www.w3.org/1999/XSL/Format'
duplicate_ns(namespaces, fo_uri, fo_uri_2)
svg_uri_2 = 'http://www.w3.org/2000/svg'
duplicate_ns(namespaces, svg_uri, svg_uri_2)

# Register the namespaces
for uri, namespace in namespaces.iteritems():
    if not has_namespace(uri):
        register_namespace(namespace)
コード例 #17
0
ファイル: schema.py プロジェクト: mmather02/itools
namespaces = rng_file.get_namespaces()

# Apply the metadata
for uri, element_name in inline_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.is_inline = True
for uri, element_name in skip_content_elements:
    element = namespaces[uri].get_element_schema(element_name)
    element.skip_content = True
for uri, element_name, context in contexts:
    element = namespaces[uri].get_element_schema(element_name)
    element.context = context

# The namespaces fo and svg have two names
fo_uri_2 = 'http://www.w3.org/1999/XSL/Format'
duplicate_ns(namespaces, fo_uri, fo_uri_2)
svg_uri_2 = 'http://www.w3.org/2000/svg'
duplicate_ns(namespaces, svg_uri, svg_uri_2)

# Register the namespaces
for uri, namespace in namespaces.iteritems():
    if not has_namespace(uri):
        register_namespace(namespace)

# Specific to OpenOffice
officeooo = XMLNamespace(
    'http://openoffice.org/2009/office', 'officeooo', [],
    {'rsid': String, 'paragraph-rsid': String})

register_namespace(officeooo)