本文整理汇总了Python中exe.engine.uniqueidgenerator.UniqueIdGenerator类的典型用法代码示例。如果您正苦于以下问题:Python UniqueIdGenerator类的具体用法?Python UniqueIdGenerator怎么用?Python UniqueIdGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UniqueIdGenerator类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: TestUniqueId
class TestUniqueId(unittest.TestCase):
def setUp(self):
self.generator = UniqueIdGenerator("David's Gen", sys.argv[0])
def testGenerate(self):
howMany = 10000
values = {}
for x in range(howMany):
id = self.generator.generate()
self.assert_(id.isalnum())
values[id] = 1
self.assertEqual(howMany, len(values))
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:12,代码来源:testuniqueid.py
示例2: Manifest
class Manifest(object):
"""
Represents an imsmanifest xml file
"""
def __init__(self, config, outputDir, package, pages, scormType):
"""
Initialize
'outputDir' is the directory that we read the html from and also output
the mainfest.xml
"""
self.config = config
self.outputDir = outputDir
self.package = package
self.idGenerator = UniqueIdGenerator(package.name, config.exePath)
self.pages = pages
self.itemStr = ""
self.resStr = ""
self.scormType = scormType
self.dependencies = {}
def createMetaData(self, template):
"""
if user did not supply metadata title, description or creator
then use package title, description, or creator in imslrm
if they did not supply a package title, use the package name
if they did not supply a date, use today
"""
lrm = self.package.dublinCore.__dict__.copy()
if lrm.get('title', '') == '':
lrm['title'] = self.package.title
if lrm['title'] == '':
lrm['title'] = self.package.name
if lrm.get('description', '') == '':
lrm['description'] = self.package.description
if lrm['description'] == '':
lrm['description'] = self.package.name
if lrm.get('creator', '') == '':
lrm['creator'] = self.package.author
if lrm['date'] == '':
lrm['date'] = time.strftime('%Y-%m-%d')
# if they don't look like VCARD entries, coerce to fn:
for f in ('creator', 'publisher', 'contributors'):
if re.match('.*[:;]', lrm[f]) == None:
lrm[f] = u'FN:' + lrm[f]
xml = template % lrm
return xml
def save(self, filename):
"""
Save a imsmanifest file to self.outputDir
"""
out = open(self.outputDir/filename, "w")
if filename == "imsmanifest.xml":
out.write(self.createXML().encode('utf8'))
out.close()
if self.scormType == "scorm1.2":
templateFilename = self.config.xulDir/'templates'/'imslrm.xml'
template = open(templateFilename, 'rb').read()
xml = self.createMetaData(template)
out = open(self.outputDir/'imslrm.xml', 'wb')
out.write(xml.encode('utf8'))
out.close()
def createXML(self):
"""
returning XLM string for manifest file
"""
manifestId = unicode(self.idGenerator.generate())
orgId = unicode(self.idGenerator.generate())
# Add the namespaces
if self.scormType == "scorm1.2":
xmlStr = u'<?xml version="1.0" encoding="UTF-8"?>\n'
xmlStr += u'<!-- generated by eXe - http://exelearning.org -->\n'
xmlStr += u'<manifest identifier="'+manifestId+'" '
xmlStr += u'xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2" '
xmlStr += u'xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2" '
xmlStr += u'xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2" '
xmlStr += u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
xmlStr += u"xsi:schemaLocation=\"http://www.imsproject.org/xsd/"
xmlStr += u"imscp_rootv1p1p2 imscp_rootv1p1p2.xsd "
xmlStr += u"http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 "
xmlStr += u"imsmd_rootv1p2p1.xsd "
xmlStr += u"http://www.adlnet.org/xsd/adlcp_rootv1p2 "
xmlStr += u"adlcp_rootv1p2.xsd\" "
xmlStr += u"> \n"
xmlStr += u"<metadata> \n"
xmlStr += u" <schema>ADL SCORM</schema> \n"
xmlStr += u" <schemaversion>1.2</schemaversion> \n"
xmlStr += u" <adlcp:location>imslrm.xml"
xmlStr += u"</adlcp:location> \n"
xmlStr += u"</metadata> \n"
elif self.scormType == "scorm2004":
xmlStr = u'<?xml version="1.0" encoding="UTF-8"?>\n'
xmlStr += u'<!-- generated by eXe - http://exelearning.org -->\n'
xmlStr += u'<manifest identifier="'+manifestId+'" '
xmlStr += u'xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2" '
xmlStr += u'xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2" '
#.........这里部分代码省略.........
开发者ID:giorgil2,项目名称:eXe,代码行数:101,代码来源:scormexport.py
示例3: Manifest
class Manifest(object):
"""
Represents an imsmanifest xml file
"""
def __init__(self, config, outputDir, package, pages, scormType, metadataType):
"""
Initialize
'outputDir' is the directory that we read the html from and also output
the mainfest.xml
"""
self.config = config
self.outputDir = outputDir
self.package = package
self.idGenerator = UniqueIdGenerator(package.name, config.exePath)
self.pages = pages
self.itemStr = ""
self.resStr = ""
self.scormType = scormType
self.metadataType = metadataType
self.dependencies = {}
def createMetaData(self, template):
"""
if user did not supply metadata title, description or creator
then use package title, description, or creator in imslrm
if they did not supply a package title, use the package name
if they did not supply a date, use today
"""
xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
namespace = 'xmlns="http://ltsc.ieee.org/xsd/LOM" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ltsc.ieee.org/xsd/LOM lomCustom.xsd"'
# depending on (user desired) the metadata type:
if self.metadataType == "LOMES":
output = StringIO.StringIO()
metadata = copy.deepcopy(self.package.lomEs)
title = metadata.get_general().get_title() or lomsubs.titleSub([])
if not title.get_string():
title.add_string(lomsubs.LangStringSub(self.package.lang.encode("utf-8"), self.package.name))
metadata.get_general().set_title(title)
metadata.export(output, 0, namespacedef_=namespace, pretty_print=False)
xml += output.getvalue()
if self.metadataType == "LOM":
output = StringIO.StringIO()
metadata = copy.deepcopy(self.package.lom)
title = metadata.get_general().get_title() or lomsubs.titleSub([])
if not title.get_string():
title.add_string(lomsubs.LangStringSub(self.package.lang.encode("utf-8"), self.package.name))
metadata.get_general().set_title(title)
metadata.export(output, 0, namespacedef_=namespace, pretty_print=False)
xml += output.getvalue()
if self.metadataType == "DC":
lrm = self.package.dublinCore.__dict__.copy()
# use package values in absentia:
if lrm.get("title", "") == "":
lrm["title"] = self.package.title
if lrm["title"] == "":
lrm["title"] = self.package.name
if lrm.get("description", "") == "":
lrm["description"] = self.package.description
if lrm["description"] == "":
lrm["description"] = self.package.name
if lrm.get("creator", "") == "":
lrm["creator"] = self.package.author
if lrm["date"] == "":
lrm["date"] = time.strftime("%Y-%m-%d")
# if they don't look like VCARD entries, coerce to fn:
for f in ("creator", "publisher", "contributors"):
if re.match(".*[:;]", lrm[f]) == None:
lrm[f] = u"FN:" + lrm[f]
xml = template % lrm
return xml
def save(self, filename):
"""
Save a imsmanifest file to self.outputDir
Two works: createXML and createMetaData
"""
out = open(self.outputDir / filename, "w")
if filename == "imsmanifest.xml":
out.write(self.createXML().encode("utf8"))
out.close()
# now depending on metadataType, <metadata> content is diferent:
if self.scormType == "scorm1.2" or self.scormType == "scorm2004":
if self.metadataType == "DC":
# if old template is desired, select imslrm.xml file:\r
# anything else, yoy should select:
templateFilename = self.config.webDir / "templates" / "imslrm.xml"
template = open(templateFilename, "rb").read()
elif self.metadataType == "LOMES":
template = None
elif self.metadataType == "LOM":
template = None
# Now the file with metadatas.
# Notice that its name is independent of metadataType:
xml = self.createMetaData(template)
out = open(self.outputDir / "imslrm.xml", "wb")
out.write(xml.encode("utf8"))
out.close()
def createXML(self):
#.........这里部分代码省略.........
开发者ID:RichDijk,项目名称:eXe,代码行数:101,代码来源:scormexport.py
示例4: Manifest
class Manifest(object):
"""
Represents an imsmanifest xml file
"""
def __init__(self, config, outputDir, package, pages, metadataType):
"""
Initialize
'outputDir' is the directory that we read the html from and also output
the mainfest.xml
"""
self.config = config
self.outputDir = outputDir
self.package = package
self.idGenerator = UniqueIdGenerator(package.name, config.exePath)
self.pages = pages
self.metadataType = metadataType
self.itemStr = ""
self.resStr = ""
def createMetaData(self):
"""
if user did not supply metadata title, description or creator
then use package title, description, or creator in imslrm
if they did not supply a package title, use the package name
if they did not supply a date, use today
"""
xml = ""
namespace = "lom:"
# depending on (user desired) the metadata type:
if self.metadataType == "LOMES":
output = StringIO.StringIO()
metadata = copy.deepcopy(self.package.lomEs)
title = metadata.get_general().get_title() or lomsubs.titleSub([])
if not title.get_string():
title.add_string(lomsubs.LangStringSub(self.package.lang.encode("utf-8"), self.package.name))
metadata.get_general().set_title(title)
metadata.export(output, 0, namespace_=namespace, pretty_print=False)
xml = output.getvalue()
if self.metadataType == "LOM":
output = StringIO.StringIO()
metadata = copy.deepcopy(self.package.lom)
title = metadata.get_general().get_title() or lomsubs.titleSub([])
if not title.get_string():
title.add_string(lomsubs.LangStringSub(self.package.lang.encode("utf-8"), self.package.name))
metadata.get_general().set_title(title)
metadata.export(output, 0, namespace_=namespace, pretty_print=False)
xml = output.getvalue()
if self.metadataType == "DC":
lrm = self.package.dublinCore.__dict__.copy()
# use package values in absentia:
if lrm.get("title", "") == "":
lrm["title"] = self.package.title
if lrm["title"] == "":
lrm["title"] = self.package.name
if lrm.get("description", "") == "":
lrm["description"] = self.package.description
if lrm["description"] == "":
lrm["description"] = self.package.name
if lrm.get("creator", "") == "":
lrm["creator"] = self.package.author
if lrm["date"] == "":
lrm["date"] = time.strftime("%Y-%m-%d")
# if they don't look like VCARD entries, coerce to fn:
for f in ("creator", "publisher", "contributors"):
if re.match(".*[:;]", lrm[f]) == None:
lrm[f] = u"FN:" + lrm[f]
templateFilename = self.config.webDir / "templates" / "imslrm.xml"
template = open(templateFilename, "rb").read()
xml = template % lrm
out = open(self.outputDir / "imslrm.xml", "wb")
out.write(xml.encode("utf8"))
out.close()
xml = "<adlcp:location>imslrm.xml</adlcp:location>"
return xml
def save(self, filename):
"""
Save a imsmanifest file to self.outputDir
"""
out = open(self.outputDir / filename, "w")
if filename == "imsmanifest.xml":
out.write(self.createXML().encode("utf8"))
out.close()
def createXML(self):
"""
returning XLM string for manifest file
"""
manifestId = self.idGenerator.generate()
orgId = self.idGenerator.generate()
xmlStr = (
u"""<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by eXe - http://exelearning.net -->
<manifest identifier="%s"
xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lom="http://ltsc.ieee.org/xsd/LOM"
#.........这里部分代码省略.........
开发者ID:RichDijk,项目名称:eXe,代码行数:101,代码来源:imsexport.py
示例5: Manifest
class Manifest(object):
"""
Represents an imsmanifest xml file
"""
def __init__(self, config, outputDir, package, pages, scormType, metadataType):
"""
Initialize
'outputDir' is the directory that we read the html from and also output
the mainfest.xml
"""
self.config = config
self.outputDir = outputDir
self.package = package
self.idGenerator = UniqueIdGenerator(package.name, config.exePath)
self.pages = pages
self.itemStr = ""
self.resStr = ""
self.scormType = scormType
self.metadataType = metadataType
self.dependencies = {}
def _validateMetaData(self, metadata):
modifiedMetaData = False
fieldsModified = []
if metadata.get_general().get_description():
for description in metadata.get_general().get_description():
strings = description.get_string()
for string in strings:
value = string.get_valueOf_()
# general description: The field must be 1000 characters maximum, standard SCORM 2.1
if len(value) > 1000:
string.set_valueOf_(value[:1000])
modifiedMetaData = True
fieldsModified.append(_('general description'))
if metadata.get_educational():
for educational in metadata.get_educational():
if educational.get_description():
for description in educational.get_description():
strings = description.get_string()
for string in strings:
value = string.get_valueOf_()
# educational description: The field must be 1000 characters maximum, standard SCORM 2.1
if len(value) > 1000:
string.set_valueOf_(value[:1000])
modifiedMetaData = True
fieldsModified.append(_('educational description'))
return {'modifiedMetaData': modifiedMetaData, 'fieldsModified': fieldsModified}
def createMetaData(self, template):
"""
if user did not supply metadata title, description or creator
then use package title, description, or creator in imslrm
if they did not supply a package title, use the package name
if they did not supply a date, use today
"""
xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
namespace = 'xmlns="http://ltsc.ieee.org/xsd/LOM" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ltsc.ieee.org/xsd/LOM lomCustom.xsd"'
modifiedMetaData = False
# depending on (user desired) the metadata type:
if self.metadataType == 'LOMES':
output = StringIO.StringIO()
metadata = copy.deepcopy(self.package.lomEs)
title = metadata.get_general().get_title() or lomsubs.titleSub([])
if not title.get_string():
title.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), self.package.name))
metadata.get_general().set_title(title)
if self.scormType == "scorm1.2":
modifiedMetaData = self._validateMetaData(metadata)
if self.package.exportSource:
technical = metadata.get_technical()
if not technical:
technical = lomsubs.technicalSub('technical')
metadata.set_technical(technical)
opr = technical.get_otherPlatformRequirements()
if not opr:
opr = lomsubs.otherPlatformRequirementsSub()
technical.set_otherPlatformRequirements(opr)
opr.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), 'editor: eXe Learning'))
found = False
for platform in opr.get_string():
if platform.get_valueOf_() == self.package.lomESPlatformMark:
found = True
if not found:
opr.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), self.package.lomESPlatformMark))
metadata.export(output, 0, namespacedef_=namespace, pretty_print=False)
xml += output.getvalue()
if self.metadataType == 'LOM':
output = StringIO.StringIO()
metadata = copy.deepcopy(self.package.lom)
title = metadata.get_general().get_title() or lomsubs.titleSub([])
if not title.get_string():
#.........这里部分代码省略.........
开发者ID:exelearning,项目名称:iteexe,代码行数:101,代码来源:scormexport.py
示例6: setUp
def setUp(self):
self.generator = UniqueIdGenerator("David's Gen", sys.argv[0])
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:2,代码来源:testuniqueid.py
注:本文中的exe.engine.uniqueidgenerator.UniqueIdGenerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论