~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: John Arbash Meinel
  • Date: 2010-01-12 22:36:23 UTC
  • mfrom: (4953 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4955.
  • Revision ID: john@arbash-meinel.com-20100112223623-836x5mou0gm5vsep
merge bzr.dev 4953 to clean up the ui factory issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
202
202
    :param old: The old path, to rename from
203
203
    :param new: The new path, to rename to
204
204
    :param rename_func: The potentially non-atomic rename function
205
 
    :param unlink_func: A way to delete the target file if the full rename succeeds
 
205
    :param unlink_func: A way to delete the target file if the full rename
 
206
        succeeds
206
207
    """
207
 
 
 
208
    new = safe_unicode(new)
208
209
    # sftp rename doesn't allow overwriting, so play tricks:
209
210
    base = os.path.basename(new)
210
211
    dirname = os.path.dirname(new)
211
 
    tmp_name = u'tmp.%s.%.9f.%d.%s' % (base, time.time(), os.getpid(), rand_chars(10))
 
212
    tmp_name = u'tmp.%s.%.9f.%d.%s' % (base, time.time(),
 
213
                                       os.getpid(), rand_chars(10))
212
214
    tmp_name = pathjoin(dirname, tmp_name)
213
215
 
214
216
    # Rename the file out of the way, but keep track if it didn't exist
2087
2089
    if use_cache:
2088
2090
        _cached_concurrency = concurrency
2089
2091
    return concurrency
 
2092
 
 
2093
 
 
2094
class UnicodeOrBytesToBytesWriter(codecs.StreamWriter):
 
2095
    """A stream writer that doesn't decode str arguments."""
 
2096
 
 
2097
    def __init__(self, encode, stream, errors='strict'):
 
2098
        codecs.StreamWriter.__init__(self, stream, errors)
 
2099
        self.encode = encode
 
2100
 
 
2101
    def write(self, object):
 
2102
        if type(object) is str:
 
2103
            self.stream.write(object)
 
2104
        else:
 
2105
            data, _ = self.encode(object, self.errors)
 
2106
            self.stream.write(data)