Пример #1
0
    def serialize(self,
                  document,
                  indent=False,
                  encoding=bridge.ENCODING,
                  prefixes=None,
                  omit_declaration=False):
        doc = XmlDocument()
        doc.LoadXml(self.__start_document(document))
        if document.xml_text:
            doc.DocumentElement.AppendChild(
                doc.CreateTextNode(document.xml_text))
        self.__serialize_element(doc, doc.DocumentElement, document)

        settings = XmlWriterSettings()
        settings.Indent = indent
        settings.Encoding = Encoding.GetEncoding(encoding)
        settings.OmitXmlDeclaration = omit_declaration

        ms = MemoryStream()
        xw = XmlWriter.Create(ms, settings)
        doc.Save(xw)
        sr = StreamReader(ms)
        ms.Seek(0, SeekOrigin.Begin)
        content = sr.ReadToEnd()
        ms.Close()

        return content
Пример #2
0
 def GetReader(self):
     return SourceCodeReader(StringReader(self.text), Encoding.GetEncoding(0))
Пример #3
0
# 2006-11-11 baus    Added _fileobject class
# 2006-11-20 sanxiyn Splitted _fileobject to the separate file
# 2006-11-29 sanxiyn Added timeout, SocketType

from System import Array, Byte, Enum

from System.Net import IPAddress, IPEndPoint
from System.Net.Sockets import Socket, SocketException  #, NetworkStream
from System.Net.Sockets import AddressFamily, ProtocolType, SocketType
#from System.Net.Sockets import SocketOptionLevel, SocketOptionName

# Name collision with the Python interface
ClrSocketType = SocketType

from System.Text import Encoding
raw = Encoding.GetEncoding('utf-8')


def _make_buffer(size):
    return Array.CreateInstance(Byte, size)


_GLOBAL_DEFAULT_TIMEOUT = object()

AF_INET = AddressFamily.InterNetwork
AF_UNSPEC = AddressFamily.Unspecified
SOCK_STREAM = ClrSocketType.Stream
SOCK_DGRAM = 2
IPPROTO_IP = 0

SOL_SOCKET = 65535
Пример #4
0
# Based on Mathieu Fenniak's work dated 2006-06-04
# http://mathieu.fenniak.net/import-zlib-vs-net-framework/

# 2006-10-08 sanxiyn Created

from System.IO import MemoryStream
from System.IO.Compression import CompressionMode, DeflateStream

# --------------------------------------------------------------------
# Utilities

from System import Array, Byte

from System.Text import Encoding
raw = Encoding.GetEncoding('iso-8859-1')


def _make_buffer(size):
    return Array.CreateInstance(Byte, size)


def _read_to_end(stream, bufsize=4096):
    buffer = _make_buffer(bufsize)
    memory = MemoryStream()
    while True:
        count = stream.Read(buffer, 0, bufsize)
        if not count:
            break
        memory.Write(buffer, 0, count)
    bytes = memory.ToArray()
Пример #5
0
import os.path
from System.Reflection import Assembly
from System.Reflection import BindingFlags
import System
from System.Text import Encoding
from System import Type

hota = Assembly.LoadFile(os.getcwd() + "/tools/HotA editor.exe")
hdat = hota.GetType("HotA_editor.Hdat")

hdata = System.Activator.CreateInstance(hdat)
t = hdata.GetType()
mi = t.GetMethod("ReadFile", BindingFlags.Instance | BindingFlags.NonPublic)
r = mi.Invoke(
    hdata, ["homm3_files/HotA/HotA.dat",
            Encoding.GetEncoding("windows-1250")])

for item in r.Items:
    if not os.path.exists("_tmp/HotA_txt/" + item.Name):
        os.makedirs("_tmp/HotA_txt/" + item.Name)
    if item.Data1 != "":
        with open(os.path.join("_tmp/HotA_txt/" + item.Name, "data1.txt"),
                  'w+b') as the_file:
            the_file.write(str.encode(item.Data1, encoding='cp1250'))
    if item.Data2 != "":
        with open(os.path.join("_tmp/HotA_txt/" + item.Name, "data2.txt"),
                  'w+b') as the_file:
            the_file.write(str.encode(item.Data2, encoding='cp1250'))
    if item.Data3 != "":
        with open(os.path.join("_tmp/HotA_txt/" + item.Name, "data3.txt"),
                  'w+b') as the_file: