| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d5054fd commit df95149
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | string_types, | |
| 24 | 24 | FileType, | |
| 25 | 25 | defenc, | |
| 26 | + force_text, | ||
| 26 | 27 | with_metaclass, | |
| 27 | 28 | PY3 | |
| 28 | 29 | ) | |
@@ -412,7 +413,7 @@ def write_section(name, section_dict): | |||
| 412 | 413 | fp.write(("[%s]\n" % name).encode(defenc)) | |
| 413 | 414 | for (key, value) in section_dict.items(): | |
| 414 | 415 | if key != "__name__": | |
| 415 | - fp.write(("\t%s = %s\n" % (key, str(value).replace('\n', '\n\t'))).encode(defenc)) | ||
| 416 | + fp.write(("\t%s = %s\n" % (key, self._value_to_string(value).replace('\n', '\n\t'))).encode(defenc)) | ||
| 416 | 417 | # END if key is not __name__ | |
| 417 | 418 | # END section writing | |
| 418 | 419 | ||
@@ -529,6 +530,11 @@ def get_value(self, section, option, default=None): | |||
| 529 | 530 | ||
| 530 | 531 | return valuestr | |
| 531 | 532 | ||
| 533 | + def _value_to_string(self, value): | ||
| 534 | + if isinstance(value, (int, float, bool)): | ||
| 535 | + return str(value) | ||
| 536 | + return force_text(value) | ||
| 537 | + | ||
| 532 | 538 | @needs_values | |
| 533 | 539 | @set_dirty_and_flush_changes | |
| 534 | 540 | def set_value(self, section, option, value): | |
@@ -543,7 +549,7 @@ def set_value(self, section, option, value): | |||
| 543 | 549 | to a string""" | |
| 544 | 550 | if not self.has_section(section): | |
| 545 | 551 | self.add_section(section) | |
| 546 | - self.set(section, option, str(value)) | ||
| 552 | + self.set(section, option, self._value_to_string(value)) | ||
| 547 | 553 | ||
| 548 | 554 | def rename_section(self, section, new_name): | |
| 549 | 555 | """rename the given section to new_name | |
@@ -558,7 +564,7 @@ def rename_section(self, section, new_name): | |||
| 558 | 564 | ||
| 559 | 565 | super(GitConfigParser, self).add_section(new_name) | |
| 560 | 566 | for k, v in self.items(section): | |
| 561 | - self.set(new_name, k, str(v)) | ||
| 567 | + self.set(new_name, k, self._value_to_string(v)) | ||
| 562 | 568 | # end for each value to copy | |
| 563 | 569 | ||
| 564 | 570 | # This call writes back the changes, which is why we don't have the respective decorator | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -381,12 +381,13 @@ def test_index_mutation(self, rw_repo): | |||
| 381 | 381 | num_entries = len(index.entries) | |
| 382 | 382 | cur_head = rw_repo.head | |
| 383 | 383 | ||
| 384 | - uname = "Some Developer" | ||
| 384 | + uname = u"Thomas Müller" | ||
| 385 | 385 | umail = "sd@company.com" | |
| 386 | 386 | writer = rw_repo.config_writer() | |
| 387 | 387 | writer.set_value("user", "name", uname) | |
| 388 | 388 | writer.set_value("user", "email", umail) | |
| 389 | 389 | writer.release() | |
| 390 | + assert writer.get_value("user", "name") == uname | ||
| 390 | 391 | ||
| 391 | 392 | # remove all of the files, provide a wild mix of paths, BaseIndexEntries, | |
| 392 | 393 | # IndexEntries | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,11 @@ | |||
| 17 | 17 | # NOTE: Some of the unused imports might be used/imported by others. | |
| 18 | 18 | # Handle once test-cases are back up and running. | |
| 19 | 19 | from .exc import GitCommandError | |
| 20 | - from .compat import MAXSIZE | ||
| 20 | + from .compat import ( | ||
| 21 | + MAXSIZE, | ||
| 22 | + defenc, | ||
| 23 | + PY3 | ||
| 24 | + ) | ||
| 21 | 25 | ||
| 22 | 26 | # Most of these are unused here, but are for use by git-python modules so these | |
| 23 | 27 | # don't see gitdb all the time. Flake of course doesn't like it. | |
@@ -364,7 +368,11 @@ def _main_actor(cls, env_name, env_email, config_reader=None): | |||
| 364 | 368 | for attr, evar, cvar, default in (('name', env_name, cls.conf_name, default_name), | |
| 365 | 369 | ('email', env_email, cls.conf_email, default_email)): | |
| 366 | 370 | try: | |
| 367 | - setattr(actor, attr, os.environ[evar]) | ||
| 371 | + val = os.environ[evar] | ||
| 372 | + if not PY3: | ||
| 373 | + val = val.decode(defenc) | ||
| 374 | + # end assure we don't get 'invalid strings' | ||
| 375 | + setattr(actor, attr, val) | ||
| 368 | 376 | except KeyError: | |
| 369 | 377 | if config_reader is not None: | |
| 370 | 378 | setattr(actor, attr, config_reader.get_value('user', cvar, default)) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments