Ejemplo n.º 1
0
def rewrite_html_for_editing(fp, edit_url):
    contents = fp.read()

    button = '''
    <style type="text/css">
      #lektor-edit-link {
        position: fixed;
        z-index: 9999999;
        right: 10px;
        top: 10px;
        position: fixed;
        margin: 0;
        font-family: 'Verdana', sans-serif;
        background: #eee;
        color: #77304c;
        font-weight: normal;
        font-size: 32px;
        padding: 0;
        text-decoration: none!important;
        border: 1px solid #ccc!important;
        width: 40px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        opacity: 0.7;
      }

      #lektor-edit-link:hover {
        background: white!important;
        opacity: 1.0;
        border: 1px solid #aaa!important;
      }
    </style>
    <script type="text/javascript">
      (function() {
        if (window != window.top) {
          return;
        }
        var link = document.createElement('a');
        link.setAttribute('href', '%(edit_url)s?path=' +
            encodeURIComponent(document.location.pathname));
        link.setAttribute('id', 'lektor-edit-link');
        link.innerHTML = '\u270E';
        document.body.appendChild(link);
      })();
    </script>
    ''' % {
        'edit_url': edit_url,
    }

    return BytesIO(contents + button.encode('utf-8'))
Ejemplo n.º 2
0
    def append(self, filename, data):
        if not isinstance(filename, text_type):
            filename = filename.decode('utf-8')

        if PY2:
            input = StringIO(data)
        else:
            input = BytesIO(data.encode('utf-8'))

        try:
            self.con.storbinary('APPE ' + filename, input)
        except FTPError as e:
            self.log_buffer.append(str(e))
            return False
        return True
Ejemplo n.º 3
0
 def upload_file(self, filename, src, mkdir=False):
     if isinstance(src, string_types):
         if PY2:
             src = StringIO(src)
         else:
             src = BytesIO(src.encode('utf-8'))
     if mkdir:
         directory = posixpath.dirname(filename)
         if directory:
             self.mkdir(directory, recursive=True)
     if not isinstance(filename, text_type):
         filename = filename.decode('utf-8')
     try:
         self.con.storbinary('STOR ' + filename, src, blocksize=32768)
     except FTPError as e:
         self.log_buffer.append(str(e))
         return False
     return True
Ejemplo n.º 4
0
 def get_file(self, filename, out=None):
     if not isinstance(filename, text_type):
         filename = filename.decode('utf-8')
     getvalue = False
     if out is None:
         if PY2:
             out = StringIO()
         else:
             out = BytesIO()
         getvalue = True
     try:
         self.con.retrbinary('RETR ' + filename, out.write)
     except FTPError as e:
         msg = str(e)
         if msg[:4] != '550 ':
             self.log_buffer.append(e)
         return None
     if getvalue:
         if PY2:
             return out.getvalue()
         return out.getvalue().decode('utf-8')
     return out