Fix multibyte character problem

Fixed problem that causes a UnicodeEncodeError when use multi-byte characters in the job.yml.

Change-Id: Ie715c827a794e73fae11cdca079ea80cfb8c280d
This commit is contained in:
Kei YAMAZAKI 2013-12-29 01:45:38 +09:00
parent 777a29aa8a
commit 604d39305b
42 changed files with 61 additions and 40 deletions

View File

@ -381,7 +381,7 @@ class XmlJob(object):
def output(self):
out = minidom.parseString(XML.tostring(self.xml))
out = out.toprettyxml(indent=' ')
out = out.toprettyxml(indent=' ', encoding='utf-8')
return self.pretty_text_re.sub('>\g<1></', out)

View File

@ -17,6 +17,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import codecs
import os
import re
import doctest
@ -61,7 +62,7 @@ class BaseTestCase(object):
def __read_content(self):
# Read XML content, assuming it is unicode encoded
xml_filepath = os.path.join(self.fixtures_path, self.xml_filename)
xml_content = u"%s" % open(xml_filepath, 'r').read()
xml_content = u"%s" % codecs.open(xml_filepath, 'r', 'utf-8').read()
yaml_filepath = os.path.join(self.fixtures_path, self.yaml_filename)
with file(yaml_filepath, 'r') as yaml_file:
@ -83,7 +84,8 @@ class BaseTestCase(object):
pub.gen_xml(parser, xml_project, yaml_content)
# Prettify generated XML
pretty_xml = XmlJob(xml_project, 'fixturejob').output()
pretty_xml = unicode(XmlJob(xml_project, 'fixturejob').output(),
'utf-8')
self.assertThat(
pretty_xml,

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<hudson.tasks.Maven>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<hudson.tasks.Maven>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<hudson.plugins.parameterizedtrigger.TriggerBuilder>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<keepDependencies>false</keepDependencies>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<keepDependencies>false</keepDependencies>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<com.tikal.hudson.plugins.notification.HudsonNotificationProperty>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.plugins.batch__task.BatchTaskProperty>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.plugins.throttleconcurrents.ThrottleJobProperty>

View File

@ -10,5 +10,5 @@ Each yaml file MUST have a corresponding xml file.
Once the YAML file has been parsed, it is prettify using python minidom
which also means that:
- your XML file must start with: <?xml version="1.0" ?>
- your XML file must start with: <?xml version="1.0" encoding="utf-8"?>
- self closing elements do not contains space eg: <element/>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.tasks.ArtifactArchiver>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.blame__upstream__commiters.BlameUpstreamCommitersPublisher/>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.build__publisher.BuildPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.descriptionsetter.DescriptionSetterPublisher>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.descriptionsetter.DescriptionSetterPublisher>
<regexp>.*(&lt;a href=.*a&gt;)</regexp>
<regexpForFailed>.*(&lt;a href=.*a&gt;)</regexpForFailed>
<description>こんにちは</description>
<descriptionForFailed>さようなら</descriptionForFailed>
<setForMatrix>true</setForMatrix>
</hudson.plugins.descriptionsetter.DescriptionSetterPublisher>
</publishers>
</project>

View File

@ -0,0 +1,7 @@
publishers:
- description-setter:
regexp: ".*(<a href=.*a>)"
regexp-for-failed: ".*(<a href=.*a>)"
description: "こんにちは"
description-for-failed: "さようなら"
set-for-matrix: true

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<org.jenkinsci.plugins.emotional__jenkins.EmotionalJenkinsPublisher/>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.git.GitPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<com.cloudbees.jenkins.GitHubCommitNotifier/>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.maven.RedeployPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.plot.PlotPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.plot.PlotPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.plot.PlotPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<be.certipost.hudson.plugin.SCPRepositoryPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<org.jenkinsci.plugins.stashNotifier.StashNotifier>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<xunit>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<scm class="hudson.plugins.repo.RepoScm">
<manifestRepositoryUrl>https://example.com/project/</manifestRepositoryUrl>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
<org.jenkinsci.plugins.ghprb.GhprbTrigger>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf-8"?>
<project>
<buildWrappers>
<hudson.plugins.envfile.EnvFileBuildWrapper>